GenCAD exporter: changed 'flip components' to 'flip pads'

Such option might be useful for older CAM350 versions, but it should be verified.
This commit is contained in:
Maciej Suminski 2017-10-04 17:25:59 +02:00
parent d5fa28efe4
commit 847bede635
3 changed files with 30 additions and 60 deletions

View File

@ -127,7 +127,7 @@ void DIALOG_GENCAD_EXPORT_OPTIONS::createOptCheckboxes()
{ {
std::map<GENCAD_EXPORT_OPT, wxString> opts = std::map<GENCAD_EXPORT_OPT, wxString> opts =
{ {
{ FLIP_BOTTOM_COMPONENTS, _( "Flip bottom components geometry" ) }, { FLIP_BOTTOM_PADS, _( "Flip bottom components padstacks" ) },
{ UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) } { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) }
}; };

View File

@ -33,7 +33,7 @@ class wxTextCtrl;
///> Settings for GenCAD exporter ///> Settings for GenCAD exporter
enum GENCAD_EXPORT_OPT enum GENCAD_EXPORT_OPT
{ {
FLIP_BOTTOM_COMPONENTS, // flip components geometry instead of using MIRRORX directive FLIP_BOTTOM_PADS, // flip bottom components padstacks geometry
UNIQUE_PIN_NAMES // generate unique pin names UNIQUE_PIN_NAMES // generate unique pin names
}; };

View File

@ -225,7 +225,7 @@ static int GencadOffsetX, GencadOffsetY;
const static double SCALE_FACTOR = 1000.0 * IU_PER_MILS; const static double SCALE_FACTOR = 1000.0 * IU_PER_MILS;
// Export options // Export options
bool flipBottomComponents; bool flipBottomPads;
bool uniquePins; bool uniquePins;
/* Two helper functions to calculate coordinates of modules in gencad values /* Two helper functions to calculate coordinates of modules in gencad values
@ -261,7 +261,7 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
} }
// Get options // Get options
flipBottomComponents = optionsDialog.GetOption( FLIP_BOTTOM_COMPONENTS ); flipBottomPads = optionsDialog.GetOption( FLIP_BOTTOM_PADS );
uniquePins = optionsDialog.GetOption( UNIQUE_PIN_NAMES ); uniquePins = optionsDialog.GetOption( UNIQUE_PIN_NAMES );
// Switch the locale to standard C (needed to print floating point numbers) // Switch the locale to standard C (needed to print floating point numbers)
@ -290,7 +290,7 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
{ {
module->SetFlag( 0 ); module->SetFlag( 0 );
if( flipBottomComponents && module->GetLayer() == B_Cu ) if( module->GetLayer() == B_Cu )
{ {
module->Flip( module->GetPosition() ); module->Flip( module->GetPosition() );
module->SetFlag( 1 ); module->SetFlag( 1 );
@ -324,7 +324,7 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
// Undo the footprints modifications (flipped footprints) // Undo the footprints modifications (flipped footprints)
for( module = pcb->m_Modules; module; module = module->Next() ) for( module = pcb->m_Modules; module; module = module->Next() )
{ {
if( flipBottomComponents && module->GetFlag() ) if( module->GetFlag() )
{ {
module->Flip( module->GetPosition() ); module->Flip( module->GetPosition() );
module->SetFlag( 0 ); module->SetFlag( 0 );
@ -639,10 +639,10 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
} }
/* Component padstacks /* Component padstacks
* CAM350 don't apply correctly the FLIP semantics for padstacks, i.e. doesn't * Older versions of CAM350 don't apply correctly the FLIP semantics for
* swap the top and bottom layers... so I need to define the shape as MIRRORX * padstacks, i.e. doesn't swap the top and bottom layers... so I need to
* and define a separate 'flipped' padstack... until it appears yet another * define the shape as MIRRORX and define a separate 'flipped' padstack...
* noncompliant importer */ * until it appears yet another noncompliant importer */
for( unsigned i = 1; i < padstacks.size(); i++ ) for( unsigned i = 1; i < padstacks.size(); i++ )
{ {
D_PAD* pad = padstacks[i]; D_PAD* pad = padstacks[i];
@ -661,7 +661,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
} }
// Flipped padstack // Flipped padstack
if( flipBottomComponents ) if( flipBottomPads )
{ {
fprintf( aFile, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR ); fprintf( aFile, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
@ -693,8 +693,6 @@ static void CreateShapesSection( FILE* aFile, BOARD* aPcb )
fputs( "$SHAPES\n", aFile ); fputs( "$SHAPES\n", aFile );
const LSET all_cu = LSET::AllCuMask();
for( module = aPcb->m_Modules; module; module = module->Next() ) for( module = aPcb->m_Modules; module; module = module->Next() )
{ {
// already emitted pins to check for duplicates // already emitted pins to check for duplicates
@ -704,22 +702,10 @@ static void CreateShapesSection( FILE* aFile, BOARD* aPcb )
for( pad = module->PadsList(); pad; pad = pad->Next() ) for( pad = module->PadsList(); pad; pad = pad->Next() )
{ {
/* Funny thing: GenCAD requires the pad side even if you use /* Padstacks are defined using the correct layers for the pads, therefore to
* padstacks (which are theorically optional but gerbtools * all pads need to be marked as TOP to use the padstack information correctly.
*requires* them). Now the trouble thing is that 'BOTTOM' */
* is interpreted by someone as a padstack flip even layer = "TOP";
* if the spec explicitly says it's not... */
layer = "ALL";
if( ( pad->GetLayerSet() & all_cu ) == LSET( B_Cu ) )
{
layer = module->GetFlag() ? "TOP" : "BOTTOM";
}
else if( ( pad->GetLayerSet() & all_cu ) == LSET( F_Cu ) )
{
layer = module->GetFlag() ? "BOTTOM" : "TOP";
}
pinname = pad->GetName(); pinname = pad->GetName();
if( pinname.IsEmpty() ) if( pinname.IsEmpty() )
@ -746,7 +732,7 @@ static void CreateShapesSection( FILE* aFile, BOARD* aPcb )
NORMALIZE_ANGLE_POS( orient ); NORMALIZE_ANGLE_POS( orient );
// Bottom side modules use the flipped padstack // Bottom side modules use the flipped padstack
fprintf( aFile, ( flipBottomComponents && module->GetFlag() ) ? fprintf( aFile, ( flipBottomPads && module->GetFlag() ) ?
"PIN %s PAD%dF %g %g %s %g %s\n" : "PIN %s PAD%dF %g %g %s %g %s\n" :
"PIN %s PAD%d %g %g %s %g %s\n", "PIN %s PAD%d %g %g %s %g %s\n",
TO_UTF8( pinname ), pad->GetSubRatsnest(), TO_UTF8( pinname ), pad->GetSubRatsnest(),
@ -779,7 +765,7 @@ static void CreateComponentsSection( FILE* aFile, BOARD* aPcb )
if( module->GetFlag() ) if( module->GetFlag() )
{ {
mirror = flipBottomComponents ? "0" : "MIRRORX"; mirror = "MIRRORX";
flip = "FLIP"; flip = "FLIP";
NEGATE_AND_NORMALIZE_ANGLE_POS( fp_orient ); NEGATE_AND_NORMALIZE_ANGLE_POS( fp_orient );
} }
@ -1201,9 +1187,6 @@ static void FootprintWriteShape( FILE* aFile, MODULE* module )
EDGE_MODULE* PtEdge; EDGE_MODULE* PtEdge;
EDA_ITEM* PtStruct; EDA_ITEM* PtStruct;
// Control Y axis change sign for flipped modules
int Yaxis_sign = module->GetFlag() ? 1 : -1;
/* creates header: */ /* creates header: */
fprintf( aFile, "\nSHAPE %s\n", TO_UTF8( module->GetReference() ) ); fprintf( aFile, "\nSHAPE %s\n", TO_UTF8( module->GetReference() ) );
@ -1262,10 +1245,10 @@ static void FootprintWriteShape( FILE* aFile, MODULE* module )
{ {
case S_SEGMENT: case S_SEGMENT:
fprintf( aFile, "LINE %g %g %g %g\n", fprintf( aFile, "LINE %g %g %g %g\n",
(PtEdge->m_Start0.x) / SCALE_FACTOR, PtEdge->m_Start0.x / SCALE_FACTOR,
(Yaxis_sign * PtEdge->m_Start0.y) / SCALE_FACTOR, -PtEdge->m_Start0.y / SCALE_FACTOR,
(PtEdge->m_End0.x) / SCALE_FACTOR, PtEdge->m_End0.x / SCALE_FACTOR,
(Yaxis_sign * PtEdge->m_End0.y ) / SCALE_FACTOR ); -PtEdge->m_End0.y / SCALE_FACTOR );
break; break;
case S_CIRCLE: case S_CIRCLE:
@ -1274,7 +1257,7 @@ static void FootprintWriteShape( FILE* aFile, MODULE* module )
PtEdge->m_Start0 ) ); PtEdge->m_Start0 ) );
fprintf( aFile, "CIRCLE %g %g %g\n", fprintf( aFile, "CIRCLE %g %g %g\n",
PtEdge->m_Start0.x / SCALE_FACTOR, PtEdge->m_Start0.x / SCALE_FACTOR,
Yaxis_sign * PtEdge->m_Start0.y / SCALE_FACTOR, -PtEdge->m_Start0.y / SCALE_FACTOR,
radius / SCALE_FACTOR ); radius / SCALE_FACTOR );
break; break;
} }
@ -1287,27 +1270,14 @@ static void FootprintWriteShape( FILE* aFile, MODULE* module )
RotatePoint( &arcendx, &arcendy, -PtEdge->GetAngle() ); RotatePoint( &arcendx, &arcendy, -PtEdge->GetAngle() );
arcendx += PtEdge->GetStart0().x; arcendx += PtEdge->GetStart0().x;
arcendy += PtEdge->GetStart0().y; arcendy += PtEdge->GetStart0().y;
if( Yaxis_sign == -1 )
{ fprintf( aFile, "ARC %g %g %g %g %g %g\n",
// Flipping Y flips the arc direction too PtEdge->m_End0.x / SCALE_FACTOR,
fprintf( aFile, "ARC %g %g %g %g %g %g\n", -PtEdge->GetEnd0().y / SCALE_FACTOR,
(PtEdge->m_End0.x) / SCALE_FACTOR, arcendx / SCALE_FACTOR,
(Yaxis_sign * PtEdge->GetEnd0().y) / SCALE_FACTOR, -arcendy / SCALE_FACTOR,
(arcendx) / SCALE_FACTOR, PtEdge->GetStart0().x / SCALE_FACTOR,
(Yaxis_sign * arcendy) / SCALE_FACTOR, -PtEdge->GetStart0().y / SCALE_FACTOR );
(PtEdge->GetStart0().x) / SCALE_FACTOR,
(Yaxis_sign * PtEdge->GetStart0().y) / SCALE_FACTOR );
}
else
{
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
(arcendx) / SCALE_FACTOR,
(Yaxis_sign * arcendy) / SCALE_FACTOR,
(PtEdge->GetEnd0().x) / SCALE_FACTOR,
(Yaxis_sign * PtEdge->GetEnd0().y) / SCALE_FACTOR,
(PtEdge->GetStart0().x) / SCALE_FACTOR,
(Yaxis_sign * PtEdge->GetStart0().y) / SCALE_FACTOR );
}
break; break;
} }