2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-05-10 06:56:03 +00:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2021-11-11 22:31:52 +00:00
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
|
2022-01-13 13:45:48 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-11-10 15:55:05 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file export_gencad.cpp
|
|
|
|
* @brief Export GenCAD 1.4 format.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <build_version.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-07-09 16:22:44 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_shape.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <confirm.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <dialogs/dialog_gencad_export_options.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2017-10-09 09:50:06 +00:00
|
|
|
#include <hash_eda.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <pcbnew_settings.h>
|
|
|
|
#include <pgm_base.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <project/project_file.h> // LAST_PATH_TYPE
|
2010-01-05 08:48:49 +00:00
|
|
|
|
2021-01-25 15:18:28 +00:00
|
|
|
#include <wx/app.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
2021-01-25 15:18:28 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
static bool CreateHeaderInfoData( FILE* aFile, PCB_EDIT_FRAME* frame );
|
2011-12-05 07:03:57 +00:00
|
|
|
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 );
|
2020-11-13 15:15:52 +00:00
|
|
|
static void FootprintWriteShape( FILE* File, FOOTPRINT* aFootprint, const wxString& aShapeName );
|
2009-11-02 20:36:20 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2021-11-24 17:52:17 +00:00
|
|
|
// layer names for Gencad export
|
2017-03-13 03:19:33 +00:00
|
|
|
static std::string GenCADLayerName( int aCuCount, PCB_LAYER_ID aId )
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
|
|
|
if( IsCopperLayer( aId ) )
|
|
|
|
{
|
|
|
|
if( aId == F_Cu )
|
|
|
|
return "TOP";
|
|
|
|
else if( aId == B_Cu )
|
2014-06-30 15:03:20 +00:00
|
|
|
return "BOTTOM";
|
2014-06-24 16:17:18 +00:00
|
|
|
else if( aId <= 14 )
|
2020-08-31 16:29:13 +00:00
|
|
|
return StrPrintf( "INNER%d", aCuCount - aId - 1 );
|
2014-06-24 16:17:18 +00:00
|
|
|
else
|
2014-06-30 15:03:20 +00:00
|
|
|
return StrPrintf( "LAYER%d", aId );
|
2014-06-24 16:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
|
2017-03-13 03:19:33 +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,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
// flipped layer name for Gencad export (to make CAM350 imports correct)
|
2017-03-13 03:19:33 +00:00
|
|
|
static std::string GenCADLayerNameFlipped( int aCuCount, PCB_LAYER_ID aId )
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
2014-06-30 15:03:20 +00:00
|
|
|
if( 1<= aId && aId <= 14 )
|
|
|
|
return StrPrintf( "INNER%d", 14 - aId );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-06-30 15:03:20 +00:00
|
|
|
return GenCADLayerName( aCuCount, aId );
|
2017-11-02 20:41:29 +00:00
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
|
2017-10-19 10:52:40 +00:00
|
|
|
static wxString escapeString( const wxString& aString )
|
|
|
|
{
|
|
|
|
wxString copy( aString );
|
2022-02-05 02:06:25 +00:00
|
|
|
copy.Replace( wxT( "\"" ), wxT( "\\\"" ) );
|
2017-10-19 10:52:40 +00:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-06-30 15:03:20 +00:00
|
|
|
static std::string fmt_mask( LSET aSet )
|
|
|
|
{
|
|
|
|
return StrPrintf( "%08x", (unsigned) ( aSet & LSET::AllCuMask() ).to_ulong() );
|
|
|
|
}
|
|
|
|
|
2021-11-24 17:52:17 +00:00
|
|
|
|
2017-10-19 09:41:40 +00:00
|
|
|
// Export options
|
|
|
|
static bool flipBottomPads;
|
|
|
|
static bool uniquePins;
|
|
|
|
static bool individualShapes;
|
2017-11-08 09:21:45 +00:00
|
|
|
static bool storeOriginCoords;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
// These are the export origin (the auxiliary axis)
|
|
|
|
static int GencadOffsetX, GencadOffsetY;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-10-19 09:42:17 +00:00
|
|
|
// Association between shape names (using shapeName index) and components
|
2020-11-13 15:15:52 +00:00
|
|
|
static std::map<FOOTPRINT*, int> componentShapes;
|
2017-10-19 09:42:17 +00:00
|
|
|
static std::map<int, wxString> shapeNames;
|
|
|
|
|
2021-11-24 17:52:17 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
static const wxString getShapeName( FOOTPRINT* aFootprint )
|
2017-10-19 09:42:17 +00:00
|
|
|
{
|
|
|
|
static const wxString invalid( "invalid" );
|
|
|
|
|
|
|
|
if( individualShapes )
|
2020-11-13 01:33:30 +00:00
|
|
|
return aFootprint->GetReference();
|
2017-10-19 09:42:17 +00:00
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
auto itShape = componentShapes.find( aFootprint );
|
2017-10-19 09:42:17 +00:00
|
|
|
wxCHECK( itShape != componentShapes.end(), invalid );
|
|
|
|
|
|
|
|
auto itName = shapeNames.find( itShape->second );
|
|
|
|
wxCHECK( itName != shapeNames.end(), invalid );
|
|
|
|
|
|
|
|
return itName->second;
|
|
|
|
}
|
2017-10-09 09:50:06 +00:00
|
|
|
|
2021-11-24 17:52:17 +00:00
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
// GerbTool chokes on units different than INCH so this is the conversion factor
|
|
|
|
const static double SCALE_FACTOR = 1000.0 * IU_PER_MILS;
|
2011-11-10 15:55:05 +00:00
|
|
|
|
2021-11-24 17:52:17 +00:00
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
/* Two helper functions to calculate coordinates of footprints in gencad values
|
2011-12-02 15:09:57 +00:00
|
|
|
* (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 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-02 15:09:57 +00:00
|
|
|
return (aX - GencadOffsetX) / SCALE_FACTOR;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
static double MapYTo( int aY )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-02 15:09:57 +00:00
|
|
|
return (GencadOffsetY - aY) / SCALE_FACTOR;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
/* Driver function: processing starts here */
|
|
|
|
void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-08-03 03:03:03 +00:00
|
|
|
// Build default output file name
|
|
|
|
wxString path = GetLastPath( LAST_PATH_GENCAD );
|
|
|
|
|
|
|
|
if( path.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName brdFile = GetBoard()->GetFileName();
|
2022-02-05 02:06:25 +00:00
|
|
|
brdFile.SetExt( wxT( "cad" ) );
|
2019-08-03 03:03:03 +00:00
|
|
|
path = brdFile.GetFullPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
DIALOG_GENCAD_EXPORT_OPTIONS optionsDialog( this, path );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-10-04 09:57:59 +00:00
|
|
|
if( optionsDialog.ShowModal() == wxID_CANCEL )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
|
2019-08-03 03:03:03 +00:00
|
|
|
path = optionsDialog.GetFileName();
|
|
|
|
SetLastPath( LAST_PATH_GENCAD, path );
|
2022-02-05 02:06:25 +00:00
|
|
|
FILE* file = wxFopen( path, wxT( "wt" ) );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-10-04 09:57:59 +00:00
|
|
|
if( !file )
|
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
DisplayError( this, wxString::Format( _( "Failed to create file '%s'." ),
|
2019-08-03 03:03:03 +00:00
|
|
|
optionsDialog.GetFileName() ) );
|
2017-10-04 09:57:59 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 09:57:59 +00:00
|
|
|
// Get options
|
2017-10-04 15:25:59 +00:00
|
|
|
flipBottomPads = optionsDialog.GetOption( FLIP_BOTTOM_PADS );
|
2017-10-04 11:57:40 +00:00
|
|
|
uniquePins = optionsDialog.GetOption( UNIQUE_PIN_NAMES );
|
2017-10-09 09:50:06 +00:00
|
|
|
individualShapes = optionsDialog.GetOption( INDIVIDUAL_SHAPES );
|
2017-11-08 09:21:45 +00:00
|
|
|
storeOriginCoords = optionsDialog.GetOption( STORE_ORIGIN_COORDS );
|
2017-10-04 09:57:59 +00:00
|
|
|
|
2016-05-10 06:56:03 +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
|
2011-02-25 16:23:24 +00:00
|
|
|
GetBoard()->ComputeBoundingBox();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Save the auxiliary origin for the rest of the footprint
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I auxOrigin = m_pcb->GetDesignSettings().GetAuxOrigin();
|
2020-07-01 12:28:10 +00:00
|
|
|
GencadOffsetX = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? auxOrigin.x : 0;
|
|
|
|
GencadOffsetY = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? auxOrigin.y : 0;
|
2011-12-02 15:09:57 +00:00
|
|
|
|
|
|
|
// No idea on *why* this should be needed... maybe to fix net names?
|
2019-05-30 15:11:17 +00:00
|
|
|
Compile_Ratsnest( true );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +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
|
|
|
|
*/
|
2011-12-05 07:03:57 +00:00
|
|
|
BOARD* pcb = GetBoard();
|
2017-10-04 15:18:33 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : pcb->Footprints() )
|
2017-10-04 15:18:33 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
footprint->SetFlag( 0 );
|
2017-10-04 15:18:33 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( footprint->GetLayer() == B_Cu )
|
2017-10-04 15:18:33 +00:00
|
|
|
{
|
2021-07-09 16:42:56 +00:00
|
|
|
footprint->Flip( footprint->GetPosition(), false );
|
2020-11-12 23:50:33 +00:00
|
|
|
footprint->SetFlag( 1 );
|
2017-10-04 15:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
2011-12-05 07:03:57 +00:00
|
|
|
* need the padstack section (which is optional) anyway. Also the
|
|
|
|
* order of the section *is* important */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
CreateHeaderInfoData( file, this ); // Gencad header
|
|
|
|
CreateBoardSection( file, pcb ); // Board perimeter
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-05 07:03:57 +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.
|
2011-12-05 07:03:57 +00:00
|
|
|
* 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 );
|
2009-11-12 10:18:02 +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
|
|
|
// 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 );
|
2017-10-04 15:18:33 +00:00
|
|
|
|
|
|
|
// Undo the footprints modifications (flipped footprints)
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : pcb->Footprints() )
|
2017-10-04 15:18:33 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
if( footprint->GetFlag() )
|
2017-10-04 15:18:33 +00:00
|
|
|
{
|
2021-07-09 16:42:56 +00:00
|
|
|
footprint->Flip( footprint->GetPosition(), false );
|
2020-11-12 23:50:33 +00:00
|
|
|
footprint->SetFlag( 0 );
|
2017-10-04 15:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-19 09:43:54 +00:00
|
|
|
|
|
|
|
componentShapes.clear();
|
|
|
|
shapeNames.clear();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
// Sort vias for uniqueness
|
2021-06-11 21:07:02 +00:00
|
|
|
static bool ViaSort( const PCB_VIA* aPadref, const PCB_VIA* aPadcmp )
|
2011-12-02 15:09:57 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
if( aPadref->GetWidth() != aPadcmp->GetWidth() )
|
|
|
|
return aPadref->GetWidth() < aPadcmp->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
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
if( aPadref->GetDrillValue() != aPadcmp->GetDrillValue() )
|
|
|
|
return aPadref->GetDrillValue() < aPadcmp->GetDrillValue();
|
2011-12-02 15:09:57 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
if( aPadref->GetLayerSet() != aPadcmp->GetLayerSet() )
|
|
|
|
return aPadref->GetLayerSet().FmtBin().compare( aPadcmp->GetLayerSet().FmtBin() ) < 0;
|
2011-12-02 15:09:57 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
return false;
|
2011-12-02 15:09:57 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2011-12-05 07:03: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
|
|
|
// 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 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
std::vector<PAD*> padstacks;
|
|
|
|
std::vector<PCB_VIA*> vias;
|
|
|
|
std::vector<PCB_VIA*> viastacks;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
padstacks.resize( 1 ); // We count pads from 1
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
// The master layermask (i.e. the enabled layers) for padstack generation
|
2014-06-24 16:17:18 +00:00
|
|
|
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
|
2019-06-07 11:09:06 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
std::vector<PAD*> pads = aPcb->GetPads();
|
|
|
|
std::sort( pads.begin(), pads.end(), []( const PAD* a, const PAD* b )
|
2020-08-31 16:29:13 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
return PAD::Compare( a, b ) < 0;
|
2020-08-31 16:29:13 +00:00
|
|
|
} );
|
2019-05-31 02:30:28 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
// The same for vias
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : aPcb->Tracks() )
|
++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
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
if( PCB_VIA* via = dyn_cast<PCB_VIA*>( track ) )
|
2019-05-31 02:30:28 +00:00
|
|
|
vias.push_back( via );
|
2011-12-02 15:09:57 +00:00
|
|
|
}
|
2011-12-05 07:03:57 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
std::sort( vias.begin(), vias.end(), ViaSort );
|
2021-06-11 21:07:02 +00:00
|
|
|
vias.erase( std::unique( vias.begin(), vias.end(), []( const PCB_VIA* a, const PCB_VIA* b )
|
2020-08-31 16:29:13 +00:00
|
|
|
{
|
|
|
|
return ViaSort( a, b ) == false;
|
|
|
|
} ),
|
2019-05-31 02:30:28 +00:00
|
|
|
vias.end() );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
// Emit vias pads
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_VIA* via : vias )
|
2011-12-02 15:09:57 +00:00
|
|
|
{
|
2011-12-05 07:03:57 +00:00
|
|
|
viastacks.push_back( via );
|
2014-06-24 16:17:18 +00:00
|
|
|
fprintf( aFile, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n",
|
2020-08-31 16:29:13 +00:00
|
|
|
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
|
2021-04-22 21:20:34 +00:00
|
|
|
PAD* old_pad = nullptr;
|
2020-11-12 22:30:02 +00:00
|
|
|
int pad_name_number = 0;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
for( unsigned i = 0; i<pads.size(); ++i )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = pads[i];
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& off = pad->GetOffset();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
pad->SetSubRatsnest( pad_name_number );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2021-11-24 17:52:17 +00:00
|
|
|
// @warning: This code is not 100% correct. The #PAD::Compare function does not test
|
|
|
|
// custom pad primitives so there may be duplicate custom pads in the export.
|
2020-11-12 22:30:02 +00:00
|
|
|
if( old_pad && 0 == PAD::Compare( old_pad, pad ) )
|
2021-11-24 17:52:17 +00:00
|
|
|
continue;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
old_pad = pad;
|
|
|
|
|
|
|
|
pad_name_number++;
|
2008-11-18 18:13:55 +00:00
|
|
|
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
|
|
|
|
2011-12-05 07:03:57 +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:
|
2021-07-17 19:56:18 +00:00
|
|
|
UNIMPLEMENTED_FOR( pad->ShowPadShape() );
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2017-10-03 14:35:36 +00:00
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
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 );
|
2021-11-24 17:52:17 +00:00
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
/* Circle is center, radius */
|
2011-12-02 15:09:57 +00:00
|
|
|
fprintf( aFile, "CIRCLE %g %g %g\n",
|
2020-08-31 16:29:13 +00:00
|
|
|
off.x / SCALE_FACTOR,
|
|
|
|
-off.y / SCALE_FACTOR,
|
|
|
|
pad->GetSize().x / (SCALE_FACTOR * 2) );
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
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 );
|
2011-12-05 07:03:57 +00:00
|
|
|
|
|
|
|
// Rectangle is begin, size *not* begin, end!
|
2011-12-02 15:09:57 +00:00
|
|
|
fprintf( aFile, "RECTANGLE %g %g %g %g\n",
|
2020-08-31 16:29:13 +00:00
|
|
|
(-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;
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::ROUNDRECT:
|
|
|
|
case PAD_SHAPE::OVAL:
|
2021-11-11 22:31:52 +00:00
|
|
|
{
|
2022-01-05 01:42:27 +00:00
|
|
|
const VECTOR2I& size = pad->GetSize();
|
2021-11-11 22:31:52 +00:00
|
|
|
int radius = std::min( size.x, size.y ) / 2;
|
|
|
|
|
|
|
|
if( pad->GetShape() == PAD_SHAPE::ROUNDRECT )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2021-11-11 22:31:52 +00:00
|
|
|
radius = pad->GetRoundRectCornerRadius();
|
|
|
|
}
|
2017-10-03 14:35:36 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
int lineX = size.x / 2 - radius;
|
|
|
|
int lineY = size.y / 2 - radius;
|
2017-10-03 14:35:36 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
|
2017-10-03 14:35:36 +00:00
|
|
|
|
2021-11-11 22:31:52 +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 );
|
2014-06-30 15:03:20 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
// bottom line
|
|
|
|
if( lineX > 0 )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
2017-10-03 14:35:36 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
// 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
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
// right line
|
|
|
|
if( lineY > 0 )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
2017-10-03 14:35:36 +00:00
|
|
|
|
2021-11-11 22:31:52 +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 );
|
2017-10-03 14:35:36 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
// top line
|
|
|
|
if( lineX > 0 )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
2017-10-03 14:35:36 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
// 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
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
// left line
|
|
|
|
if( lineY > 0 )
|
|
|
|
{
|
|
|
|
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 );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2021-11-11 22:31:52 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
2021-11-11 22:31:52 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::TRAPEZOID:
|
2021-11-11 22:31:52 +00:00
|
|
|
{
|
|
|
|
fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
|
2017-10-04 12:19:47 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
int ddx = pad->GetDelta().x / 2;
|
|
|
|
int ddy = pad->GetDelta().y / 2;
|
2020-06-22 19:35:09 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I poly[4];
|
|
|
|
poly[0] = VECTOR2I( -dx + ddy, dy + ddx );
|
|
|
|
poly[1] = VECTOR2I( dx - ddy, dy - ddx );
|
|
|
|
poly[2] = VECTOR2I( dx + ddy, -dy + ddx );
|
|
|
|
poly[3] = VECTOR2I( -dx - ddy, -dy - ddx );
|
2011-12-05 07:03:57 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
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 );
|
2017-10-04 12:19:47 +00:00
|
|
|
}
|
2021-11-11 22:31:52 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
2021-11-11 22:31:52 +00:00
|
|
|
}
|
2017-10-04 14:34:57 +00:00
|
|
|
|
2021-07-09 16:22:44 +00:00
|
|
|
case PAD_SHAPE::CHAMFERED_RECT:
|
|
|
|
{
|
|
|
|
fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
int maxError = aPcb->GetDesignSettings().m_MaxError;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I padOffset( 0, 0 );
|
2021-07-09 16:22:44 +00:00
|
|
|
|
2021-11-24 17:52:17 +00:00
|
|
|
TransformRoundChamferedRectToPolygon( outline, padOffset, pad->GetSize(),
|
2022-01-16 01:06:25 +00:00
|
|
|
pad->GetOrientation(),
|
2021-11-24 17:52:17 +00:00
|
|
|
pad->GetRoundRectCornerRadius(),
|
|
|
|
pad->GetChamferRectRatio(),
|
|
|
|
pad->GetChamferPositions(), 0, maxError,
|
|
|
|
ERROR_INSIDE );
|
2021-11-11 22:31:52 +00:00
|
|
|
|
2021-07-09 16:22:44 +00:00
|
|
|
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",
|
2021-11-24 17:52:17 +00:00
|
|
|
poly.CPoint( ii ).x / SCALE_FACTOR,
|
|
|
|
-poly.CPoint( ii ).y / SCALE_FACTOR,
|
|
|
|
poly.CPoint( next ).x / SCALE_FACTOR,
|
|
|
|
-poly.CPoint( next ).y / SCALE_FACTOR );
|
2021-07-09 16:22:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::CUSTOM:
|
2021-11-11 22:31:52 +00:00
|
|
|
{
|
|
|
|
fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
|
2017-10-04 14:34:57 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
pad->MergePrimitivesAsPolygon( &outline );
|
2017-10-04 14:34:57 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
for( int jj = 0; jj < outline.OutlineCount(); ++jj )
|
|
|
|
{
|
|
|
|
const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
|
|
|
|
int pointCount = poly.PointCount();
|
2017-10-04 14:34:57 +00:00
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
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 );
|
2017-10-04 14:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-11 22:31:52 +00:00
|
|
|
|
2017-10-04 14:34:57 +00:00
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2021-11-11 22:31:52 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2011-12-05 07:03:57 +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 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
// Via padstacks
|
|
|
|
for( unsigned i = 0; i < viastacks.size(); i++ )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_VIA* via = viastacks[i];
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
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(),
|
2011-12-05 07:03:57 +00:00
|
|
|
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
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
for( LSEQ seq = mask.Seq( gc_seq, arrayDim( 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
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer = *seq;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
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(),
|
2021-11-11 22:31:52 +00:00
|
|
|
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
|
|
|
}
|
2011-12-05 07:03: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
|
2017-10-04 15:25:59 +00:00
|
|
|
* 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...
|
2021-11-11 22:31:52 +00:00
|
|
|
* until it appears yet another non-compliant importer */
|
2011-12-02 15:09:57 +00:00
|
|
|
for( unsigned i = 1; i < padstacks.size(); i++ )
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = padstacks[i];
|
2011-12-02 15:09:57 +00:00
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
// Straight padstack
|
2015-02-22 14:43:44 +00:00
|
|
|
fprintf( aFile, "PADSTACK PAD%u %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
LSET pad_set = pad->GetLayerSet() & master_layermask;
|
|
|
|
|
2014-06-30 15:03:20 +00:00
|
|
|
// the special gc_seq
|
2019-01-06 16:43:12 +00:00
|
|
|
for( LSEQ seq = pad_set.Seq( gc_seq, arrayDim( 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
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer = *seq;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2015-02-22 14:43:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
// Flipped padstack
|
2017-10-04 15:25:59 +00:00
|
|
|
if( flipBottomPads )
|
2011-12-05 07:03:57 +00:00
|
|
|
{
|
2017-10-04 09:57:59 +00:00
|
|
|
fprintf( aFile, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
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;
|
|
|
|
|
2021-11-11 22:31:52 +00:00
|
|
|
fprintf( aFile, "PAD P%u %s 0 0\n", i,
|
|
|
|
GenCADLayerNameFlipped( cu_count, layer ).c_str() );
|
2017-10-04 09:57:59 +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
|
|
|
}
|
|
|
|
}
|
2011-12-05 07:03:57 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$ENDPADSTACKS\n\n", aFile );
|
2009-11-12 10:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
/// Compute hashes for footprints without taking into account their position, rotation or layer
|
2020-11-13 15:15:52 +00:00
|
|
|
static size_t hashFootprint( const FOOTPRINT* aFootprint )
|
2017-10-09 09:50:06 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
size_t ret = 0x11223344;
|
2020-07-10 00:39:00 +00:00
|
|
|
constexpr int flags = HASH_FLAGS::HASH_POS | HASH_FLAGS::REL_COORD
|
2020-11-13 15:15:52 +00:00
|
|
|
| HASH_FLAGS::HASH_ROT | HASH_FLAGS::HASH_LAYER;
|
2017-10-09 09:50:06 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( BOARD_ITEM* i : aFootprint->GraphicalItems() )
|
2020-11-14 01:16:02 +00:00
|
|
|
ret += hash_fp_item( i, flags );
|
2017-10-09 09:50:06 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( PAD* i : aFootprint->Pads() )
|
2020-11-14 01:16:02 +00:00
|
|
|
ret += hash_fp_item( i, flags );
|
2017-10-09 09:50:06 +00:00
|
|
|
|
|
|
|
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 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-02 20:36:20 +00:00
|
|
|
const char* layer;
|
|
|
|
wxString pinname;
|
|
|
|
const char* mirror = "0";
|
2017-10-09 09:50:06 +00:00
|
|
|
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
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : aPcb->Footprints() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2017-10-09 09:50:06 +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.
|
2020-11-12 23:50:33 +00:00
|
|
|
wxString shapeName = footprint->GetFPID().Format();
|
2017-10-09 09:50:06 +00:00
|
|
|
|
|
|
|
auto shapeIt = shapes.find( shapeName );
|
2020-11-13 15:15:52 +00:00
|
|
|
size_t modHash = hashFootprint( footprint );
|
2017-10-09 09:50:06 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
newShapeName = wxString::Format( wxT( "%s_%d" ), shapeName, suffix );
|
2017-10-09 09:50:06 +00:00
|
|
|
shapeIt = shapes.find( newShapeName );
|
|
|
|
++suffix;
|
|
|
|
}
|
|
|
|
while( shapeIt != shapes.end() && shapeIt->second != modHash );
|
|
|
|
|
|
|
|
shapeName = newShapeName;
|
|
|
|
}
|
2017-10-04 11:57:40 +00:00
|
|
|
|
2017-10-09 09:50:06 +00:00
|
|
|
if( shapeIt != shapes.end() && modHash == shapeIt->second )
|
|
|
|
{
|
|
|
|
// shape found, so reuse it
|
2020-11-12 23:50:33 +00:00
|
|
|
componentShapes[footprint] = modHash;
|
2017-10-09 09:50:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 09:42:17 +00:00
|
|
|
// new shape
|
2020-11-12 23:50:33 +00:00
|
|
|
componentShapes[footprint] = modHash;
|
2017-10-19 09:42:17 +00:00
|
|
|
shapeNames[modHash] = shapeName;
|
2017-10-09 09:50:06 +00:00
|
|
|
shapes[shapeName] = modHash;
|
2020-11-12 23:50:33 +00:00
|
|
|
FootprintWriteShape( aFile, footprint, shapeName );
|
2017-10-09 09:50:06 +00:00
|
|
|
}
|
|
|
|
else // individual shape for each component
|
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
FootprintWriteShape( aFile, footprint, footprint->GetReference() );
|
2017-10-09 09:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set of already emitted pins to check for duplicates
|
|
|
|
std::set<wxString> pins;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2017-10-04 15:25:59 +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";
|
2021-08-23 23:10:21 +00:00
|
|
|
pinname = pad->GetNumber();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
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
|
|
|
|
2017-10-04 11:57:40 +00:00
|
|
|
if( uniquePins )
|
|
|
|
{
|
|
|
|
int suffix = 0;
|
|
|
|
wxString origPinname( pinname );
|
|
|
|
|
|
|
|
auto it = pins.find( pinname );
|
|
|
|
|
|
|
|
while( it != pins.end() )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
pinname = wxString::Format( wxT( "%s_%d" ), origPinname, suffix );
|
2017-10-04 11:57:40 +00:00
|
|
|
++suffix;
|
|
|
|
it = pins.find( pinname );
|
|
|
|
}
|
|
|
|
|
|
|
|
pins.insert( pinname );
|
|
|
|
}
|
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
EDA_ANGLE orient = pad->GetOrientation() - footprint->GetOrientation();
|
|
|
|
orient.Normalize();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Bottom side footprints use the flipped padstack
|
2020-11-12 23:50:33 +00:00
|
|
|
fprintf( aFile, ( flipBottomPads && footprint->GetFlag() ) ?
|
2017-10-19 10:52:40 +00:00
|
|
|
"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,
|
2022-01-13 17:27:36 +00:00
|
|
|
layer, orient.AsDegrees(), mirror );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$ENDSHAPES\n\n", aFile );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
|
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
|
2021-06-09 19:32:58 +00:00
|
|
|
* that *no one* 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 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$COMPONENTS\n", aFile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
int cu_count = aPcb->GetCopperLayerCount();
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : aPcb->Footprints() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-12-05 07:03:57 +00:00
|
|
|
const char* mirror;
|
|
|
|
const char* flip;
|
2022-01-15 00:20:02 +00:00
|
|
|
EDA_ANGLE fp_orient = footprint->GetOrientation();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( footprint->GetFlag() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2017-10-04 15:25:59 +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";
|
2022-01-15 00:20:02 +00:00
|
|
|
fp_orient = fp_orient.Invert().Normalize();
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mirror = "0";
|
|
|
|
flip = "0";
|
|
|
|
}
|
|
|
|
|
2017-10-19 10:52:40 +00:00
|
|
|
fprintf( aFile, "\nCOMPONENT \"%s\"\n",
|
2020-11-12 23:50:33 +00:00
|
|
|
TO_UTF8( escapeString( footprint->GetReference() ) ) );
|
2017-10-19 10:52:40 +00:00
|
|
|
fprintf( aFile, "DEVICE \"DEV_%s\"\n",
|
2020-11-12 23:50:33 +00:00
|
|
|
TO_UTF8( escapeString( getShapeName( footprint ) ) ) );
|
++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",
|
2020-11-12 23:50:33 +00:00
|
|
|
MapXTo( footprint->GetPosition().x ),
|
|
|
|
MapYTo( footprint->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",
|
2020-11-12 23:50:33 +00:00
|
|
|
footprint->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",
|
2022-01-15 00:20:02 +00:00
|
|
|
fp_orient.AsDegrees() );
|
2017-10-19 10:52:40 +00:00
|
|
|
fprintf( aFile, "SHAPE \"%s\" %s %s\n",
|
2020-11-12 23:50:33 +00:00
|
|
|
TO_UTF8( escapeString( getShapeName( footprint ) ) ),
|
2011-12-05 07:03:57 +00:00
|
|
|
mirror, flip );
|
2011-12-02 15:09:57 +00:00
|
|
|
|
|
|
|
// Text on silk layer: RefDes and value (are they actually useful?)
|
2020-11-12 23:50:33 +00:00
|
|
|
for( FP_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2021-11-11 22:31:52 +00:00
|
|
|
std::string layer = GenCADLayerName( cu_count,
|
|
|
|
footprint->GetFlag() ? B_SilkS : F_SilkS );
|
2011-12-02 15:09:57 +00:00
|
|
|
|
|
|
|
fprintf( aFile, "TEXT %g %g %g %g %s %s \"%s\"",
|
2020-10-04 23:34:59 +00:00
|
|
|
textItem->GetPos0().x / SCALE_FACTOR,
|
|
|
|
-textItem->GetPos0().y / SCALE_FACTOR,
|
|
|
|
textItem->GetTextWidth() / SCALE_FACTOR,
|
2021-12-28 22:13:54 +00:00
|
|
|
textItem->GetTextAngle().AsDegrees(),
|
2013-03-13 18:53:58 +00:00
|
|
|
mirror,
|
2014-06-24 16:17:18 +00:00
|
|
|
layer.c_str(),
|
2020-10-04 23:34:59 +00:00
|
|
|
TO_UTF8( escapeString( textItem->GetText() ) ) );
|
2011-12-05 07:03:57 +00:00
|
|
|
|
|
|
|
// Please note, the width is approx
|
2011-12-02 15:09:57 +00:00
|
|
|
fprintf( aFile, " 0 0 %g %g\n",
|
2020-10-04 23:34:59 +00:00
|
|
|
( textItem->GetTextWidth() * textItem->GetLength() ) / SCALE_FACTOR,
|
|
|
|
textItem->GetTextHeight() / SCALE_FACTOR );
|
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",
|
2020-11-12 23:50:33 +00:00
|
|
|
TO_UTF8( footprint->GetReference() ),
|
|
|
|
TO_UTF8( footprint->GetValue() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$ENDCOMPONENTS\n\n", aFile );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
|
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 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-02 20:36:20 +00:00
|
|
|
wxString msg;
|
2009-05-24 18:28:36 +00:00
|
|
|
NETINFO_ITEM* net;
|
2009-11-02 20:36:20 +00:00
|
|
|
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
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
for( unsigned ii = 0; ii < aPcb->GetNetCount(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-12-10 05:33:24 +00:00
|
|
|
net = aPcb->FindNet( ii );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
|
|
|
if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
msg.Printf( wxT( "NoConnection%d" ), NbNoConn++ );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 13:02:08 +00:00
|
|
|
if( net->GetNetCode() <= 0 ) // dummy netlist (no connection)
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + wxT( "\"" );
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( TO_UTF8( msg ), aFile );
|
|
|
|
fputs( "\n", aFile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : aPcb->Footprints() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2020-12-08 13:02:08 +00:00
|
|
|
if( pad->GetNetCode() != net->GetNetCode() )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2017-10-19 10:52:40 +00:00
|
|
|
msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
|
2020-11-12 23:50:33 +00:00
|
|
|
escapeString( footprint->GetReference() ),
|
2021-08-23 23:10:21 +00:00
|
|
|
escapeString( pad->GetNumber() ) );
|
2008-11-18 18:13:55 +00:00
|
|
|
|
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-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2012-01-09 08:35:06 +00:00
|
|
|
// Creates the header section
|
2011-12-02 15:09:57 +00:00
|
|
|
static bool CreateHeaderInfoData( FILE* aFile, PCB_EDIT_FRAME* aFrame )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
wxString msg;
|
|
|
|
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" ),
|
2020-08-31 16:29:13 +00:00
|
|
|
Pgm().App().GetAppName(),
|
|
|
|
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-01-09 08:35:06 +00:00
|
|
|
|
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 );
|
2012-01-09 08:35:06 +00:00
|
|
|
|
2022-01-22 15:54:10 +00:00
|
|
|
wxString rev = ExpandTextVars( board->GetTitleBlock().GetRevision(), board->GetProject() );
|
|
|
|
wxString date = ExpandTextVars( board->GetTitleBlock().GetDate(), board->GetProject() );
|
|
|
|
msg = wxT( "REVISION \"" ) + rev + wxT( " " ) + date + wxT( "\"\n" );
|
2012-01-09 08:35:06 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( TO_UTF8( msg ), aFile );
|
2011-12-05 07:03:57 +00:00
|
|
|
fputs( "UNITS INCH\n", aFile );
|
2012-01-09 08:35:06 +00:00
|
|
|
|
2017-11-08 09:21:45 +00:00
|
|
|
// 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" ),
|
2020-08-31 16:29:13 +00:00
|
|
|
storeOriginCoords ? MapXTo( 0 ) : 0,
|
|
|
|
storeOriginCoords ? MapYTo( 0 ) : 0 );
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( TO_UTF8( msg ), aFile );
|
2012-01-09 08:35:06 +00:00
|
|
|
|
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
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
|
2009-11-12 10:18:02 +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 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
int vianum = 1;
|
|
|
|
int old_netcode, old_width, old_layer;
|
|
|
|
LSET master_layermask = aPcb->GetDesignSettings().GetEnabledLayers();
|
|
|
|
|
|
|
|
int cu_count = aPcb->GetCopperLayerCount();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2019-06-07 11:09:06 +00:00
|
|
|
TRACKS tracks( aPcb->Tracks() );
|
2020-08-31 16:29:13 +00:00
|
|
|
std::sort( tracks.begin(), tracks.end(),
|
2021-06-11 21:07:02 +00:00
|
|
|
[]( const PCB_TRACK* a, const PCB_TRACK* b )
|
2020-08-31 16:29:13 +00:00
|
|
|
{
|
|
|
|
if( a->GetNetCode() == b->GetNetCode() )
|
|
|
|
{
|
|
|
|
if( a->GetWidth() == b->GetWidth() )
|
|
|
|
return ( a->GetLayer() < b->GetLayer() );
|
2019-06-07 11:09:06 +00:00
|
|
|
|
2020-08-31 16:29:13 +00:00
|
|
|
return ( a->GetWidth() < b->GetWidth() );
|
|
|
|
}
|
2019-06-07 11:09:06 +00:00
|
|
|
|
2020-08-31 16:29:13 +00:00
|
|
|
return ( a->GetNetCode() < b->GetNetCode() );
|
|
|
|
} );
|
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;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : tracks )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2014-02-25 10:40:34 +00:00
|
|
|
if( old_netcode != track->GetNetCode() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2014-02-25 10:40:34 +00:00
|
|
|
old_netcode = track->GetNetCode();
|
|
|
|
NETINFO_ITEM* net = track->GetNet();
|
2009-11-02 20:36:20 +00:00
|
|
|
wxString netname;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
if( net && (net->GetNetname() != wxEmptyString) )
|
|
|
|
netname = net->GetNetname();
|
2007-08-23 04:28:46 +00:00
|
|
|
else
|
|
|
|
netname = wxT( "_noname_" );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-10-19 10:52:40 +00:00
|
|
|
fprintf( aFile, "ROUTE \"%s\"\n", TO_UTF8( escapeString( netname ) ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
if( old_width != track->GetWidth() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
old_width = track->GetWidth();
|
|
|
|
fprintf( aFile, "TRACK TRACK%d\n", track->GetWidth() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 09:19:16 +00:00
|
|
|
if( track->Type() == PCB_TRACE_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",
|
2019-04-10 09:19:16 +00:00
|
|
|
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",
|
2013-01-13 00:04:00 +00:00
|
|
|
MapXTo( track->GetStart().x ), MapYTo( track->GetStart().y ),
|
|
|
|
MapXTo( track->GetEnd().x ), MapYTo( track->GetEnd().y ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( track->Type() == PCB_VIA_T )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_VIA* via = static_cast<const PCB_VIA*>(track);
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
LSET vset = via->GetLayerSet() & master_layermask;
|
|
|
|
|
|
|
|
fprintf( aFile, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
|
2014-04-25 06:00:04 +00:00
|
|
|
via->GetWidth(), via->GetDrillValue(),
|
2014-06-30 15:03:20 +00:00
|
|
|
fmt_mask( vset ).c_str(),
|
2014-04-25 06:00:04 +00:00
|
|
|
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-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 10:18:02 +00:00
|
|
|
/* Creates the section $DEVICES
|
2009-11-02 20:36:20 +00:00
|
|
|
* This is a list of footprints properties
|
|
|
|
* ( Shapes are in section $SHAPE )
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-12-02 15:09:57 +00:00
|
|
|
static void CreateDevicesSection( FILE* aFile, BOARD* aPcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-10-19 08:56:14 +00:00
|
|
|
std::set<wxString> emitted;
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$DEVICES\n", aFile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2017-10-19 09:42:17 +00:00
|
|
|
for( const auto& componentShape : componentShapes )
|
2011-12-05 07:03:57 +00:00
|
|
|
{
|
2017-10-19 09:42:17 +00:00
|
|
|
const wxString& shapeName = shapeNames[componentShape.second];
|
2017-10-19 08:56:14 +00:00
|
|
|
bool newDevice;
|
|
|
|
std::tie( std::ignore, newDevice ) = emitted.insert( shapeName );
|
|
|
|
|
|
|
|
if( !newDevice ) // do not repeat device definitions
|
|
|
|
continue;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT* footprint = componentShape.first;
|
2020-11-13 11:17:15 +00:00
|
|
|
|
2017-10-19 10:52:40 +00:00
|
|
|
fprintf( aFile, "\nDEVICE \"DEV_%s\"\n", TO_UTF8( escapeString( shapeName ) ) );
|
2020-11-13 11:17:15 +00:00
|
|
|
|
|
|
|
fprintf( aFile, "PART \"%s\"\n",
|
|
|
|
TO_UTF8( escapeString( footprint->GetValue() ) ) );
|
|
|
|
|
|
|
|
fprintf( aFile, "PACKAGE \"%s\"\n",
|
|
|
|
TO_UTF8( escapeString( footprint->GetFPID().Format() ) ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$ENDDEVICES\n\n", aFile );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 10:18:02 +00:00
|
|
|
/* 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 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$BOARD\n", aFile );
|
2011-12-05 07:03: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
|
|
|
// Extract the board edges
|
2020-08-31 16:29:13 +00:00
|
|
|
for( BOARD_ITEM* drawing : aPcb->Drawings() )
|
2011-12-02 15:09:57 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if( drawing->Type() == PCB_SHAPE_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
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* drawseg = static_cast<PCB_SHAPE*>( drawing );
|
2020-08-31 16:29:13 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( drawseg->GetLayer() == Edge_Cuts )
|
2011-12-05 07:03:57 +00:00
|
|
|
{
|
|
|
|
// XXX GenCAD supports arc boundaries but I've seen nothing that reads them
|
|
|
|
fprintf( aFile, "LINE %g %g %g %g\n",
|
2013-09-08 18:31:21 +00:00
|
|
|
MapXTo( drawseg->GetStart().x ), MapYTo( drawseg->GetStart().y ),
|
|
|
|
MapXTo( drawseg->GetEnd().x ), MapYTo( drawseg->GetEnd().y ) );
|
2011-12-05 07:03: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
|
|
|
}
|
|
|
|
}
|
2011-12-05 07:03:57 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$ENDBOARD\n\n", aFile );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2008-11-18 18:13:55 +00:00
|
|
|
*
|
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-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-02 15:09:57 +00:00
|
|
|
// Find thickness used for traces
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
std::set<int> trackinfo;
|
2009-05-23 15:53:47 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : aPcb->Tracks() )
|
2019-05-31 02:30:28 +00:00
|
|
|
trackinfo.insert( track->GetWidth() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
// Write data
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$TRACKS\n", aFile );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-08-31 16:29:13 +00:00
|
|
|
for( int size : trackinfo )
|
2019-05-31 02:30:28 +00:00
|
|
|
fprintf( aFile, "TRACK TRACK%d %g\n", size, size / SCALE_FACTOR );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-02 15:09:57 +00:00
|
|
|
fputs( "$ENDTRACKS\n\n", aFile );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
2020-11-13 15:15:52 +00:00
|
|
|
static void FootprintWriteShape( FILE* aFile, FOOTPRINT* aFootprint, const wxString& aShapeName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* shape;
|
2011-12-05 07:03:57 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* creates header: */
|
2017-10-19 10:52:40 +00:00
|
|
|
fprintf( aFile, "\nSHAPE \"%s\"\n", TO_UTF8( escapeString( aShapeName ) ) );
|
2011-12-02 15:09:57 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
if( aFootprint->GetAttributes() & FP_THROUGH_HOLE )
|
2020-08-26 21:43:38 +00:00
|
|
|
fprintf( aFile, "INSERT TH\n" );
|
2011-12-02 15:09:57 +00:00
|
|
|
else
|
2020-08-26 21:43:38 +00:00
|
|
|
fprintf( aFile, "INSERT SMD\n" );
|
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...
|
2020-11-13 11:17:15 +00:00
|
|
|
for( BOARD_ITEM* PtStruct : aFootprint->GraphicalItems() )
|
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
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2022-01-30 10:52:52 +00:00
|
|
|
case PCB_FP_TEXTBOX_T:
|
2011-12-05 07:03:57 +00:00
|
|
|
|
|
|
|
// If we wanted to export text, this is not the correct section
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2020-10-04 23:34:59 +00:00
|
|
|
shape = (FP_SHAPE*) PtStruct;
|
2021-11-11 22:31:52 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
if( shape->GetLayer() == F_SilkS || shape->GetLayer() == B_SilkS )
|
2011-12-02 15:09:57 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
switch( shape->GetShape() )
|
2011-12-05 07:03:57 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2011-12-02 15:09:57 +00:00
|
|
|
fprintf( aFile, "LINE %g %g %g %g\n",
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->GetStart0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetStart0().y / SCALE_FACTOR,
|
|
|
|
shape->GetEnd0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetEnd0().y / SCALE_FACTOR );
|
2011-12-05 07:03:57 +00:00
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::RECT:
|
2020-06-15 19:50:20 +00:00
|
|
|
{
|
|
|
|
fprintf( aFile, "LINE %g %g %g %g\n",
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->GetStart0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetStart0().y / SCALE_FACTOR,
|
|
|
|
shape->GetEnd0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetStart0().y / SCALE_FACTOR );
|
2020-06-15 19:50:20 +00:00
|
|
|
fprintf( aFile, "LINE %g %g %g %g\n",
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->GetEnd0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetStart0().y / SCALE_FACTOR,
|
|
|
|
shape->GetEnd0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetEnd0().y / SCALE_FACTOR );
|
2020-06-15 19:50:20 +00:00
|
|
|
fprintf( aFile, "LINE %g %g %g %g\n",
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->GetEnd0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetEnd0().y / SCALE_FACTOR,
|
|
|
|
shape->GetStart0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetEnd0().y / SCALE_FACTOR );
|
2020-06-15 19:50:20 +00:00
|
|
|
fprintf( aFile, "LINE %g %g %g %g\n",
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->GetStart0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetEnd0().y / SCALE_FACTOR,
|
|
|
|
shape->GetStart0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetStart0().y / SCALE_FACTOR );
|
2020-06-15 19:50:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2011-12-05 07:03:57 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
int radius = KiROUND( GetLineLength( shape->GetEnd0(), shape->GetStart0() ) );
|
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
fprintf( aFile, "CIRCLE %g %g %g\n",
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->GetStart0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetStart0().y / SCALE_FACTOR,
|
2011-12-05 07:03:57 +00:00
|
|
|
radius / SCALE_FACTOR );
|
|
|
|
break;
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2021-11-12 18:07:13 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start = shape->GetStart0();
|
|
|
|
VECTOR2I end = shape->GetEnd0();
|
2021-11-12 18:07:13 +00:00
|
|
|
|
2022-01-14 15:34:41 +00:00
|
|
|
if( shape->GetArcAngle() > ANGLE_0 )
|
2021-11-12 18:07:13 +00:00
|
|
|
std::swap( start, end );
|
|
|
|
|
2017-10-04 15:25:59 +00:00
|
|
|
fprintf( aFile, "ARC %g %g %g %g %g %g\n",
|
2021-11-12 18:07:13 +00:00
|
|
|
start.x / SCALE_FACTOR,
|
|
|
|
-start.y / SCALE_FACTOR,
|
|
|
|
end.x / SCALE_FACTOR,
|
|
|
|
-end.y / SCALE_FACTOR,
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->GetCenter0().x / SCALE_FACTOR,
|
|
|
|
-shape->GetCenter0().y / SCALE_FACTOR );
|
2021-11-12 18:07:13 +00:00
|
|
|
}
|
2011-12-05 07:03:57 +00:00
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2016-06-05 11:49:25 +00:00
|
|
|
// Not exported (TODO)
|
|
|
|
break;
|
|
|
|
|
2011-12-05 07:03:57 +00:00
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Type Edge Module %d invalid." ),
|
2020-08-31 13:19:57 +00:00
|
|
|
PtStruct->Type() ) );
|
2011-12-05 07:03:57 +00:00
|
|
|
break;
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
}
|
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
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|