kicad/pcbnew/exporters/export_gencad.cpp

1408 lines
45 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 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-2016 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>
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
#include <pgm_base.h>
2018-01-29 20:58:58 +00:00
#include <pcb_edit_frame.h>
#include <trigo.h>
#include <build_version.h>
#include <macros.h>
#include <pcbnew.h>
2017-10-04 09:57:59 +00:00
#include <dialogs/dialog_gencad_export_options.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_edge_mod.h>
#include <hash_eda.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 );
static void FootprintWriteShape( FILE* File, MODULE* module, const wxString& aShapeName );
2009-11-02 20:36:20 +00:00
// layer names for Gencad export
#if 0 // was:
static const wxString GenCADLayerName[] =
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" )
};
#else
static std::string GenCADLayerName( int aCuCount, PCB_LAYER_ID aId )
{
if( IsCopperLayer( aId ) )
{
if( aId == F_Cu )
return "TOP";
else if( aId == B_Cu )
2014-06-30 15:03:20 +00:00
return "BOTTOM";
else if( aId <= 14 )
{
2014-06-30 15:03:20 +00:00
return StrPrintf( "INNER%d", aCuCount - aId - 1 );
}
else
{
2014-06-30 15:03:20 +00:00
return StrPrintf( "LAYER%d", aId );
}
}
else
{
const char* txt;
// using a switch to clearly show mapping & catch out of bounds index.
switch( aId )
{
// Technicals
case B_Adhes: txt = "B.Adhes"; break;
case F_Adhes: txt = "F.Adhes"; break;
case B_Paste: txt = "SOLDERPASTE_BOTTOM"; break;
case F_Paste: txt = "SOLDERPASTE_TOP"; break;
case B_SilkS: txt = "SILKSCREEN_BOTTOM"; break;
case F_SilkS: txt = "SILKSCREEN_TOP"; break;
case B_Mask: txt = "SOLDERMASK_BOTTOM"; break;
case F_Mask: txt = "SOLDERMASK_TOP"; break;
// Users
case Dwgs_User: txt = "Dwgs.User"; break;
case Cmts_User: txt = "Cmts.User"; break;
case Eco1_User: txt = "Eco1.User"; break;
case Eco2_User: txt = "Eco2.User"; break;
case Edge_Cuts: txt = "Edge.Cuts"; break;
case Margin: txt = "Margin"; break;
// Footprint
case F_CrtYd: txt = "F_CrtYd"; break;
case B_CrtYd: txt = "B_CrtYd"; break;
case F_Fab: txt = "F_Fab"; break;
case B_Fab: txt = "B_Fab"; break;
default:
wxASSERT_MSG( 0, wxT( "aId UNEXPECTED" ) );
txt = "BAD-INDEX!"; break;
}
return txt;
}
2017-11-02 20:41:29 +00:00
}
static const PCB_LAYER_ID gc_seq[] = {
2014-06-30 15:03:20 +00:00
B_Cu,
In30_Cu,
In29_Cu,
In28_Cu,
In27_Cu,
In26_Cu,
In25_Cu,
In24_Cu,
In23_Cu,
In22_Cu,
In21_Cu,
In20_Cu,
In19_Cu,
In18_Cu,
In17_Cu,
In16_Cu,
In15_Cu,
In14_Cu,
In13_Cu,
In12_Cu,
In11_Cu,
In10_Cu,
In9_Cu,
In8_Cu,
In7_Cu,
In6_Cu,
In5_Cu,
In4_Cu,
In3_Cu,
In2_Cu,
In1_Cu,
F_Cu,
};
// flipped layer name for Gencad export (to make CAM350 imports correct)
static std::string GenCADLayerNameFlipped( int aCuCount, PCB_LAYER_ID aId )
{
2014-06-30 15:03:20 +00:00
if( 1<= aId && aId <= 14 )
{
2014-06-30 15:03:20 +00:00
return StrPrintf( "INNER%d", 14 - aId );
}
2014-06-30 15:03:20 +00:00
return GenCADLayerName( aCuCount, aId );
2017-11-02 20:41:29 +00:00
}
static wxString escapeString( const wxString& aString )
{
wxString copy( aString );
copy.Replace( "\"", "\\\"" );
return copy;
}
#endif
2014-06-30 15:03:20 +00:00
static std::string fmt_mask( LSET aSet )
{
#if 0
return aSet.FmtHex();
#else
return StrPrintf( "%08x", (unsigned) ( aSet & LSET::AllCuMask() ).to_ulong() );
#endif
}
// Export options
static bool flipBottomPads;
static bool uniquePins;
static bool individualShapes;
static bool storeOriginCoords;
2011-12-02 15:09:57 +00:00
// These are the export origin (the auxiliary axis)
static int GencadOffsetX, GencadOffsetY;
// Association between shape names (using shapeName index) and components
static std::map<MODULE*, int> componentShapes;
static std::map<int, wxString> shapeNames;
static const wxString& getShapeName( MODULE* aModule )
{
static const wxString invalid( "invalid" );
if( individualShapes )
return aModule->GetReference();
auto itShape = componentShapes.find( aModule );
wxCHECK( itShape != componentShapes.end(), invalid );
auto itName = shapeNames.find( itShape->second );
wxCHECK( itName != shapeNames.end(), invalid );
return itName->second;
}
// GerbTool chokes on units different than INCH so this is the conversion factor
const static double SCALE_FACTOR = 1000.0 * IU_PER_MILS;
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 )
{
2017-10-04 09:57:59 +00:00
DIALOG_GENCAD_EXPORT_OPTIONS optionsDialog( this );
2017-10-04 09:57:59 +00:00
if( optionsDialog.ShowModal() == wxID_CANCEL )
2007-08-23 04:28:46 +00:00
return;
2017-10-04 09:57:59 +00:00
FILE* file = wxFopen( optionsDialog.GetFileName(), "wt" );
2017-10-04 09:57:59 +00:00
if( !file )
{
DisplayError( this, wxString::Format( _( "Unable to create \"%s\"" ),
2017-10-04 09:57:59 +00:00
GetChars( optionsDialog.GetFileName() ) ) );
return;
2007-08-23 04:28:46 +00:00
}
2017-10-04 09:57:59 +00:00
// Get options
flipBottomPads = optionsDialog.GetOption( FLIP_BOTTOM_PADS );
uniquePins = optionsDialog.GetOption( UNIQUE_PIN_NAMES );
individualShapes = optionsDialog.GetOption( INDIVIDUAL_SHAPES );
storeOriginCoords = optionsDialog.GetOption( STORE_ORIGIN_COORDS );
2017-10-04 09:57:59 +00:00
// Switch the locale to standard C (needed to print floating point numbers)
LOCALE_IO toggle;
2011-12-02 15:09:57 +00:00
// 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 = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? GetAuxOrigin().x : 0;
GencadOffsetY = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? GetAuxOrigin().y : 0;
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();
MODULE* module;
for( module = pcb->m_Modules; module; module = module->Next() )
{
module->SetFlag( 0 );
if( module->GetLayer() == B_Cu )
{
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 );
// Undo the footprints modifications (flipped footprints)
for( module = pcb->m_Modules; module; module = module->Next() )
{
if( module->GetFlag() )
{
module->Flip( module->GetPosition() );
module->SetFlag( 0 );
}
}
componentShapes.clear();
shapeNames.clear();
}
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
{
VIA* padref = *(VIA**) aRefptr;
VIA* padcmp = *(VIA**) 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->GetLayerSet() != padcmp->GetLayerSet() )
return padref->GetLayerSet().FmtBin().compare( padcmp->GetLayerSet().FmtBin() );
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<VIA*> vias;
std::vector<VIA*> 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
LSET master_layermask = aPcb->GetDesignSettings().GetEnabledLayers();
int cu_count = aPcb->GetCopperLayerCount();
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
for( VIA* via = GetFirstVia( aPcb->m_Track ); via;
via = GetFirstVia( via->Next() ) )
++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
{
vias.push_back( via );
2011-12-02 15:09:57 +00:00
}
qsort( &vias[0], vias.size(), sizeof(VIA*), ViaSort );
2011-12-02 15:09:57 +00:00
// Emit vias pads
TRACK* old_via = 0;
2014-06-30 15:03:20 +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
for( unsigned i = 0; i < vias.size(); i++ )
2011-12-02 15:09:57 +00:00
{
VIA* via = vias[i];
2014-06-30 15:03:20 +00:00
if( old_via && 0 == ViaSort( &old_via, &via ) )
continue;
old_via = via;
viastacks.push_back( via );
fprintf( aFile, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n",
via->GetWidth(), via->GetDrillValue(),
fmt_mask( via->GetLayerSet() & master_layermask ).c_str(),
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];
const wxPoint& off = pad->GetOffset();
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:
wxASSERT_MSG( false, "Pad type not implemented" );
// fall-through
case PAD_SHAPE_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",
off.x / SCALE_FACTOR,
-off.y / SCALE_FACTOR,
2012-02-19 04:02:19 +00:00
pad->GetSize().x / (SCALE_FACTOR * 2) );
2007-08-23 04:28:46 +00:00
break;
case PAD_SHAPE_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",
(-dx + off.x ) / SCALE_FACTOR,
(-dy - off.y ) / SCALE_FACTOR,
dx / (SCALE_FACTOR / 2), dy / (SCALE_FACTOR / 2) );
2007-08-23 04:28:46 +00:00
break;
case PAD_SHAPE_ROUNDRECT:
case PAD_SHAPE_OVAL:
2007-08-23 04:28:46 +00:00
{
const wxSize& size = pad->GetSize();
int radius;
if( pad->GetShape() == PAD_SHAPE_ROUNDRECT )
radius = pad->GetRoundRectCornerRadius();
else
radius = std::min( size.x, size.y ) / 2;
int lineX = size.x / 2 - radius;
int lineY = size.y / 2 - radius;
fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
2014-06-30 15:03:20 +00:00
// bottom left arc
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
( off.x - lineX - radius ) / SCALE_FACTOR,
( -off.y - lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
( -off.y - lineY - radius ) / SCALE_FACTOR,
( off.x - lineX ) / SCALE_FACTOR, ( -off.y - lineY ) / SCALE_FACTOR );
// bottom line
if( lineX > 0 )
2014-06-30 15:03:20 +00:00
{
fprintf( aFile, "LINE %g %g %g %g\n",
( off.x - lineX ) / SCALE_FACTOR,
( -off.y - lineY - radius ) / SCALE_FACTOR,
( off.x + lineX ) / SCALE_FACTOR,
( -off.y - lineY - radius ) / SCALE_FACTOR );
}
// bottom right arc
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
( off.x + lineX ) / SCALE_FACTOR,
( -off.y - lineY - radius ) / SCALE_FACTOR,
( off.x + lineX + radius ) / SCALE_FACTOR,
( -off.y - lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
( -off.y - lineY ) / SCALE_FACTOR );
2014-06-30 15:03:20 +00:00
// right line
if( lineY > 0 )
{
2014-06-30 15:03:20 +00:00
fprintf( aFile, "LINE %g %g %g %g\n",
( off.x + lineX + radius ) / SCALE_FACTOR,
( -off.y + lineY ) / SCALE_FACTOR,
( off.x + lineX + radius ) / SCALE_FACTOR,
( -off.y - lineY ) / SCALE_FACTOR );
2014-06-30 15:03:20 +00:00
}
// top right arc
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
( off.x + lineX + radius ) / SCALE_FACTOR,
( -off.y + lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
( -off.y + lineY + radius ) / SCALE_FACTOR,
( off.x + lineX ) / SCALE_FACTOR, ( -off.y + lineY ) / SCALE_FACTOR );
// top line
if( lineX > 0 )
2014-06-30 15:03:20 +00:00
{
fprintf( aFile, "LINE %g %g %g %g\n"
, ( off.x - lineX ) / SCALE_FACTOR,
( -off.y + lineY + radius ) / SCALE_FACTOR,
( off.x + lineX ) / SCALE_FACTOR,
( -off.y + lineY + radius ) / SCALE_FACTOR );
}
// top left arc
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
( off.x - lineX ) / SCALE_FACTOR,
( -off.y + lineY + radius ) / SCALE_FACTOR,
( off.x - lineX - radius ) / SCALE_FACTOR,
( -off.y + lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
( -off.y + lineY ) / SCALE_FACTOR );
2014-06-30 15:03:20 +00:00
// left line
if( lineY > 0 )
{
2014-06-30 15:03:20 +00:00
fprintf( aFile, "LINE %g %g %g %g\n",
( off.x - lineX - radius ) / SCALE_FACTOR,
( -off.y - lineY ) / SCALE_FACTOR,
( off.x - lineX - radius ) / SCALE_FACTOR,
( -off.y + lineY ) / SCALE_FACTOR );
2014-06-30 15:03:20 +00:00
}
2007-08-23 04:28:46 +00:00
}
break;
case PAD_SHAPE_TRAPEZOID:
{
fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
wxPoint poly[4];
pad->BuildPadPolygon( poly, wxSize( 0, 0 ), 0 );
for( int cur = 0; cur < 4; ++cur )
{
int next = ( cur + 1 ) % 4;
fprintf( aFile, "LINE %g %g %g %g\n",
( off.x + poly[cur].x ) / SCALE_FACTOR,
( -off.y - poly[cur].y ) / SCALE_FACTOR,
( off.x + poly[next].x ) / SCALE_FACTOR,
( -off.y - poly[next].y ) / SCALE_FACTOR );
}
}
2007-08-23 04:28:46 +00:00
break;
2017-10-04 14:34:57 +00:00
case PAD_SHAPE_CUSTOM:
{
fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
const SHAPE_POLY_SET& outline = pad->GetCustomShapeAsPolygon();
for( int jj = 0; jj < outline.OutlineCount(); ++jj )
{
const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
int pointCount = poly.PointCount();
for( int ii = 0; ii < pointCount; ii++ )
{
int next = ( ii + 1 ) % pointCount;
fprintf( aFile, "LINE %g %g %g %g\n",
( off.x + poly.CPoint( ii ).x ) / SCALE_FACTOR,
( -off.y - poly.CPoint( ii ).y ) / SCALE_FACTOR,
( off.x + poly.CPoint( next ).x ) / SCALE_FACTOR,
( -off.y - poly.CPoint( next ).y ) / SCALE_FACTOR );
}
}
}
break;
2007-08-23 04:28:46 +00:00
}
}
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++ )
{
VIA* via = viastacks[i];
LSET mask = via->GetLayerSet() & master_layermask;
fprintf( aFile, "PADSTACK VIA%d.%d.%s %g\n",
via->GetWidth(), via->GetDrillValue(),
2014-06-30 15:03:20 +00:00
fmt_mask( mask ).c_str(),
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
2014-06-30 15:03:20 +00:00
for( LSEQ seq = mask.Seq( gc_seq, DIM( gc_seq ) ); seq; ++seq )
++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
{
PCB_LAYER_ID layer = *seq;
fprintf( aFile, "PAD V%d.%d.%s %s 0 0\n",
via->GetWidth(), via->GetDrillValue(),
2014-06-30 15:03:20 +00:00
fmt_mask( mask ).c_str(),
GenCADLayerName( cu_count, layer ).c_str()
);
++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
* Older versions of 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%u %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
LSET pad_set = pad->GetLayerSet() & master_layermask;
2014-06-30 15:03:20 +00:00
// the special gc_seq
for( LSEQ seq = pad_set.Seq( gc_seq, DIM( gc_seq ) ); seq; ++seq )
++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
{
PCB_LAYER_ID layer = *seq;
fprintf( aFile, "PAD P%u %s 0 0\n", i, GenCADLayerName( cu_count, layer ).c_str() );
++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
if( flipBottomPads )
{
2017-10-04 09:57:59 +00:00
fprintf( aFile, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
2017-10-04 09:57:59 +00:00
// the normal PCB_LAYER_ID sequence is inverted from gc_seq[]
for( LSEQ seq = pad_set.Seq(); seq; ++seq )
{
PCB_LAYER_ID layer = *seq;
fprintf( aFile, "PAD P%u %s 0 0\n", i, GenCADLayerNameFlipped( cu_count, layer ).c_str() );
}
++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 );
}
/// Compute hashes for modules without taking into account their position, rotation or layer
static size_t hashModule( const MODULE* aModule )
{
size_t ret = 0x11223344;
constexpr int flags = HASH_FLAGS::POSITION | HASH_FLAGS::REL_COORD
| HASH_FLAGS::ROTATION | HASH_FLAGS::LAYER;
for( const BOARD_ITEM* i = aModule->GraphicalItemsList(); i; i = i->Next() )
ret ^= hash_eda( i, flags );
for( const D_PAD* i = aModule->PadsList(); i; i = i->Next() )
ret ^= hash_eda( i, flags );
return ret;
}
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";
std::map<wxString, size_t> shapes;
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
for( module = aPcb->m_Modules; module; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
if( !individualShapes )
{
// Check if such shape has been already generated, and if so - reuse it
// It is necessary to compute hash (i.e. check all children objects) as
// certain components instances might have been modified on the board.
// In such case the shape will be different despite the same LIB_ID.
wxString shapeName = module->GetFPID().Format();
auto shapeIt = shapes.find( shapeName );
size_t modHash = hashModule( module );
if( shapeIt != shapes.end() )
{
if( modHash != shapeIt->second )
{
// there is an entry for this footprint, but it has a modified shape,
// so we need to create a new entry
wxString newShapeName;
int suffix = 0;
// find an unused name or matching entry
do
{
newShapeName = wxString::Format( "%s_%d", shapeName, suffix );
shapeIt = shapes.find( newShapeName );
++suffix;
}
while( shapeIt != shapes.end() && shapeIt->second != modHash );
shapeName = newShapeName;
}
if( shapeIt != shapes.end() && modHash == shapeIt->second )
{
// shape found, so reuse it
componentShapes[module] = modHash;
continue;
}
}
// new shape
componentShapes[module] = modHash;
shapeNames[modHash] = shapeName;
shapes[shapeName] = modHash;
FootprintWriteShape( aFile, module, shapeName );
}
else // individual shape for each component
{
FootprintWriteShape( aFile, module, module->GetReference() );
}
// set of already emitted pins to check for duplicates
std::set<wxString> pins;
for( pad = module->PadsList(); pad; pad = pad->Next() )
2007-08-23 04:28:46 +00:00
{
/* Padstacks are defined using the correct layers for the pads, therefore to
* all pads need to be marked as TOP to use the padstack information correctly.
*/
layer = "TOP";
pinname = pad->GetName();
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
if( uniquePins )
{
int suffix = 0;
wxString origPinname( pinname );
auto it = pins.find( pinname );
while( it != pins.end() )
{
pinname = wxString::Format( "%s_%d", origPinname, suffix );
++suffix;
it = pins.find( pinname );
}
pins.insert( pinname );
}
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, ( flipBottomPads && module->GetFlag() ) ?
"PIN \"%s\" PAD%dF %g %g %s %g %s\n" :
"PIN \"%s\" PAD%d %g %g %s %g %s\n",
TO_UTF8( escapeString( 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
int cu_count = aPcb->GetCopperLayerCount();
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
const char* mirror;
const char* flip;
double fp_orient = module->GetOrientation();
if( module->GetFlag() )
2007-08-23 04:28:46 +00:00
{
mirror = "MIRRORX";
++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 = "FLIP";
NEGATE_AND_NORMALIZE_ANGLE_POS( fp_orient );
2007-08-23 04:28:46 +00:00
}
else
{
mirror = "0";
flip = "0";
}
fprintf( aFile, "\nCOMPONENT \"%s\"\n",
TO_UTF8( escapeString( module->GetReference() ) ) );
fprintf( aFile, "DEVICE \"DEV_%s\"\n",
TO_UTF8( escapeString( getShapeName( module ) ) ) );
++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",
fp_orient / 10.0 );
fprintf( aFile, "SHAPE \"%s\" %s %s\n",
TO_UTF8( escapeString( getShapeName( module ) ) ),
mirror, flip );
2011-12-02 15:09:57 +00:00
// Text on silk layer: RefDes and value (are they actually useful?)
TEXTE_MODULE *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 txt_orient = textmod->GetTextAngle();
std::string layer = GenCADLayerName( cu_count, module->GetFlag() ? B_SilkS : F_SilkS );
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->GetTextWidth() / SCALE_FACTOR,
txt_orient / 10.0,
mirror,
layer.c_str(),
TO_UTF8( escapeString( textmod->GetText() ) ) );
// Please note, the width is approx
2011-12-02 15:09:57 +00:00
fprintf( aFile, " 0 0 %g %g\n",
( textmod->GetTextWidth() * textmod->GetLength() ) / SCALE_FACTOR,
textmod->GetTextHeight() / 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
{
msg.Printf( "NoConnection%d", NbNoConn++ );
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 \"" ) + escapeString( 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
for( module = aPcb->m_Modules; module; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
for( pad = module->PadsList(); pad; pad = pad->Next() )
2007-08-23 04:28:46 +00:00
{
if( pad->GetNetCode() != net->GetNet() )
2007-08-23 04:28:46 +00:00
continue;
msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
GetChars( escapeString( module->GetReference() ) ),
GetChars( escapeString( pad->GetName() ) ) );
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" ),
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
GetChars( Pgm().App().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 );
// giving 0 as the argument to Map{X,Y}To returns the scaled origin point
++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" ),
storeOriginCoords ? MapXTo( 0 ) : 0,
storeOriginCoords ? MapYTo( 0 ) : 0 );
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 );
if( ( diff = ref->GetNetCode() - cmp->GetNetCode() ) )
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;
LSET master_layermask = aPcb->GetDesignSettings().GetEnabledLayers();
int cu_count = aPcb->GetCopperLayerCount();
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;
for( track = aPcb->m_Track; track; track = track->Next() )
2007-08-23 04:28:46 +00:00
nbitems++;
for( track = aPcb->m_Zone; track; 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;
for( track = aPcb->m_Track; track; track = track->Next() )
2007-08-23 04:28:46 +00:00
tracklist[nbitems++] = track;
for( track = aPcb->m_Zone; track; 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];
if( old_netcode != track->GetNetCode() )
2007-08-23 04:28:46 +00:00
{
old_netcode = track->GetNetCode();
NETINFO_ITEM* net = 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_" );
fprintf( aFile, "ROUTE \"%s\"\n", TO_UTF8( escapeString( 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",
GenCADLayerName( cu_count, track->GetLayer() ).c_str()
);
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
{
const VIA* via = static_cast<const VIA*>(track);
LSET vset = via->GetLayerSet() & master_layermask;
fprintf( aFile, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
via->GetWidth(), via->GetDrillValue(),
2014-06-30 15:03:20 +00:00
fmt_mask( vset ).c_str(),
MapXTo( via->GetStart().x ), MapYTo( via->GetStart().y ),
via->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 )
{
std::set<wxString> emitted;
2011-12-02 15:09:57 +00:00
fputs( "$DEVICES\n", aFile );
2007-08-23 04:28:46 +00:00
for( const auto& componentShape : componentShapes )
{
const wxString& shapeName = shapeNames[componentShape.second];
bool newDevice;
std::tie( std::ignore, newDevice ) = emitted.insert( shapeName );
if( !newDevice ) // do not repeat device definitions
continue;
const MODULE* module = componentShape.first;
fprintf( aFile, "\nDEVICE \"DEV_%s\"\n", TO_UTF8( escapeString( shapeName ) ) );
fprintf( aFile, "PART \"%s\"\n", TO_UTF8( escapeString( module->GetValue() ) ) );
fprintf( aFile, "PACKAGE \"%s\"\n", TO_UTF8( escapeString( module->GetFPID().Format() ) ) );
// 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";
2011-12-02 15:09:57 +00:00
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( auto drawing : aPcb->Drawings() )
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 = static_cast<DRAWSEGMENT*>( drawing );
if( drawseg->GetLayer() == Edge_Cuts )
{
// XXX GenCAD supports arc boundaries but I've seen nothing that reads them
fprintf( aFile, "LINE %g %g %g %g\n",
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;
for( track = aPcb->m_Track; track; 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
}
for( track = aPcb->m_Zone; track; 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
*/
static void FootprintWriteShape( FILE* aFile, MODULE* module, const wxString& aShapeName )
{
EDGE_MODULE* PtEdge;
EDA_ITEM* PtStruct;
2009-11-02 20:36:20 +00:00
/* creates header: */
fprintf( aFile, "\nSHAPE \"%s\"\n", TO_UTF8( escapeString( aShapeName ) ) );
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->GraphicalItemsList(); PtStruct; 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;
if( PtEdge->GetLayer() == F_SilkS
|| PtEdge->GetLayer() == B_SilkS )
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,
-PtEdge->m_Start0.y / SCALE_FACTOR,
PtEdge->m_End0.x / SCALE_FACTOR,
-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,
-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;
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
PtEdge->m_End0.x / SCALE_FACTOR,
-PtEdge->GetEnd0().y / SCALE_FACTOR,
arcendx / SCALE_FACTOR,
-arcendy / SCALE_FACTOR,
PtEdge->GetStart0().x / SCALE_FACTOR,
-PtEdge->GetStart0().y / SCALE_FACTOR );
break;
}
2007-08-23 04:28:46 +00:00
case S_POLYGON:
// Not exported (TODO)
break;
default:
DisplayError( NULL, wxString::Format( "Type Edge Module %d invalid.", PtStruct->Type() ) );
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
}
}