kicad/pcbnew/export_gencad.cpp

1113 lines
38 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file export_gencad.cpp
* @brief Export GenCAD 1.4 format.
*/
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <gestfich.h>
#include <appl_wxstruct.h>
#include <wxPcbStruct.h>
#include <trigo.h>
#include <build_version.h>
#include <macros.h>
#include <pcbnew.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_edge_mod.h>
2011-12-02 15:09:57 +00:00
static bool CreateHeaderInfoData( FILE* aFile, PCB_EDIT_FRAME* frame );
static void CreateArtworksSection( FILE* aFile );
2011-12-02 15:09:57 +00:00
static void CreateTracksInfoData( FILE* aFile, BOARD* aPcb );
static void CreateBoardSection( FILE* aFile, BOARD* aPcb );
static void CreateComponentsSection( FILE* aFile, BOARD* aPcb );
static void CreateDevicesSection( FILE* aFile, BOARD* aPcb );
static void CreateRoutesSection( FILE* aFile, BOARD* aPcb );
static void CreateSignalsSection( FILE* aFile, BOARD* aPcb );
static void CreateShapesSection( FILE* aFile, BOARD* aPcb );
static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb );
2009-11-02 20:36:20 +00:00
static void FootprintWriteShape( FILE* File, MODULE* module );
// layer name for Gencad export
2011-12-02 15:09:57 +00:00
static const wxString GenCADLayerName[32] =
2009-11-02 20:36:20 +00:00
{
wxT( "BOTTOM" ), wxT( "INNER1" ), wxT( "INNER2" ),
wxT( "INNER3" ), wxT( "INNER4" ), wxT( "INNER5" ),
wxT( "INNER6" ), wxT( "INNER7" ), wxT( "INNER8" ),
wxT( "INNER9" ), wxT( "INNER10" ), wxT( "INNER11" ),
wxT( "INNER12" ), wxT( "INNER13" ), wxT( "INNER14" ),
wxT( "TOP" ), wxT( "LAYER17" ), wxT( "LAYER18" ),
wxT( "SOLDERPASTE_BOTTOM" ), wxT( "SOLDERPASTE_TOP" ),
wxT( "SILKSCREEN_BOTTOM" ), wxT( "SILKSCREEN_TOP" ),
wxT( "SOLDERMASK_BOTTOM" ), wxT( "SOLDERMASK_TOP" ), wxT( "LAYER25" ),
wxT( "LAYER26" ), wxT( "LAYER27" ), wxT( "LAYER28" ),
wxT( "LAYER29" ), wxT( "LAYER30" ), wxT( "LAYER31" ),
2011-12-02 15:09:57 +00:00
wxT( "LAYER32" )
2007-08-23 04:28:46 +00:00
};
2011-12-02 15:09:57 +00:00
// flipped layer name for Gencad export (to make CAM350 imports correct)
static const wxString GenCADLayerNameFlipped[32] =
{
wxT( "TOP" ), wxT( "INNER14" ), wxT( "INNER13" ),
wxT( "INNER12" ), wxT( "INNER11" ), wxT( "INNER10" ),
wxT( "INNER9" ), wxT( "INNER8" ), wxT( "INNER7" ),
wxT( "INNER6" ), wxT( "INNER5" ), wxT( "INNER4" ),
wxT( "INNER3" ), wxT( "INNER2" ), wxT( "INNER1" ),
wxT( "BOTTOM" ), wxT( "LAYER17" ), wxT( "LAYER18" ),
wxT( "SOLDERPASTE_TOP" ), wxT( "SOLDERPASTE_BOTTOM" ),
wxT( "SILKSCREEN_TOP" ), wxT( "SILKSCREEN_BOTTOM" ),
wxT( "SOLDERMASK_TOP" ), wxT( "SOLDERMASK_BOTTOM" ), wxT( "LAYER25" ),
wxT( "LAYER26" ), wxT( "LAYER27" ), wxT( "LAYER28" ),
wxT( "LAYER29" ), wxT( "LAYER30" ), wxT( "LAYER31" ),
2011-12-02 15:09:57 +00:00
wxT( "LAYER32" )
};
// These are the export origin (the auxiliary axis)
static int GencadOffsetX, GencadOffsetY;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
/* GerbTool chokes on units different than INCH so this is the conversion
* factor */
const static double SCALE_FACTOR = 10000.0 * IU_PER_DECIMILS;
2011-12-02 15:09:57 +00:00
/* Two helper functions to calculate coordinates of modules in gencad values
* (GenCAD Y axis from bottom to top)
2009-11-02 20:36:20 +00:00
*/
2011-12-02 15:09:57 +00:00
static double MapXTo( int aX )
{
2011-12-02 15:09:57 +00:00
return (aX - GencadOffsetX) / SCALE_FACTOR;
}
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
static double MapYTo( int aY )
{
2011-12-02 15:09:57 +00:00
return (GencadOffsetY - aY) / SCALE_FACTOR;
}
2011-12-02 15:09:57 +00:00
/* Driver function: processing starts here */
void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
{
2012-08-29 16:59:50 +00:00
wxFileName fn = GetBoard()->GetFileName();
2009-11-02 20:36:20 +00:00
wxString msg, ext, wildcard;
FILE* file;
2007-08-23 04:28:46 +00:00
ext = wxT( "cad" );
wildcard = _( "GenCAD 1.4 board files (.cad)|*.cad" );
fn.SetExt( ext );
2009-05-23 15:53:47 +00:00
wxFileDialog dlg( this, _( "Save GenCAD Board File" ), wxGetCwd(),
fn.GetFullName(), wildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL )
2007-08-23 04:28:46 +00:00
return;
if( ( file = wxFopen( dlg.GetPath(), wxT( "wt" ) ) ) == NULL )
2007-08-23 04:28:46 +00:00
{
msg.Printf( _( "Unable to create <%s>" ), GetChars( dlg.GetPath() ) );
2007-08-23 04:28:46 +00:00
DisplayError( this, msg ); return;
}
2011-12-02 15:09:57 +00:00
SetLocaleTo_C_standard(); // No pesky decimal separators in gencad
// Update some board data, to ensure a reliable gencad export
GetBoard()->ComputeBoundingBox();
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
// Save the auxiliary origin for the rest of the module
GencadOffsetX = GetOriginAxisPosition().x;
GencadOffsetY = GetOriginAxisPosition().y;
2011-12-02 15:09:57 +00:00
// No idea on *why* this should be needed... maybe to fix net names?
Compile_Ratsnest( NULL, true );
2007-08-23 04:28:46 +00:00
/* Temporary modification of footprints that are flipped (i.e. on bottom
* layer) to convert them to non flipped footprints.
2009-11-02 20:36:20 +00:00
* This is necessary to easily export shapes to GenCAD,
* that are given as normal orientation (non flipped, rotation = 0))
* these changes will be undone later
*/
BOARD* pcb = GetBoard();
2007-08-23 04:28:46 +00:00
MODULE* module;
2011-12-02 15:09:57 +00:00
for( module = pcb->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
module->SetFlag( 0 );
if( module->GetLayer() == LAYER_N_BACK )
2007-08-23 04:28:46 +00:00
{
module->Flip( module->GetPosition() );
module->SetFlag( 1 );
2007-08-23 04:28:46 +00:00
}
}
2011-12-02 15:09:57 +00:00
/* Gencad has some mandatory and some optional sections: some importer
* need the padstack section (which is optional) anyway. Also the
* order of the section *is* important */
2007-08-23 04:28:46 +00:00
CreateHeaderInfoData( file, this ); // Gencad header
CreateBoardSection( file, pcb ); // Board perimeter
2007-08-23 04:28:46 +00:00
CreatePadsShapesSection( file, pcb ); // Pads and padstacks
CreateArtworksSection( file ); // Empty but mandatory
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
/* Gencad splits a component info in shape, component and device.
* We don't do any sharing (it would be difficult since each module is
* customizable after placement) */
2011-12-02 15:09:57 +00:00
CreateShapesSection( file, pcb );
CreateComponentsSection( file, pcb );
CreateDevicesSection( file, pcb );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
// In a similar way the netlist is split in net, track and route
2011-12-02 15:09:57 +00:00
CreateSignalsSection( file, pcb );
CreateTracksInfoData( file, pcb );
CreateRoutesSection( file, pcb );
2007-08-23 04:28:46 +00:00
fclose( file );
SetLocaleTo_Default(); // revert to the current locale
2007-08-23 04:28:46 +00:00
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
// Undo the footprints modifications (flipped footprints)
2011-12-02 15:09:57 +00:00
for( module = pcb->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
if( module->GetFlag() )
2007-08-23 04:28:46 +00:00
{
module->Flip( module->GetPosition() );
module->SetFlag( 0 );
2007-08-23 04:28:46 +00:00
}
}
}
2011-12-02 15:09:57 +00:00
// Comparator for sorting pads with qsort
static int PadListSortByShape( const void* aRefptr, const void* aObjptr )
{
2011-12-02 15:09:57 +00:00
const D_PAD* padref = *(D_PAD**) aRefptr;
const D_PAD* padcmp = *(D_PAD**) aObjptr;
2008-01-24 21:50:12 +00:00
return D_PAD::Compare( padref, padcmp );
}
2011-12-02 15:09:57 +00:00
// Sort vias for uniqueness
static int ViaSort( const void* aRefptr, const void* aObjptr )
2011-12-02 15:09:57 +00:00
{
TRACK* padref = *(TRACK**) aRefptr;
TRACK* padcmp = *(TRACK**) aObjptr;
2007-08-23 04:28:46 +00:00
if( padref->GetWidth() != padcmp->GetWidth() )
return padref->GetWidth() - padcmp->GetWidth();
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
2011-12-02 15:09:57 +00:00
if( padref->GetDrillValue() != padcmp->GetDrillValue() )
return padref->GetDrillValue() - padcmp->GetDrillValue();
2011-12-02 15:09:57 +00:00
if( padref->GetLayerMask() != padcmp->GetLayerMask() )
return padref->GetLayerMask() - padcmp->GetLayerMask();
2011-12-02 15:09:57 +00:00
return 0;
}
2011-12-02 15:09:57 +00:00
// The ARTWORKS section is empty but (officially) mandatory
static void CreateArtworksSection( FILE* aFile )
{
/* The artworks section is empty */
fputs( "$ARTWORKS\n", aFile );
fputs( "$ENDARTWORKS\n\n", aFile );
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
// Emit PADS and PADSTACKS. They are sorted and emitted uniquely.
2011-12-02 15:09:57 +00:00
// Via name is synthesized from their attributes, pads are numbered
static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
{
std::vector<D_PAD*> pads;
2011-12-02 15:09:57 +00:00
std::vector<D_PAD*> padstacks;
std::vector<TRACK*> vias;
std::vector<TRACK*> viastacks;
padstacks.resize( 1 ); // We count pads from 1
2011-12-02 15:09:57 +00:00
// The master layermask (i.e. the enabled layers) for padstack generation
LAYER_MSK master_layermask = aPcb->GetDesignSettings().GetEnabledLayers();
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
fputs( "$PADS\n", aFile );
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
// Enumerate and sort the pads
if( aPcb->GetPadCount() > 0 )
{
pads = aPcb->GetPads();
qsort( &pads[0], aPcb->GetPadCount(), sizeof( D_PAD* ),
PadListSortByShape );
}
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
// The same for vias
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
for( TRACK* track = aPcb->m_Track; track != NULL; track = track->Next() )
{
if( track->Type() == PCB_VIA_T )
{
vias.push_back( track );
}
2011-12-02 15:09:57 +00:00
}
2011-12-02 15:09:57 +00:00
qsort( &vias[0], vias.size(), sizeof(TRACK*), ViaSort );
2011-12-02 15:09:57 +00:00
// Emit vias pads
TRACK* old_via = 0;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
for( unsigned i = 0; i < vias.size(); i++ )
2011-12-02 15:09:57 +00:00
{
TRACK* via = vias[i];
if( old_via && 0 == ViaSort( &old_via, &via ) )
continue;
old_via = via;
viastacks.push_back( via );
fprintf( aFile, "PAD V%d.%d.%X ROUND %g\nCIRCLE 0 0 %g\n",
via->GetWidth(), via->GetDrillValue(),
via->GetLayerMask(),
via->GetDrillValue() / SCALE_FACTOR,
via->GetWidth() / (SCALE_FACTOR * 2) );
2011-12-02 15:09:57 +00:00
}
// Emit component pads
D_PAD* old_pad = 0;
int pad_name_number = 0;
for( unsigned i = 0; i<pads.size(); ++i )
2007-08-23 04:28:46 +00:00
{
D_PAD* pad = pads[i];
pad->SetSubRatsnest( pad_name_number );
2007-08-23 04:28:46 +00:00
2008-01-24 21:50:12 +00:00
if( old_pad && 0==D_PAD::Compare( old_pad, pad ) )
continue; // already created
2007-08-23 04:28:46 +00:00
old_pad = pad;
pad_name_number++;
pad->SetSubRatsnest( pad_name_number );
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
fprintf( aFile, "PAD P%d", pad->GetSubRatsnest() );
2007-08-23 04:28:46 +00:00
padstacks.push_back( pad ); // Will have its own padstack later
2012-02-19 04:02:19 +00:00
int dx = pad->GetSize().x / 2;
int dy = pad->GetSize().y / 2;
2007-08-23 04:28:46 +00:00
2012-02-19 04:02:19 +00:00
switch( pad->GetShape() )
2007-08-23 04:28:46 +00:00
{
default:
2008-01-05 17:30:56 +00:00
case PAD_CIRCLE:
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, " ROUND %g\n",
2012-02-19 04:02:19 +00:00
pad->GetDrillSize().x / SCALE_FACTOR );
/* Circle is center, radius */
2011-12-02 15:09:57 +00:00
fprintf( aFile, "CIRCLE %g %g %g\n",
2012-02-19 04:02:19 +00:00
pad->GetOffset().x / SCALE_FACTOR,
-pad->GetOffset().y / SCALE_FACTOR,
pad->GetSize().x / (SCALE_FACTOR * 2) );
2007-08-23 04:28:46 +00:00
break;
2008-01-05 17:30:56 +00:00
case PAD_RECT:
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, " RECTANGULAR %g\n",
2012-02-19 04:02:19 +00:00
pad->GetDrillSize().x / SCALE_FACTOR );
// Rectangle is begin, size *not* begin, end!
2011-12-02 15:09:57 +00:00
fprintf( aFile, "RECTANGLE %g %g %g %g\n",
2012-02-19 04:02:19 +00:00
(-dx + pad->GetOffset().x ) / SCALE_FACTOR,
(-dy - pad->GetOffset().y ) / SCALE_FACTOR,
dx / (SCALE_FACTOR / 2), dy / (SCALE_FACTOR / 2) );
2007-08-23 04:28:46 +00:00
break;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
case PAD_OVAL: // Create outline by 2 lines and 2 arcs
2007-08-23 04:28:46 +00:00
{
// OrCAD Layout call them OVAL or OBLONG - GenCAD call them FINGERs
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, " FINGER %g\n",
2012-02-19 04:02:19 +00:00
pad->GetDrillSize().x / SCALE_FACTOR );
2007-08-23 04:28:46 +00:00
int dr = dx - dy;
2011-12-02 15:09:57 +00:00
2009-11-02 20:36:20 +00:00
if( dr >= 0 ) // Horizontal oval
2007-08-23 04:28:46 +00:00
{
int radius = dy;
2011-12-02 15:09:57 +00:00
fprintf( aFile, "LINE %g %g %g %g\n",
2012-02-19 04:02:19 +00:00
(-dr + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y - radius) / SCALE_FACTOR,
(dr + pad->GetOffset().x ) / SCALE_FACTOR,
(-pad->GetOffset().y - radius) / SCALE_FACTOR );
// GenCAD arcs are (start, end, center)
2011-12-02 15:09:57 +00:00
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
2012-02-19 04:02:19 +00:00
(dr + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y - radius) / SCALE_FACTOR,
(dr + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y + radius) / SCALE_FACTOR,
(dr + pad->GetOffset().x) / SCALE_FACTOR,
-pad->GetOffset().y / SCALE_FACTOR );
2011-12-02 15:09:57 +00:00
fprintf( aFile, "LINE %g %g %g %g\n",
2012-02-19 04:02:19 +00:00
(dr + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y + radius) / SCALE_FACTOR,
(-dr + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y + radius) / SCALE_FACTOR );
2011-12-02 15:09:57 +00:00
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
2012-02-19 04:02:19 +00:00
(-dr + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y + radius) / SCALE_FACTOR,
(-dr + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y - radius) / SCALE_FACTOR,
(-dr + pad->GetOffset().x) / SCALE_FACTOR,
-pad->GetOffset().y / SCALE_FACTOR );
2007-08-23 04:28:46 +00:00
}
2009-11-02 20:36:20 +00:00
else // Vertical oval
2007-08-23 04:28:46 +00:00
{
dr = -dr;
int radius = dx;
2011-12-02 15:09:57 +00:00
fprintf( aFile, "LINE %g %g %g %g\n",
2012-02-19 04:02:19 +00:00
(-radius + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y - dr) / SCALE_FACTOR,
(-radius + pad->GetOffset().x ) / SCALE_FACTOR,
(-pad->GetOffset().y + dr) / SCALE_FACTOR );
2011-12-02 15:09:57 +00:00
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
2012-02-19 04:02:19 +00:00
(-radius + pad->GetOffset().x ) / SCALE_FACTOR,
(-pad->GetOffset().y + dr) / SCALE_FACTOR,
(radius + pad->GetOffset().x ) / SCALE_FACTOR,
(-pad->GetOffset().y + dr) / SCALE_FACTOR,
pad->GetOffset().x / SCALE_FACTOR,
(-pad->GetOffset().y + dr) / SCALE_FACTOR );
2011-12-02 15:09:57 +00:00
fprintf( aFile, "LINE %g %g %g %g\n",
2012-02-19 04:02:19 +00:00
(radius + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y + dr) / SCALE_FACTOR,
(radius + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y - dr) / SCALE_FACTOR );
2011-12-02 15:09:57 +00:00
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
2012-02-19 04:02:19 +00:00
(radius + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y - dr) / SCALE_FACTOR,
(-radius + pad->GetOffset().x) / SCALE_FACTOR,
(-pad->GetOffset().y - dr) / SCALE_FACTOR,
pad->GetOffset().x / SCALE_FACTOR,
(-pad->GetOffset().y - dr) / SCALE_FACTOR );
2007-08-23 04:28:46 +00:00
}
break;
}
2008-01-05 17:30:56 +00:00
case PAD_TRAPEZOID:
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, " POLYGON %g\n",
2012-02-19 04:02:19 +00:00
pad->GetDrillSize().x / SCALE_FACTOR );
// XXX TO BE IMPLEMENTED! and I don't know if it could be actually imported by something
2007-08-23 04:28:46 +00:00
break;
}
}
2011-12-02 15:09:57 +00:00
fputs( "\n$ENDPADS\n\n", aFile );
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
// Now emit the padstacks definitions, using the combined layer masks
fputs( "$PADSTACKS\n", aFile );
2011-12-02 15:09:57 +00:00
// Via padstacks
for( unsigned i = 0; i < viastacks.size(); i++ )
{
TRACK* via = viastacks[i];
LAYER_MSK mask = via->GetLayerMask() & master_layermask;
fprintf( aFile, "PADSTACK VIA%d.%d.%X %g\n",
via->GetWidth(), via->GetDrillValue(), mask,
via->GetDrillValue() / SCALE_FACTOR );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
for( LAYER_NUM layer = FIRST_LAYER; layer < NB_LAYERS; ++layer )
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
{
if( mask & GetLayerMask( layer ) )
{
fprintf( aFile, "PAD V%d.%d.%X %s 0 0\n",
via->GetWidth(), via->GetDrillValue(),
mask,
TO_UTF8( GenCADLayerName[layer] ) );
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
}
2011-12-02 15:09:57 +00:00
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
/* Component padstacks
* CAM350 don't apply correctly the FLIP semantics for padstacks, i.e. doesn't
* swap the top and bottom layers... so I need to define the shape as MIRRORX
* and define a separate 'flipped' padstack... until it appears yet another
* noncompliant importer */
2011-12-02 15:09:57 +00:00
for( unsigned i = 1; i < padstacks.size(); i++ )
{
D_PAD* pad = padstacks[i];
2011-12-02 15:09:57 +00:00
// Straight padstack
fprintf( aFile, "PADSTACK PAD%d %g\n", i,
2012-02-19 04:02:19 +00:00
pad->GetDrillSize().x / SCALE_FACTOR );
for( LAYER_NUM layer = FIRST_LAYER; layer < NB_LAYERS; ++layer )
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
{
if( pad->GetLayerMask() & GetLayerMask( layer ) & master_layermask )
{
fprintf( aFile, "PAD P%d %s 0 0\n", i,
TO_UTF8( GenCADLayerName[layer] ) );
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
}
// Flipped padstack
fprintf( aFile, "PADSTACK PAD%dF %g\n", i,
2012-02-19 04:02:19 +00:00
pad->GetDrillSize().x / SCALE_FACTOR );
for( LAYER_NUM layer = FIRST_LAYER; layer < NB_LAYERS; ++layer )
{
if( pad->GetLayerMask() & GetLayerMask( layer ) & master_layermask )
{
fprintf( aFile, "PAD P%d %s 0 0\n", i,
TO_UTF8( GenCADLayerNameFlipped[layer] ) );
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
}
}
2011-12-02 15:09:57 +00:00
fputs( "$ENDPADSTACKS\n\n", aFile );
}
2009-11-02 20:36:20 +00:00
/* Creates the footprint shape list.
2011-12-02 15:09:57 +00:00
* Since module shape is customizable after the placement we cannot share them;
* instead we opt for the one-module-one-shape-one-component-one-device approach
2007-08-23 04:28:46 +00:00
*/
2011-12-02 15:09:57 +00:00
static void CreateShapesSection( FILE* aFile, BOARD* aPcb )
{
2009-11-02 20:36:20 +00:00
MODULE* module;
D_PAD* pad;
const char* layer;
wxString pinname;
const char* mirror = "0";
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
fputs( "$SHAPES\n", aFile );
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
for( module = aPcb->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
2011-12-02 15:09:57 +00:00
FootprintWriteShape( aFile, module );
for( pad = module->Pads(); pad != NULL; pad = pad->Next() )
2007-08-23 04:28:46 +00:00
{
/* Funny thing: GenCAD requires the pad side even if you use
* padstacks (which are theorically optional but gerbtools
*requires* them). Now the trouble thing is that 'BOTTOM'
* is interpreted by someone as a padstack flip even
* if the spec explicitly says it's not... */
2007-08-23 04:28:46 +00:00
layer = "ALL";
2012-02-19 04:02:19 +00:00
if( ( pad->GetLayerMask() & ALL_CU_LAYERS ) == LAYER_BACK )
2007-08-23 04:28:46 +00:00
{
layer = ( module->GetFlag() ) ? "TOP" : "BOTTOM";
2007-08-23 04:28:46 +00:00
}
2012-02-19 04:02:19 +00:00
else if( ( pad->GetLayerMask() & ALL_CU_LAYERS ) == LAYER_FRONT )
2007-08-23 04:28:46 +00:00
{
layer = ( module->GetFlag() ) ? "BOTTOM" : "TOP";
2007-08-23 04:28:46 +00:00
}
pad->ReturnStringPadName( pinname );
2007-08-23 04:28:46 +00:00
if( pinname.IsEmpty() )
2011-12-02 15:09:57 +00:00
pinname = wxT( "none" );
2007-08-23 04:28:46 +00:00
double orient = pad->GetOrientation() - module->GetOrientation();
2007-08-23 04:28:46 +00:00
NORMALIZE_ANGLE_POS( orient );
// Bottom side modules use the flipped padstack
fprintf( aFile, (module->GetFlag()) ?
"PIN %s PAD%dF %g %g %s %g %s\n" :
"PIN %s PAD%d %g %g %s %g %s\n",
TO_UTF8( pinname ), pad->GetSubRatsnest(),
2012-02-19 04:02:19 +00:00
pad->GetPos0().x / SCALE_FACTOR,
-pad->GetPos0().y / SCALE_FACTOR,
layer, orient / 10.0, mirror );
2007-08-23 04:28:46 +00:00
}
}
2011-12-02 15:09:57 +00:00
fputs( "$ENDSHAPES\n\n", aFile );
}
2009-11-02 20:36:20 +00:00
/* Creates the section $COMPONENTS (Footprints placement)
2011-12-02 15:09:57 +00:00
* Bottom side components are difficult to handle: shapes must be mirrored or
* flipped, silk layers need to be handled correctly and so on. Also it seems
* that *noone* follows the specs...
2007-08-23 04:28:46 +00:00
*/
2011-12-02 15:09:57 +00:00
static void CreateComponentsSection( FILE* aFile, BOARD* aPcb )
{
2011-12-02 15:09:57 +00:00
fputs( "$COMPONENTS\n", aFile );
2007-08-23 04:28:46 +00:00
for( MODULE* module = aPcb->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
TEXTE_MODULE* textmod;
const char* mirror;
const char* flip;
double orient = module->GetOrientation();
if( module->GetFlag() )
2007-08-23 04:28:46 +00:00
{
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
mirror = "0";
flip = "FLIP";
2007-08-23 04:28:46 +00:00
NEGATE_AND_NORMALIZE_ANGLE_POS( orient );
}
else
{
mirror = "0";
flip = "0";
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, "\nCOMPONENT %s\n",
TO_UTF8( module->GetReference() ) );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, "DEVICE %s_%s\n",
TO_UTF8( module->GetReference() ),
TO_UTF8( module->GetValue() ) );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, "PLACE %g %g\n",
MapXTo( module->GetPosition().x ),
MapYTo( module->GetPosition().y ) );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, "LAYER %s\n",
(module->GetFlag()) ? "BOTTOM" : "TOP" );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, "ROTATION %g\n",
orient / 10.0 );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, "SHAPE %s %s %s\n",
TO_UTF8( module->GetReference() ),
mirror, flip );
2011-12-02 15:09:57 +00:00
// Text on silk layer: RefDes and value (are they actually useful?)
textmod = &module->Reference();
2011-12-02 15:09:57 +00:00
for( int ii = 0; ii < 2; ii++ )
2007-08-23 04:28:46 +00:00
{
double orient = textmod->GetOrientation();
wxString layer = GenCADLayerName[(module->GetFlag()) ?
SILKSCREEN_N_BACK : SILKSCREEN_N_FRONT];
2011-12-02 15:09:57 +00:00
fprintf( aFile, "TEXT %g %g %g %g %s %s \"%s\"",
textmod->GetPos0().x / SCALE_FACTOR,
2011-12-12 08:37:05 +00:00
-textmod->GetPos0().y / SCALE_FACTOR,
textmod->GetSize().x / SCALE_FACTOR,
orient / 10.0,
mirror,
TO_UTF8( layer ),
TO_UTF8( textmod->GetText() ) );
// Please note, the width is approx
2011-12-02 15:09:57 +00:00
fprintf( aFile, " 0 0 %g %g\n",
( textmod->GetSize().x * textmod->GetLength() ) / SCALE_FACTOR,
2012-02-19 04:02:19 +00:00
textmod->GetSize().y / SCALE_FACTOR );
2007-08-23 04:28:46 +00:00
textmod = &module->Value(); // Dirty trick for the second iteration
2007-08-23 04:28:46 +00:00
}
2011-12-02 15:09:57 +00:00
// The SHEET is a 'generic description' for referencing the component
fprintf( aFile, "SHEET \"RefDes: %s, Value: %s\"\n",
TO_UTF8( module->GetReference() ),
TO_UTF8( module->GetValue() ) );
2007-08-23 04:28:46 +00:00
}
2011-12-02 15:09:57 +00:00
fputs( "$ENDCOMPONENTS\n\n", aFile );
}
2011-12-02 15:09:57 +00:00
/* Emit the netlist (which is actually the thing for which GenCAD is used these
* days!); tracks are handled later */
static void CreateSignalsSection( FILE* aFile, BOARD* aPcb )
{
2009-11-02 20:36:20 +00:00
wxString msg;
NETINFO_ITEM* net;
2009-11-02 20:36:20 +00:00
D_PAD* pad;
MODULE* module;
int NbNoConn = 1;
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
fputs( "$SIGNALS\n", aFile );
2007-08-23 04:28:46 +00:00
for( unsigned ii = 0; ii < aPcb->GetNetCount(); ii++ )
2007-08-23 04:28:46 +00:00
{
net = aPcb->FindNet( ii );
if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
2007-08-23 04:28:46 +00:00
{
wxString msg; msg << wxT( "NoConnection" ) << NbNoConn++;
2011-03-03 19:08:13 +00:00
net->SetNetname( msg );
2007-08-23 04:28:46 +00:00
}
if( net->GetNet() <= 0 ) // dummy netlist (no connection)
2007-08-23 04:28:46 +00:00
continue;
msg = wxT( "SIGNAL " ) + net->GetNetname();
2011-12-02 15:09:57 +00:00
fputs( TO_UTF8( msg ), aFile );
fputs( "\n", aFile );
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
for( module = aPcb->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
for( pad = module->Pads(); pad != NULL; pad = pad->Next() )
2007-08-23 04:28:46 +00:00
{
wxString padname;
if( pad->GetNet() != net->GetNet() )
2007-08-23 04:28:46 +00:00
continue;
2007-08-23 04:28:46 +00:00
pad->ReturnStringPadName( padname );
2011-12-02 15:09:57 +00:00
msg.Printf( wxT( "NODE %s %s" ),
GetChars( module->GetReference() ),
GetChars( padname ) );
2011-12-02 15:09:57 +00:00
fputs( TO_UTF8( msg ), aFile );
fputs( "\n", aFile );
2007-08-23 04:28:46 +00:00
}
}
}
2011-12-02 15:09:57 +00:00
fputs( "$ENDSIGNALS\n\n", aFile );
}
2007-08-23 04:28:46 +00:00
// Creates the header section
2011-12-02 15:09:57 +00:00
static bool CreateHeaderInfoData( FILE* aFile, PCB_EDIT_FRAME* aFrame )
{
2007-08-23 04:28:46 +00:00
wxString msg;
2012-08-29 16:59:50 +00:00
BOARD *board = aFrame->GetBoard();
2011-12-02 15:09:57 +00:00
fputs( "$HEADER\n", aFile );
fputs( "GENCAD 1.4\n", aFile );
// Please note: GenCAD syntax requires quoted strings if they can contain spaces
msg.Printf( wxT( "USER \"%s %s\"\n" ),
GetChars( wxGetApp().GetAppName() ),
GetChars( GetBuildVersion() ) );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fputs( TO_UTF8( msg ), aFile );
2012-08-29 16:59:50 +00:00
msg = wxT( "DRAWING \"" ) + board->GetFileName() + wxT( "\"\n" );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fputs( TO_UTF8( msg ), aFile );
const TITLE_BLOCK& tb = aFrame->GetTitleBlock();
msg = wxT( "REVISION \"" ) + tb.GetRevision() + wxT( " " ) + tb.GetDate() + wxT( "\"\n" );
2011-12-02 15:09:57 +00:00
fputs( TO_UTF8( msg ), aFile );
fputs( "UNITS INCH\n", aFile );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
msg.Printf( wxT( "ORIGIN %g %g\n" ),
MapXTo( aFrame->GetOriginAxisPosition().x ),
MapYTo( aFrame->GetOriginAxisPosition().y ) );
2011-12-02 15:09:57 +00:00
fputs( TO_UTF8( msg ), aFile );
2011-12-02 15:09:57 +00:00
fputs( "INTERTRACK 0\n", aFile );
fputs( "$ENDHEADER\n\n", aFile );
2007-08-23 04:28:46 +00:00
return true;
}
/*
2009-11-02 20:36:20 +00:00
* Sort function used to sort tracks segments:
* items are sorted by netcode, then by width then by layer
2007-08-23 04:28:46 +00:00
*/
2011-12-02 15:09:57 +00:00
static int TrackListSortByNetcode( const void* refptr, const void* objptr )
{
2007-08-23 04:28:46 +00:00
const TRACK* ref, * cmp;
int diff;
ref = *( (TRACK**) refptr );
cmp = *( (TRACK**) objptr );
2009-11-02 20:36:20 +00:00
if( ( diff = ref->GetNet() - cmp->GetNet() ) )
2007-08-23 04:28:46 +00:00
return diff;
if( ( diff = ref->GetWidth() - cmp->GetWidth() ) )
2007-08-23 04:28:46 +00:00
return diff;
2009-11-02 20:36:20 +00:00
if( ( diff = ref->GetLayer() - cmp->GetLayer() ) )
2007-08-23 04:28:46 +00:00
return diff;
return 0;
}
2007-08-23 04:28:46 +00:00
/* Creates the section ROUTES
* that handles tracks, vias
2009-11-02 20:36:20 +00:00
* TODO: add zones
2007-08-23 04:28:46 +00:00
* section:
* $ROUTE
* ...
* $ENROUTE
2009-11-02 20:36:20 +00:00
* Track segments must be sorted by nets
2007-08-23 04:28:46 +00:00
*/
2011-12-02 15:09:57 +00:00
static void CreateRoutesSection( FILE* aFile, BOARD* aPcb )
{
TRACK* track, ** tracklist;
int vianum = 1;
int old_netcode, old_width, old_layer;
int nbitems, ii;
LAYER_MSK master_layermask = aPcb->GetDesignSettings().GetEnabledLayers();
2007-08-23 04:28:46 +00:00
2009-11-02 20:36:20 +00:00
// Count items
2007-08-23 04:28:46 +00:00
nbitems = 0;
2011-12-02 15:09:57 +00:00
for( track = aPcb->m_Track; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
nbitems++;
2011-12-02 15:09:57 +00:00
for( track = aPcb->m_Zone; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
if( track->Type() == PCB_ZONE_T )
2007-08-23 04:28:46 +00:00
nbitems++;
}
tracklist = (TRACK**) operator new( (nbitems + 1)* sizeof( TRACK* ) );
2007-08-23 04:28:46 +00:00
nbitems = 0;
2011-12-02 15:09:57 +00:00
for( track = aPcb->m_Track; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
tracklist[nbitems++] = track;
2011-12-02 15:09:57 +00:00
for( track = aPcb->m_Zone; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
if( track->Type() == PCB_ZONE_T )
2007-08-23 04:28:46 +00:00
tracklist[nbitems++] = track;
}
tracklist[nbitems] = NULL;
2011-12-02 15:09:57 +00:00
qsort( tracklist, nbitems, sizeof(TRACK*), TrackListSortByNetcode );
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
fputs( "$ROUTES\n", aFile );
2007-08-23 04:28:46 +00:00
old_netcode = -1; old_width = -1; old_layer = -1;
2007-08-23 04:28:46 +00:00
for( ii = 0; ii < nbitems; ii++ )
{
track = tracklist[ii];
2007-10-13 06:18:44 +00:00
if( old_netcode != track->GetNet() )
2007-08-23 04:28:46 +00:00
{
2007-10-13 06:18:44 +00:00
old_netcode = track->GetNet();
2011-12-02 15:09:57 +00:00
NETINFO_ITEM* net = aPcb->FindNet( track->GetNet() );
2009-11-02 20:36:20 +00:00
wxString netname;
if( net && (net->GetNetname() != wxEmptyString) )
netname = net->GetNetname();
2007-08-23 04:28:46 +00:00
else
netname = wxT( "_noname_" );
2011-12-02 15:09:57 +00:00
fprintf( aFile, "ROUTE %s\n", TO_UTF8( netname ) );
2007-08-23 04:28:46 +00:00
}
if( old_width != track->GetWidth() )
2007-08-23 04:28:46 +00:00
{
old_width = track->GetWidth();
fprintf( aFile, "TRACK TRACK%d\n", track->GetWidth() );
2007-08-23 04:28:46 +00:00
}
if( (track->Type() == PCB_TRACE_T) || (track->Type() == PCB_ZONE_T) )
2007-08-23 04:28:46 +00:00
{
if( old_layer != track->GetLayer() )
{
old_layer = track->GetLayer();
2011-12-02 15:09:57 +00:00
fprintf( aFile, "LAYER %s\n",
TO_UTF8( GenCADLayerName[track->GetLayer() & 0x1F] ) );
2007-08-23 04:28:46 +00:00
}
2011-12-02 15:09:57 +00:00
fprintf( aFile, "LINE %g %g %g %g\n",
MapXTo( track->GetStart().x ), MapYTo( track->GetStart().y ),
MapXTo( track->GetEnd().x ), MapYTo( track->GetEnd().y ) );
2007-08-23 04:28:46 +00:00
}
if( track->Type() == PCB_VIA_T )
2007-08-23 04:28:46 +00:00
{
2011-12-02 15:09:57 +00:00
fprintf( aFile, "VIA VIA%d.%d.%X %g %g ALL %g via%d\n",
track->GetWidth(), track->GetDrillValue(),
track->GetLayerMask() & master_layermask,
MapXTo( track->GetStart().x ), MapYTo( track->GetStart().y ),
track->GetDrillValue() / SCALE_FACTOR, vianum++ );
2007-08-23 04:28:46 +00:00
}
}
2011-12-02 15:09:57 +00:00
fputs( "$ENDROUTES\n\n", aFile );
2007-08-23 04:28:46 +00:00
delete tracklist;
}
/* Creates the section $DEVICES
2009-11-02 20:36:20 +00:00
* This is a list of footprints properties
* ( Shapes are in section $SHAPE )
2007-08-23 04:28:46 +00:00
*/
2011-12-02 15:09:57 +00:00
static void CreateDevicesSection( FILE* aFile, BOARD* aPcb )
{
2007-08-23 04:28:46 +00:00
MODULE* module;
2011-12-02 15:09:57 +00:00
fputs( "$DEVICES\n", aFile );
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
for( module = aPcb->m_Modules; module != NULL; module = module->Next() )
{
fprintf( aFile, "DEVICE \"%s\"\n", TO_UTF8( module->GetReference() ) );
fprintf( aFile, "PART \"%s\"\n", TO_UTF8( module->GetValue() ) );
fprintf( aFile, "PACKAGE \"%s\"\n", TO_UTF8( module->GetLibRef() ) );
// The TYPE attribute is almost freeform
const char* ty = "TH";
if( module->GetAttributes() & MOD_CMS )
2011-12-02 15:09:57 +00:00
ty = "SMD";
if( module->GetAttributes() & MOD_VIRTUAL )
2011-12-02 15:09:57 +00:00
ty = "VIRTUAL";
fprintf( aFile, "TYPE %s\n", ty );
2007-08-23 04:28:46 +00:00
}
2011-12-02 15:09:57 +00:00
fputs( "$ENDDEVICES\n\n", aFile );
}
/* Creates the section $BOARD.
2011-12-02 15:09:57 +00:00
* We output here only the board perimeter
2007-08-23 04:28:46 +00:00
*/
2011-12-02 15:09:57 +00:00
static void CreateBoardSection( FILE* aFile, BOARD* aPcb )
{
2011-12-02 15:09:57 +00:00
fputs( "$BOARD\n", aFile );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
// Extract the board edges
for( EDA_ITEM* drawing = aPcb->m_Drawings;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
drawing != 0;
drawing = drawing->Next() )
2011-12-02 15:09:57 +00:00
{
if( drawing->Type() == PCB_LINE_T )
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
{
DRAWSEGMENT* drawseg = dynamic_cast<DRAWSEGMENT*>( drawing );
if( drawseg->GetLayer() == EDGE_N )
{
// XXX GenCAD supports arc boundaries but I've seen nothing that reads them
fprintf( aFile, "LINE %g %g %g %g\n",
2011-12-14 04:29:25 +00:00
MapXTo( drawseg->GetStart().x ), MapYTo( drawseg->GetStart().y ),
MapXTo( drawseg->GetEnd().x ), MapYTo( drawseg->GetEnd().y ) );
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
}
}
2011-12-02 15:09:57 +00:00
fputs( "$ENDBOARD\n\n", aFile );
}
2009-11-02 20:36:20 +00:00
/* Creates the section "$TRACKS"
* This sections give the list of widths (tools) used in tracks and vias
2007-08-23 04:28:46 +00:00
* format:
* $TRACK
* TRACK <name> <width>
* $ENDTRACK
*
2009-11-02 20:36:20 +00:00
* Each tool name is build like this: "TRACK" + track width.
* For instance for a width = 120 : name = "TRACK120".
2007-08-23 04:28:46 +00:00
*/
2011-12-02 15:09:57 +00:00
static void CreateTracksInfoData( FILE* aFile, BOARD* aPcb )
{
2007-08-23 04:28:46 +00:00
TRACK* track;
2009-11-02 20:36:20 +00:00
int last_width = -1;
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
// Find thickness used for traces
// XXX could use the same sorting approach used for pads
2007-08-23 04:28:46 +00:00
2009-05-23 15:53:47 +00:00
std::vector <int> trackinfo;
2007-08-23 04:28:46 +00:00
2009-11-02 20:36:20 +00:00
unsigned ii;
2011-12-02 15:09:57 +00:00
for( track = aPcb->m_Track; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
if( last_width != track->GetWidth() ) // Find a thickness already used.
2007-08-23 04:28:46 +00:00
{
for( ii = 0; ii < trackinfo.size(); ii++ )
2007-08-23 04:28:46 +00:00
{
if( trackinfo[ii] == track->GetWidth() )
2009-11-02 20:36:20 +00:00
break;
2007-08-23 04:28:46 +00:00
}
2009-11-02 20:36:20 +00:00
if( ii == trackinfo.size() ) // not found
trackinfo.push_back( track->GetWidth() );
2009-05-23 15:53:47 +00:00
last_width = track->GetWidth();
2009-11-02 20:36:20 +00:00
}
2007-08-23 04:28:46 +00:00
}
2011-12-02 15:09:57 +00:00
for( track = aPcb->m_Zone; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
if( last_width != track->GetWidth() ) // Find a thickness already used.
2007-08-23 04:28:46 +00:00
{
for( ii = 0; ii < trackinfo.size(); ii++ )
2007-08-23 04:28:46 +00:00
{
if( trackinfo[ii] == track->GetWidth() )
2009-11-02 20:36:20 +00:00
break;
2007-08-23 04:28:46 +00:00
}
2009-11-02 20:36:20 +00:00
if( ii == trackinfo.size() ) // not found
trackinfo.push_back( track->GetWidth() );
2009-05-23 15:53:47 +00:00
last_width = track->GetWidth();
2007-08-23 04:28:46 +00:00
}
}
// Write data
2011-12-02 15:09:57 +00:00
fputs( "$TRACKS\n", aFile );
for( ii = 0; ii < trackinfo.size(); ii++ )
2007-08-23 04:28:46 +00:00
{
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
fprintf( aFile, "TRACK TRACK%d %g\n", trackinfo[ii],
trackinfo[ii] / SCALE_FACTOR );
2007-08-23 04:28:46 +00:00
}
2011-12-02 15:09:57 +00:00
fputs( "$ENDTRACKS\n\n", aFile );
}
2009-11-02 20:36:20 +00:00
/* Creates the shape of a footprint (section SHAPE)
* The shape is always given "normal" (Orient 0, not mirrored)
2011-12-02 15:09:57 +00:00
* It's almost guaranteed that the silk layer will be imported wrong but
* the shape also contains the pads!
2007-08-23 04:28:46 +00:00
*/
2011-12-02 15:09:57 +00:00
static void FootprintWriteShape( FILE* aFile, MODULE* module )
{
EDGE_MODULE* PtEdge;
EDA_ITEM* PtStruct;
2011-12-02 15:09:57 +00:00
// Control Y axis change sign for flipped modules
int Yaxis_sign = -1;
2011-12-02 15:09:57 +00:00
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
// Flip for bottom side components
if( module->GetFlag() )
2011-12-02 15:09:57 +00:00
Yaxis_sign = 1;
2007-08-23 04:28:46 +00:00
2009-11-02 20:36:20 +00:00
/* creates header: */
fprintf( aFile, "\nSHAPE %s\n", TO_UTF8( module->GetReference() ) );
2011-12-02 15:09:57 +00:00
if( module->GetAttributes() & MOD_VIRTUAL )
2011-12-02 15:09:57 +00:00
{
fprintf( aFile, "INSERT SMD\n" );
2011-12-02 15:09:57 +00:00
}
else
{
if( module->GetAttributes() & MOD_CMS )
{
fprintf( aFile, "INSERT SMD\n" );
2011-12-02 15:09:57 +00:00
}
else
{
fprintf( aFile, "INSERT TH\n" );
}
}
#if 0 /* ATTRIBUTE name and value is unspecified and the original exporter
* got the syntax wrong, so CAM350 rejected the whole shape! */
2007-08-23 04:28:46 +00:00
if( module->m_Attributs != MOD_DEFAULT )
{
2011-12-02 15:09:57 +00:00
fprintf( aFile, "ATTRIBUTE" );
2007-08-23 04:28:46 +00:00
if( module->m_Attributs & MOD_CMS )
2011-12-02 15:09:57 +00:00
fprintf( aFile, " PAD_SMD" );
2007-08-23 04:28:46 +00:00
if( module->m_Attributs & MOD_VIRTUAL )
2011-12-02 15:09:57 +00:00
fprintf( aFile, " VIRTUAL" );
2011-12-02 15:09:57 +00:00
fprintf( aFile, "\n" );
2007-08-23 04:28:46 +00:00
}
2011-12-02 15:09:57 +00:00
#endif
2007-08-23 04:28:46 +00:00
2011-12-02 15:09:57 +00:00
// Silk outline; wildly interpreted by various importers:
// CAM350 read it right but only closed shapes
// ProntoPlace double-flip it (at least the pads are correct)
// GerberTool usually get it right...
for( PtStruct = module->GraphicalItems(); PtStruct != NULL; PtStruct = PtStruct->Next() )
2007-08-23 04:28:46 +00:00
{
2011-12-02 15:09:57 +00:00
switch( PtStruct->Type() )
2007-08-23 04:28:46 +00:00
{
case PCB_MODULE_TEXT_T:
// If we wanted to export text, this is not the correct section
2007-08-23 04:28:46 +00:00
break;
case PCB_MODULE_EDGE_T:
2011-12-02 15:09:57 +00:00
PtEdge = (EDGE_MODULE*) PtStruct;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
if( PtEdge->GetLayer() == SILKSCREEN_N_FRONT
|| PtEdge->GetLayer() == SILKSCREEN_N_BACK )
2011-12-02 15:09:57 +00:00
{
2011-12-14 04:29:25 +00:00
switch( PtEdge->GetShape() )
{
case S_SEGMENT:
2011-12-02 15:09:57 +00:00
fprintf( aFile, "LINE %g %g %g %g\n",
(PtEdge->m_Start0.x) / SCALE_FACTOR,
(Yaxis_sign * PtEdge->m_Start0.y) / SCALE_FACTOR,
(PtEdge->m_End0.x) / SCALE_FACTOR,
(Yaxis_sign * PtEdge->m_End0.y ) / SCALE_FACTOR );
break;
2007-08-23 04:28:46 +00:00
case S_CIRCLE:
{
int radius = KiROUND( GetLineLength( PtEdge->m_End0,
PtEdge->m_Start0 ) );
fprintf( aFile, "CIRCLE %g %g %g\n",
PtEdge->m_Start0.x / SCALE_FACTOR,
Yaxis_sign * PtEdge->m_Start0.y / SCALE_FACTOR,
radius / SCALE_FACTOR );
break;
}
2007-08-23 04:28:46 +00:00
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
case S_ARC:
{
int arcendx, arcendy;
arcendx = PtEdge->m_End0.x - PtEdge->m_Start0.x;
arcendy = PtEdge->m_End0.y - PtEdge->m_Start0.y;
2011-12-14 04:29:25 +00:00
RotatePoint( &arcendx, &arcendy, -PtEdge->GetAngle() );
arcendx += PtEdge->GetStart0().x;
arcendy += PtEdge->GetStart0().y;
if( Yaxis_sign == -1 )
2011-12-02 15:09:57 +00:00
{
// Flipping Y flips the arc direction too
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
(arcendx) / SCALE_FACTOR,
(Yaxis_sign * arcendy) / SCALE_FACTOR,
(PtEdge->m_End0.x) / SCALE_FACTOR,
2011-12-14 04:29:25 +00:00
(Yaxis_sign * PtEdge->GetEnd0().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",
2011-12-14 04:29:25 +00:00
(PtEdge->GetEnd0().x) / SCALE_FACTOR,
(Yaxis_sign * PtEdge->GetEnd0().y) / SCALE_FACTOR,
(arcendx) / SCALE_FACTOR,
(Yaxis_sign * arcendy) / SCALE_FACTOR,
2011-12-14 04:29:25 +00:00
(PtEdge->GetStart0().x) / SCALE_FACTOR,
(Yaxis_sign * PtEdge->GetStart0().y) / SCALE_FACTOR );
}
break;
}
2007-08-23 04:28:46 +00:00
default:
DisplayError( NULL, wxT( "Type Edge Module invalid." ) );
break;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
}
2011-12-02 15:09:57 +00:00
}
2007-08-23 04:28:46 +00:00
break;
default:
break;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
}
2007-08-23 04:28:46 +00:00
}
}