2013-09-13 10:59:47 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011-2013 Lorenzo Marcantonio <l.marcantonio@logossrl.com>
|
2017-11-12 00:31:38 +00:00
|
|
|
* Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors.
|
2013-09-13 10:59:47 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file export_d356.cpp
|
|
|
|
* @brief Export IPC-D-356 test format
|
|
|
|
*/
|
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <kiface_i.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <trigo.h>
|
|
|
|
#include <build_version.h>
|
|
|
|
#include <macros.h>
|
2017-11-12 00:31:38 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
2013-09-13 10:59:47 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <cctype>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2020-02-04 10:30:21 +00:00
|
|
|
#include <export_d356.h>
|
|
|
|
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Compute the access code for a pad. Returns -1 if there is no copper
|
2014-06-24 16:17:18 +00:00
|
|
|
static int compute_pad_access_code( BOARD *aPcb, LSET aLayerMask )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
|
|
|
// Non-copper is not interesting here
|
2014-06-24 16:17:18 +00:00
|
|
|
aLayerMask &= LSET::AllCuMask();
|
|
|
|
if( !aLayerMask.any() )
|
2014-03-29 11:22:20 +00:00
|
|
|
return -1;
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// Traditional TH pad
|
2014-06-24 16:17:18 +00:00
|
|
|
if( aLayerMask[F_Cu] && aLayerMask[B_Cu] )
|
2014-03-29 11:22:20 +00:00
|
|
|
return 0;
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// Front SMD pad
|
2014-06-24 16:17:18 +00:00
|
|
|
if( aLayerMask[F_Cu] )
|
2014-03-29 11:22:20 +00:00
|
|
|
return 1;
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// Back SMD pad
|
2014-06-24 16:17:18 +00:00
|
|
|
if( aLayerMask[B_Cu] )
|
2014-03-29 11:22:20 +00:00
|
|
|
return aPcb->GetCopperLayerCount();
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// OK, we have an inner-layer only pad (and I have no idea about
|
|
|
|
// what could be used for); anyway, find the first copper layer
|
|
|
|
// it's on
|
2014-06-24 16:17:18 +00:00
|
|
|
for( LAYER_NUM layer = In1_Cu; layer < B_Cu; ++layer )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
if( aLayerMask[layer] )
|
|
|
|
return layer + 1;
|
2013-09-13 10:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This shouldn't happen
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert and clamp a size from IU to decimils */
|
|
|
|
static int iu_to_d356(int iu, int clamp)
|
|
|
|
{
|
2016-06-05 11:49:25 +00:00
|
|
|
int val = KiROUND( iu / ( IU_PER_MILS / 10 ) );
|
2013-09-13 10:59:47 +00:00
|
|
|
if( val > clamp ) return clamp;
|
|
|
|
if( val < -clamp ) return -clamp;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
/* Extract the D356 record from the footprints (pads) */
|
2020-07-01 12:28:10 +00:00
|
|
|
static void build_pad_testpoints( BOARD *aPcb, std::vector <D356_RECORD>& aRecords )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
2020-07-01 12:28:10 +00:00
|
|
|
wxPoint origin = aPcb->GetDesignSettings().m_AuxOrigin;
|
2013-09-13 10:59:47 +00:00
|
|
|
|
2019-05-31 00:15:57 +00:00
|
|
|
for( auto module : aPcb->Modules() )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : module->Pads() )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
|
|
|
D356_RECORD rk;
|
2014-06-24 16:17:18 +00:00
|
|
|
rk.access = compute_pad_access_code( aPcb, pad->GetLayerSet() );
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// It could be a mask only pad, we only handle pads with copper here
|
|
|
|
if( rk.access != -1 )
|
|
|
|
{
|
2014-03-29 11:22:20 +00:00
|
|
|
rk.netname = pad->GetNetname();
|
2017-08-11 09:22:13 +00:00
|
|
|
rk.pin = pad->GetName();
|
2014-03-29 11:22:20 +00:00
|
|
|
rk.refdes = module->GetReference();
|
|
|
|
rk.midpoint = false; // XXX MAYBE need to be computed (how?)
|
|
|
|
const wxSize& drill = pad->GetDrillSize();
|
|
|
|
rk.drill = std::min( drill.x, drill.y );
|
|
|
|
rk.hole = (rk.drill != 0);
|
2015-08-23 19:40:33 +00:00
|
|
|
rk.smd = pad->GetAttribute() == PAD_ATTRIB_SMD;
|
2020-09-30 15:38:35 +00:00
|
|
|
rk.mechanical = ( pad->GetAttribute() == PAD_ATTRIB_NPTH );
|
2014-03-29 11:22:20 +00:00
|
|
|
rk.x_location = pad->GetPosition().x - origin.x;
|
|
|
|
rk.y_location = origin.y - pad->GetPosition().y;
|
|
|
|
rk.x_size = pad->GetSize().x;
|
|
|
|
|
|
|
|
// Rule: round pads have y = 0
|
2015-08-23 19:40:33 +00:00
|
|
|
if( pad->GetShape() == PAD_SHAPE_CIRCLE )
|
2014-03-29 11:22:20 +00:00
|
|
|
rk.y_size = 0;
|
|
|
|
else
|
|
|
|
rk.y_size = pad->GetSize().y;
|
|
|
|
|
|
|
|
rk.rotation = -KiROUND( pad->GetOrientation() ) / 10;
|
|
|
|
if( rk.rotation < 0 ) rk.rotation += 360;
|
|
|
|
|
|
|
|
// the value indicates which sides are *not* accessible
|
|
|
|
rk.soldermask = 3;
|
2014-06-24 16:17:18 +00:00
|
|
|
if( pad->GetLayerSet()[F_Mask] )
|
2014-03-29 11:22:20 +00:00
|
|
|
rk.soldermask &= ~1;
|
2014-06-24 16:17:18 +00:00
|
|
|
if( pad->GetLayerSet()[B_Mask] )
|
2014-03-29 11:22:20 +00:00
|
|
|
rk.soldermask &= ~2;
|
|
|
|
|
|
|
|
aRecords.push_back( rk );
|
2013-09-13 10:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the access code for a via. In D-356 layers are numbered from 1 up,
|
|
|
|
where '1' is the 'primary side' (usually the component side);
|
|
|
|
'0' means 'both sides', and other layers follows in an unspecified order */
|
|
|
|
static int via_access_code( BOARD *aPcb, int top_layer, int bottom_layer )
|
|
|
|
{
|
|
|
|
// Easy case for through vias: top_layer is component, bottom_layer is
|
|
|
|
// solder, access code is 0
|
2014-06-24 16:17:18 +00:00
|
|
|
if( (top_layer == F_Cu) && (bottom_layer == B_Cu) )
|
2014-03-29 11:22:20 +00:00
|
|
|
return 0;
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// Blind via, reachable from front
|
2014-06-24 16:17:18 +00:00
|
|
|
if( top_layer == F_Cu )
|
2014-03-29 11:22:20 +00:00
|
|
|
return 1;
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// Blind via, reachable from bottom
|
2014-06-24 16:17:18 +00:00
|
|
|
if( bottom_layer == B_Cu )
|
2014-03-29 11:22:20 +00:00
|
|
|
return aPcb->GetCopperLayerCount();
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// It's a buried via, accessible from some inner layer
|
|
|
|
// (maybe could be used for testing before laminating? no idea)
|
|
|
|
return bottom_layer + 1; // XXX is this correct?
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract the D356 record from the vias */
|
2020-07-01 12:28:10 +00:00
|
|
|
static void build_via_testpoints( BOARD *aPcb, std::vector <D356_RECORD>& aRecords )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
2020-07-01 12:28:10 +00:00
|
|
|
wxPoint origin = aPcb->GetDesignSettings().m_AuxOrigin;
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// Enumerate all the track segments and keep the vias
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto track : aPcb->Tracks() )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
2014-04-25 06:00:04 +00:00
|
|
|
VIA *via = (VIA*) track;
|
|
|
|
NETINFO_ITEM *net = track->GetNet();
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
D356_RECORD rk;
|
2014-04-25 06:00:04 +00:00
|
|
|
rk.smd = false;
|
2013-09-13 10:59:47 +00:00
|
|
|
rk.hole = true;
|
2014-04-25 06:00:04 +00:00
|
|
|
if( net )
|
|
|
|
rk.netname = net->GetNetname();
|
|
|
|
else
|
|
|
|
rk.netname = wxEmptyString;
|
2013-09-13 10:59:47 +00:00
|
|
|
rk.refdes = wxT("VIA");
|
|
|
|
rk.pin = wxT("");
|
|
|
|
rk.midpoint = true; // Vias are always midpoints
|
|
|
|
rk.drill = via->GetDrillValue();
|
|
|
|
rk.mechanical = false;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID top_layer, bottom_layer;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
via->LayerPair( &top_layer, &bottom_layer );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2013-09-13 10:59:47 +00:00
|
|
|
rk.access = via_access_code( aPcb, top_layer, bottom_layer );
|
|
|
|
rk.x_location = via->GetPosition().x - origin.x;
|
|
|
|
rk.y_location = origin.y - via->GetPosition().y;
|
|
|
|
rk.x_size = via->GetWidth();
|
|
|
|
rk.y_size = 0; // Round so height = 0
|
|
|
|
rk.rotation = 0;
|
|
|
|
rk.soldermask = 3; // XXX always tented?
|
|
|
|
|
|
|
|
aRecords.push_back( rk );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a new netname to the d356 canonicalized list */
|
|
|
|
static const wxString intern_new_d356_netname( const wxString &aNetname,
|
|
|
|
std::map<wxString, wxString> &aMap, std::set<wxString> &aSet )
|
|
|
|
{
|
|
|
|
wxString canon;
|
2018-03-12 07:34:21 +00:00
|
|
|
|
|
|
|
for( size_t ii = 0; ii < aNetname.Len(); ++ii )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
|
|
|
// Rule: we can only use the standard ASCII, control excluded
|
2018-03-12 07:34:21 +00:00
|
|
|
wxUniChar ch = aNetname[ii];
|
|
|
|
|
|
|
|
if( ch > 126 || !std::isgraph( static_cast<unsigned char>( ch ) ) )
|
2013-09-13 10:59:47 +00:00
|
|
|
ch = '?';
|
2018-03-12 07:34:21 +00:00
|
|
|
|
2013-09-13 10:59:47 +00:00
|
|
|
canon += ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rule: only uppercase (unofficial, but known to give problems
|
|
|
|
// otherwise)
|
|
|
|
canon.MakeUpper();
|
|
|
|
|
|
|
|
// Rule: maximum length is 14 characters, otherwise we keep the tail
|
|
|
|
if( canon.size() > 14 )
|
|
|
|
{
|
|
|
|
canon = canon.Right( 14 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if it's still unique
|
|
|
|
if( aSet.count( canon ) )
|
|
|
|
{
|
|
|
|
// Nope, need to uniquify it, trim it more and add a number
|
|
|
|
wxString base( canon );
|
|
|
|
if( base.size() > 10 )
|
|
|
|
{
|
|
|
|
base = base.Right( 10 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int ctr = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
++ctr;
|
|
|
|
canon = base;
|
|
|
|
canon << '#' << ctr;
|
|
|
|
} while ( aSet.count( canon ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register it
|
|
|
|
aMap[aNetname] = canon;
|
|
|
|
aSet.insert( canon );
|
|
|
|
return canon;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write all the accumuled data to the file in D356 format */
|
2020-02-04 10:30:21 +00:00
|
|
|
void IPC356D_WRITER::write_D356_records( std::vector <D356_RECORD> &aRecords, FILE* aFile )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
|
|
|
// Sanified and shorted network names and set of short names
|
|
|
|
std::map<wxString, wxString> d356_net_map;
|
|
|
|
std::set<wxString> d356_net_set;
|
|
|
|
|
2020-02-04 10:30:21 +00:00
|
|
|
for( unsigned i = 0; i < aRecords.size(); i++ )
|
2013-09-13 10:59:47 +00:00
|
|
|
{
|
|
|
|
D356_RECORD &rk = aRecords[i];
|
|
|
|
|
|
|
|
// Try to sanify the network name (there are limits on this), if
|
|
|
|
// not already done. Also 'empty' net are marked as N/C, as
|
|
|
|
// specified.
|
2020-02-04 10:30:21 +00:00
|
|
|
wxString d356_net( wxT( "N/C" ) );
|
|
|
|
|
2013-09-13 10:59:47 +00:00
|
|
|
if( !rk.netname.empty() )
|
|
|
|
{
|
|
|
|
d356_net = d356_net_map[rk.netname];
|
|
|
|
|
|
|
|
if( d356_net.empty() )
|
2020-02-04 10:30:21 +00:00
|
|
|
d356_net = intern_new_d356_netname( rk.netname, d356_net_map, d356_net_set );
|
2013-09-13 10:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Choose the best record type
|
|
|
|
int rktype;
|
2020-02-04 10:30:21 +00:00
|
|
|
|
2013-09-13 10:59:47 +00:00
|
|
|
if( rk.smd )
|
|
|
|
rktype = 327;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( rk.mechanical )
|
|
|
|
rktype = 367;
|
|
|
|
else
|
|
|
|
rktype = 317;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Operation code, signal and component
|
2020-02-04 10:30:21 +00:00
|
|
|
fprintf( aFile, "%03d%-14.14s %-6.6s%c%-4.4s%c",
|
2013-09-13 10:59:47 +00:00
|
|
|
rktype, TO_UTF8(d356_net),
|
|
|
|
TO_UTF8(rk.refdes),
|
|
|
|
rk.pin.empty()?' ':'-',
|
|
|
|
TO_UTF8(rk.pin),
|
|
|
|
rk.midpoint?'M':' ' );
|
|
|
|
|
|
|
|
// Hole definition
|
|
|
|
if( rk.hole )
|
|
|
|
{
|
2020-02-04 10:30:21 +00:00
|
|
|
fprintf( aFile, "D%04d%c",
|
2013-09-13 10:59:47 +00:00
|
|
|
iu_to_d356( rk.drill, 9999 ),
|
|
|
|
rk.mechanical ? 'U':'P' );
|
|
|
|
}
|
|
|
|
else
|
2020-02-04 10:30:21 +00:00
|
|
|
fprintf( aFile, " " );
|
2013-09-13 10:59:47 +00:00
|
|
|
|
|
|
|
// Test point access
|
2020-02-04 10:30:21 +00:00
|
|
|
fprintf( aFile, "A%02dX%+07dY%+07dX%04dY%04dR%03d",
|
2013-09-13 10:59:47 +00:00
|
|
|
rk.access,
|
|
|
|
iu_to_d356( rk.x_location, 999999 ),
|
|
|
|
iu_to_d356( rk.y_location, 999999 ),
|
|
|
|
iu_to_d356( rk.x_size, 9999 ),
|
|
|
|
iu_to_d356( rk.y_size, 9999 ),
|
|
|
|
rk.rotation );
|
|
|
|
|
|
|
|
// Soldermask
|
2020-02-04 10:30:21 +00:00
|
|
|
fprintf( aFile, "S%d\n", rk.soldermask );
|
2013-09-13 10:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2020-02-04 10:30:21 +00:00
|
|
|
void IPC356D_WRITER::Write( const wxString& aFilename )
|
|
|
|
{
|
|
|
|
FILE* file = nullptr;
|
|
|
|
LOCALE_IO toggle; // Switch the locale to standard C
|
|
|
|
|
|
|
|
if( ( file = wxFopen( aFilename, wxT( "wt" ) ) ) == nullptr )
|
|
|
|
{
|
|
|
|
wxString details;
|
|
|
|
details.Printf( "The file %s could not be opened for writing", aFilename );
|
|
|
|
DisplayErrorMessage( m_parent, "Could not write IPC-356D file!", details );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will contain everything needed for the 356 file
|
|
|
|
std::vector<D356_RECORD> d356_records;
|
|
|
|
|
|
|
|
build_via_testpoints( m_pcb, d356_records );
|
|
|
|
|
|
|
|
build_pad_testpoints( m_pcb, d356_records );
|
|
|
|
|
|
|
|
// Code 00 AFAIK is ASCII, CUST 0 is decimils/degrees
|
|
|
|
// CUST 1 would be metric but gerbtool simply ignores it!
|
|
|
|
fprintf( file, "P CODE 00\n" );
|
|
|
|
fprintf( file, "P UNITS CUST 0\n" );
|
|
|
|
fprintf( file, "P arrayDim N\n" );
|
|
|
|
write_D356_records( d356_records, file );
|
|
|
|
fprintf( file, "999\n" );
|
|
|
|
|
|
|
|
fclose( file );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-13 10:59:47 +00:00
|
|
|
void PCB_EDIT_FRAME::GenD356File( wxCommandEvent& aEvent )
|
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxFileName fn = GetBoard()->GetFileName();
|
|
|
|
wxString msg, ext, wildcard;
|
2013-09-13 10:59:47 +00:00
|
|
|
|
2017-11-12 00:31:38 +00:00
|
|
|
ext = IpcD356FileExtension;
|
|
|
|
wildcard = IpcD356FileWildcard();
|
2013-09-13 10:59:47 +00:00
|
|
|
fn.SetExt( ext );
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
|
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "Export D-356 Test File" ), pro_dir,
|
2013-09-13 10:59:47 +00:00
|
|
|
fn.GetFullName(), wildcard,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2020-02-04 10:30:21 +00:00
|
|
|
IPC356D_WRITER writer( GetBoard(), this );
|
2013-09-13 10:59:47 +00:00
|
|
|
|
2020-02-04 10:30:21 +00:00
|
|
|
writer.Write( dlg.GetPath() );
|
2013-09-13 10:59:47 +00:00
|
|
|
}
|