2008-02-06 22:32:15 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2008-02-06 22:32:15 +00:00
|
|
|
*
|
2013-05-01 15:48:00 +00:00
|
|
|
* Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2022-03-16 11:31:45 +00:00
|
|
|
* Copyright (C) 2007-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2008-02-07 20:23:58 +00:00
|
|
|
*
|
2008-02-06 22:32:15 +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.
|
2008-02-07 20:23:58 +00:00
|
|
|
*
|
2008-02-06 22:32:15 +00:00
|
|
|
* 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.
|
2008-02-07 20:23:58 +00:00
|
|
|
*
|
2008-02-06 22:32:15 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
2008-02-07 20:23:58 +00:00
|
|
|
* 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.,
|
2008-02-06 22:32:15 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2008-02-06 22:32:15 +00:00
|
|
|
/* This source is a complement to specctra.cpp and implements the import of
|
2008-02-07 20:23:58 +00:00
|
|
|
a specctra session file (*.ses), and import of a specctra design file
|
|
|
|
(*.dsn) file. The specification for the grammar of the specctra dsn file
|
2008-02-06 22:32:15 +00:00
|
|
|
used to develop this code is given here:
|
2008-09-17 13:32:43 +00:00
|
|
|
http://tech.groups.yahoo.com/group/kicad-users/files/ then file "specctra.pdf"
|
2008-02-06 22:32:15 +00:00
|
|
|
Also see the comments at the top of the specctra.cpp file itself.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h> // DisplayError()
|
|
|
|
#include <gestfich.h> // EDA_FileSelector()
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2013-05-02 18:06:58 +00:00
|
|
|
#include <macros.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>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2023-05-18 03:03:06 +00:00
|
|
|
#include <pcb_group.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2017-03-21 10:22:03 +00:00
|
|
|
#include <view/view.h>
|
2018-01-29 17:09:18 +00:00
|
|
|
#include "specctra.h"
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2008-02-06 22:32:15 +00:00
|
|
|
|
|
|
|
using namespace DSN;
|
|
|
|
|
2019-04-15 22:54:47 +00:00
|
|
|
bool PCB_EDIT_FRAME::ImportSpecctraSession( const wxString& fullFileName )
|
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
// To avoid issues with undo/redo lists (dangling pointers) clear the lists
|
2017-03-21 10:22:03 +00:00
|
|
|
// todo: use undo/redo feature
|
2020-07-13 11:21:40 +00:00
|
|
|
ClearUndoRedoList();
|
2017-03-21 10:22:03 +00:00
|
|
|
|
2022-03-16 11:31:45 +00:00
|
|
|
if( GetCanvas() ) // clear view:
|
|
|
|
{
|
|
|
|
for( PCB_TRACK* track : GetBoard()->Tracks() )
|
|
|
|
GetCanvas()->GetView()->Remove( track );
|
|
|
|
}
|
|
|
|
|
2008-02-07 20:23:58 +00:00
|
|
|
try
|
|
|
|
{
|
2023-11-20 03:06:27 +00:00
|
|
|
DSN::ImportSpecctraSession( GetBoard(), fullFileName );
|
2008-02-07 06:49:16 +00:00
|
|
|
}
|
2023-11-20 03:06:27 +00:00
|
|
|
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2008-02-07 06:49:16 +00:00
|
|
|
{
|
2019-06-04 20:59:59 +00:00
|
|
|
wxString msg = _( "Board may be corrupted, do not save it.\n Fix problem and try again" );
|
2017-07-20 14:06:41 +00:00
|
|
|
|
|
|
|
wxString extra = ioe.What();
|
2008-02-09 08:34:45 +00:00
|
|
|
|
2017-07-20 14:06:41 +00:00
|
|
|
DisplayErrorMessage( this, msg, extra);
|
2019-04-15 22:54:47 +00:00
|
|
|
return false;
|
2008-02-07 06:49:16 +00:00
|
|
|
}
|
2008-02-07 17:10:12 +00:00
|
|
|
|
2022-10-06 23:15:17 +00:00
|
|
|
OnModify();
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
if( GetCanvas() ) // Update view:
|
2017-03-21 10:22:03 +00:00
|
|
|
{
|
|
|
|
// Update footprint positions
|
|
|
|
|
Fix typos in pcbnew sub-directory
Found via `codespell -q 3 -S *.po,./thirdparty,./Documentation/changelogs -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,ba,busses,dout,einstance,leaded,modul,ontext,ot,overide,serie,te,,tesselate,tesselator,tht`
2022-06-29 20:21:10 +00:00
|
|
|
// add imported tracks (previous tracks are removed, therefore all are new)
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto track : GetBoard()->Tracks() )
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->GetView()->Add( track );
|
2023-11-20 03:06:27 +00:00
|
|
|
}
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( wxString( _( "Session file imported and merged OK." ) ) );
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2017-03-21 10:22:03 +00:00
|
|
|
Refresh();
|
2019-04-15 22:54:47 +00:00
|
|
|
|
|
|
|
return true;
|
2008-02-07 06:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DSN {
|
2008-02-07 17:10:12 +00:00
|
|
|
|
2008-06-30 13:47:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function scale
|
2011-09-30 18:15:37 +00:00
|
|
|
* converts a session file distance to KiCad units of deci-mils.
|
2008-06-30 13:47:55 +00:00
|
|
|
* @param distance The session file length to convert.
|
2022-08-20 09:27:35 +00:00
|
|
|
* @param aResolution The session UNIT_RES which holds the engineering unit specifier
|
2018-02-03 17:50:55 +00:00
|
|
|
* @return int - The KiCad length in internal unit
|
2008-06-30 13:47:55 +00:00
|
|
|
*/
|
2008-02-08 00:16:59 +00:00
|
|
|
static int scale( double distance, UNIT_RES* aResolution )
|
2008-02-07 17:10:12 +00:00
|
|
|
{
|
2008-02-07 20:23:58 +00:00
|
|
|
double resValue = aResolution->GetValue();
|
2012-04-11 14:49:11 +00:00
|
|
|
double factor;
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2012-04-10 16:28:26 +00:00
|
|
|
switch( aResolution->GetEngUnits() )
|
|
|
|
{
|
|
|
|
default:
|
2022-08-20 09:27:35 +00:00
|
|
|
case T_inch: factor = 25.4e6; break; // nanometers per inch
|
|
|
|
case T_mil: factor = 25.4e3; break; // nanometers per mil
|
|
|
|
case T_cm: factor = 1e7; break; // nanometers per cm
|
|
|
|
case T_mm: factor = 1e6; break; // nanometers per mm
|
|
|
|
case T_um: factor = 1e3; break; // nanometers per um
|
2012-04-10 16:28:26 +00:00
|
|
|
}
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
return KiROUND( factor * distance / resValue );
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2008-02-12 01:02:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function mapPt
|
|
|
|
* translates a point from the Specctra Session format coordinate system
|
2011-09-30 18:15:37 +00:00
|
|
|
* to the KiCad coordinate system.
|
2008-02-12 01:02:53 +00:00
|
|
|
* @param aPoint The session point to translate
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aResolution - The amount to scale the point.
|
2011-09-30 18:15:37 +00:00
|
|
|
* @return wxPoint - The KiCad coordinate system point.
|
2008-02-12 01:02:53 +00:00
|
|
|
*/
|
2023-02-19 03:40:07 +00:00
|
|
|
static VECTOR2I mapPt( const POINT& aPoint, UNIT_RES* aResolution )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I ret( scale( aPoint.x, aResolution ),
|
|
|
|
-scale( aPoint.y, aResolution ) ); // negate y
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2008-02-07 17:10:12 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2008-02-07 06:49:16 +00:00
|
|
|
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2022-03-16 11:31:45 +00:00
|
|
|
PCB_TRACK* SPECCTRA_DB::makeTRACK( WIRE* wire, PATH* aPath, int aPointIndex, int aNetcode )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2013-05-05 10:11:30 +00:00
|
|
|
int layerNdx = findLayerName( aPath->layer_id );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
|
|
|
if( layerNdx == -1 )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Session file uses invalid layer id '%s'." ),
|
2023-09-09 04:10:57 +00:00
|
|
|
From_UTF8( aPath->layer_id.c_str() ) ) );
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* track = new PCB_TRACK( m_sessionBoard );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
track->SetStart( mapPt( aPath->points[aPointIndex+0], m_routeResolution ) );
|
|
|
|
track->SetEnd( mapPt( aPath->points[aPointIndex+1], m_routeResolution ) );
|
|
|
|
track->SetLayer( m_pcbLayer2kicad[layerNdx] );
|
|
|
|
track->SetWidth( scale( aPath->aperture_width, m_routeResolution ) );
|
2014-02-25 10:40:34 +00:00
|
|
|
track->SetNetCode( aNetcode );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2022-03-16 11:31:45 +00:00
|
|
|
// a track can be locked.
|
|
|
|
// However specctra as 4 types, none is exactly the same as our locked option
|
|
|
|
// wire->wire_type = T_fix, T_route, T_normal or T_protect
|
|
|
|
// fix and protect could be used as lock option
|
|
|
|
// but protect is returned for all tracks having initially the route or protect property
|
2023-04-01 14:14:35 +00:00
|
|
|
if( wire->m_wire_type == T_fix )
|
2022-03-16 11:31:45 +00:00
|
|
|
track->SetLocked( true );
|
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-16 11:31:45 +00:00
|
|
|
PCB_VIA* SPECCTRA_DB::makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT& aPoint, int aNetCode,
|
2021-06-11 21:07:02 +00:00
|
|
|
int aViaDrillDefault )
|
2008-02-09 08:34:45 +00:00
|
|
|
{
|
2023-04-01 14:14:35 +00:00
|
|
|
PCB_VIA* via = nullptr;
|
2021-06-11 21:07:02 +00:00
|
|
|
SHAPE* shape;
|
|
|
|
int shapeCount = aPadstack->Length();
|
|
|
|
int drill_diam_iu = -1;
|
|
|
|
int copperLayerCount = m_sessionBoard->GetCopperLayerCount();
|
2008-02-09 08:34:45 +00:00
|
|
|
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// The drill diameter is encoded in the padstack name if Pcbnew did the DSN export.
|
2015-06-23 08:37:54 +00:00
|
|
|
// It is after the colon and before the last '_'
|
2023-04-01 13:11:56 +00:00
|
|
|
int drillStartNdx = aPadstack->m_padstack_id.find( ':' );
|
2008-02-09 08:34:45 +00:00
|
|
|
|
|
|
|
if( drillStartNdx != -1 )
|
|
|
|
{
|
2008-02-12 01:02:53 +00:00
|
|
|
++drillStartNdx; // skip over the ':'
|
2015-06-23 08:37:54 +00:00
|
|
|
|
2023-04-01 13:11:56 +00:00
|
|
|
int drillEndNdx = aPadstack->m_padstack_id.rfind( '_' );
|
2008-02-09 08:34:45 +00:00
|
|
|
if( drillEndNdx != -1 )
|
|
|
|
{
|
2023-04-01 13:11:56 +00:00
|
|
|
std::string diam_txt( aPadstack->m_padstack_id,
|
2015-06-23 08:37:54 +00:00
|
|
|
drillStartNdx, drillEndNdx-drillStartNdx );
|
2008-02-09 16:33:03 +00:00
|
|
|
|
2015-06-23 08:37:54 +00:00
|
|
|
double drill_um = strtod( diam_txt.c_str(), 0 );
|
|
|
|
|
2022-09-17 00:45:14 +00:00
|
|
|
drill_diam_iu = int( drill_um * ( pcbIUScale.IU_PER_MM / 1000.0 ) );
|
2015-06-23 08:37:54 +00:00
|
|
|
|
|
|
|
if( drill_diam_iu == aViaDrillDefault )
|
|
|
|
drill_diam_iu = UNDEFINED_DRILL_DIAMETER;
|
2008-02-09 08:34:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( shapeCount == 0 )
|
|
|
|
{
|
2015-12-10 08:13:35 +00:00
|
|
|
THROW_IO_ERROR( _( "Session via padstack has no shapes" ) );
|
2008-02-09 08:34:45 +00:00
|
|
|
}
|
|
|
|
else if( shapeCount == 1 )
|
|
|
|
{
|
|
|
|
shape = (SHAPE*) (*aPadstack)[0];
|
2008-02-12 01:02:53 +00:00
|
|
|
DSN_T type = shape->shape->Type();
|
2021-06-27 23:26:54 +00:00
|
|
|
|
2008-02-12 01:02:53 +00:00
|
|
|
if( type != T_circle )
|
2021-06-27 23:26:54 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unsupported via shape: %s." ),
|
|
|
|
GetTokenString( type ) ) );
|
|
|
|
}
|
2008-02-12 01:02:53 +00:00
|
|
|
|
|
|
|
CIRCLE* circle = (CIRCLE*) shape->shape;
|
2020-11-14 21:21:54 +00:00
|
|
|
int viaDiam = scale( circle->diameter, m_routeResolution );
|
2008-02-12 01:02:53 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
via = new PCB_VIA( m_sessionBoard );
|
2020-11-14 21:21:54 +00:00
|
|
|
via->SetPosition( mapPt( aPoint, m_routeResolution ) );
|
2015-06-23 08:37:54 +00:00
|
|
|
via->SetDrill( drill_diam_iu );
|
2019-12-28 00:55:11 +00:00
|
|
|
via->SetViaType( VIATYPE::THROUGH );
|
2013-01-13 00:04:00 +00:00
|
|
|
via->SetWidth( viaDiam );
|
2014-06-24 16:17:18 +00:00
|
|
|
via->SetLayerPair( F_Cu, B_Cu );
|
2008-02-09 08:34:45 +00:00
|
|
|
}
|
2008-02-12 01:02:53 +00:00
|
|
|
else if( shapeCount == copperLayerCount )
|
2008-02-09 08:34:45 +00:00
|
|
|
{
|
|
|
|
shape = (SHAPE*) (*aPadstack)[0];
|
2008-02-12 01:02:53 +00:00
|
|
|
DSN_T type = shape->shape->Type();
|
2022-08-20 09:27:35 +00:00
|
|
|
|
2008-02-12 01:02:53 +00:00
|
|
|
if( type != T_circle )
|
2022-08-20 09:27:35 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unsupported via shape: %s" ),
|
|
|
|
GetTokenString( type ) ) );
|
|
|
|
}
|
2008-02-12 01:02:53 +00:00
|
|
|
|
|
|
|
CIRCLE* circle = (CIRCLE*) shape->shape;
|
2020-11-14 21:21:54 +00:00
|
|
|
int viaDiam = scale( circle->diameter, m_routeResolution );
|
2008-02-12 01:02:53 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
via = new PCB_VIA( m_sessionBoard );
|
2020-11-14 21:21:54 +00:00
|
|
|
via->SetPosition( mapPt( aPoint, m_routeResolution ) );
|
2015-06-23 08:37:54 +00:00
|
|
|
via->SetDrill( drill_diam_iu );
|
2019-12-28 00:55:11 +00:00
|
|
|
via->SetViaType( VIATYPE::THROUGH );
|
2013-01-13 00:04:00 +00:00
|
|
|
via->SetWidth( viaDiam );
|
2014-06-24 16:17:18 +00:00
|
|
|
via->SetLayerPair( F_Cu, B_Cu );
|
2008-02-12 01:02:53 +00:00
|
|
|
}
|
|
|
|
else // VIA_MICROVIA or VIA_BLIND_BURIED
|
|
|
|
{
|
2013-04-29 16:35:07 +00:00
|
|
|
int topLayerNdx = -1; // session layer detectors
|
|
|
|
int botLayerNdx = INT_MAX;
|
|
|
|
|
2008-02-12 01:02:53 +00:00
|
|
|
int viaDiam = -1;
|
|
|
|
|
|
|
|
for( int i=0; i<shapeCount; ++i )
|
2008-02-09 08:34:45 +00:00
|
|
|
{
|
2008-02-12 01:02:53 +00:00
|
|
|
shape = (SHAPE*) (*aPadstack)[i];
|
|
|
|
DSN_T type = shape->shape->Type();
|
2022-08-20 09:27:35 +00:00
|
|
|
|
2008-02-12 01:02:53 +00:00
|
|
|
if( type != T_circle )
|
2022-08-20 09:27:35 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unsupported via shape: %s" ),
|
|
|
|
GetTokenString( type ) ) );
|
|
|
|
}
|
2008-02-12 01:02:53 +00:00
|
|
|
|
2008-02-09 08:34:45 +00:00
|
|
|
CIRCLE* circle = (CIRCLE*) shape->shape;
|
2008-02-12 01:02:53 +00:00
|
|
|
|
2013-04-29 16:35:07 +00:00
|
|
|
int layerNdx = findLayerName( circle->layer_id );
|
|
|
|
if( layerNdx == -1 )
|
2008-02-12 01:02:53 +00:00
|
|
|
{
|
2023-09-09 04:10:57 +00:00
|
|
|
wxString layerName = From_UTF8( circle->layer_id.c_str() );
|
2022-08-20 09:27:35 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Session file uses invalid layer id '%s'" ),
|
|
|
|
layerName ) );
|
2008-02-12 01:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( layerNdx > topLayerNdx )
|
|
|
|
topLayerNdx = layerNdx;
|
|
|
|
|
|
|
|
if( layerNdx < botLayerNdx )
|
|
|
|
botLayerNdx = layerNdx;
|
|
|
|
|
|
|
|
if( viaDiam == -1 )
|
2020-11-14 21:21:54 +00:00
|
|
|
viaDiam = scale( circle->diameter, m_routeResolution );
|
2008-02-09 08:34:45 +00:00
|
|
|
}
|
2008-02-12 01:02:53 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
via = new PCB_VIA( m_sessionBoard );
|
2020-11-14 21:21:54 +00:00
|
|
|
via->SetPosition( mapPt( aPoint, m_routeResolution ) );
|
2015-06-23 08:37:54 +00:00
|
|
|
via->SetDrill( drill_diam_iu );
|
2008-02-12 01:02:53 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
if( ( topLayerNdx == 0 && botLayerNdx == 1 )
|
|
|
|
|| ( topLayerNdx == copperLayerCount-2 && botLayerNdx == copperLayerCount-1 ) )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
via->SetViaType( VIATYPE::MICROVIA );
|
2022-08-20 09:27:35 +00:00
|
|
|
}
|
2008-02-12 01:02:53 +00:00
|
|
|
else
|
2022-08-20 09:27:35 +00:00
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
via->SetViaType( VIATYPE::BLIND_BURIED );
|
2022-08-20 09:27:35 +00:00
|
|
|
}
|
2008-02-12 01:02:53 +00:00
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
via->SetWidth( viaDiam );
|
2022-08-20 09:27:35 +00:00
|
|
|
via->SetLayerPair( m_pcbLayer2kicad[ topLayerNdx ], m_pcbLayer2kicad[ botLayerNdx ] );
|
2008-02-09 08:34:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 03:28:03 +00:00
|
|
|
wxASSERT( via );
|
2008-02-09 08:34:45 +00:00
|
|
|
|
2016-05-12 03:28:03 +00:00
|
|
|
via->SetNetCode( aNetCode );
|
2022-03-16 11:31:45 +00:00
|
|
|
|
|
|
|
// a via can be locked.
|
|
|
|
// However specctra as 4 types, none is exactly the same as our locked option
|
|
|
|
// aVia->via_type = T_fix, T_route, T_normal or T_protect
|
|
|
|
// fix and protect could be used as lock option
|
|
|
|
// but protect is returned for all tracks having initially the route or protect property
|
2023-04-01 14:14:35 +00:00
|
|
|
if( aVia->m_via_type == T_fix )
|
2022-03-16 11:31:45 +00:00
|
|
|
via->SetLocked( true );
|
|
|
|
|
2008-02-09 08:34:45 +00:00
|
|
|
return via;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-07 20:23:58 +00:00
|
|
|
// no UI code in this function, throw exception to report problems to the
|
2011-03-01 19:26:17 +00:00
|
|
|
// UI handler: void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event )
|
2008-02-07 06:49:16 +00:00
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void SPECCTRA_DB::FromSESSION( BOARD* aBoard )
|
2008-02-07 06:49:16 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
m_sessionBoard = aBoard; // not owned here
|
2008-02-07 06:49:16 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( !m_session )
|
2015-12-10 08:13:35 +00:00
|
|
|
THROW_IO_ERROR( _("Session file is missing the \"session\" section") );
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( !m_session->route )
|
2015-12-10 08:13:35 +00:00
|
|
|
THROW_IO_ERROR( _("Session file is missing the \"routes\" section") );
|
2008-02-07 06:49:16 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( !m_session->route->library )
|
2015-12-10 08:13:35 +00:00
|
|
|
THROW_IO_ERROR( _("Session file is missing the \"library_out\" section") );
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
// delete the old tracks and vias but save locked tracks/vias; they will be re-added later
|
2022-03-16 11:31:45 +00:00
|
|
|
std::vector<PCB_TRACK*> locked;
|
|
|
|
|
|
|
|
while( !aBoard->Tracks().empty() )
|
|
|
|
{
|
|
|
|
PCB_TRACK* track = aBoard->Tracks().back();
|
|
|
|
aBoard->Tracks().pop_back();
|
|
|
|
|
|
|
|
if( track->IsLocked() )
|
2023-05-18 03:03:06 +00:00
|
|
|
{
|
2022-03-16 11:31:45 +00:00
|
|
|
locked.push_back( track );
|
2023-05-18 03:03:06 +00:00
|
|
|
}
|
2022-03-16 11:31:45 +00:00
|
|
|
else
|
2023-05-18 03:03:06 +00:00
|
|
|
{
|
|
|
|
if( PCB_GROUP* group = track->GetParentGroup() )
|
|
|
|
group->RemoveItem( track );
|
|
|
|
|
2022-03-16 11:31:45 +00:00
|
|
|
delete track;
|
2023-05-18 03:03:06 +00:00
|
|
|
}
|
2022-03-16 11:31:45 +00:00
|
|
|
}
|
2008-02-07 17:10:12 +00:00
|
|
|
|
2008-02-07 20:23:58 +00:00
|
|
|
aBoard->DeleteMARKERs();
|
2008-02-07 17:10:12 +00:00
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
buildLayerMaps( aBoard );
|
|
|
|
|
2022-03-16 11:31:45 +00:00
|
|
|
// Add locked tracks: because they are exported as Fix tracks, they are not
|
|
|
|
// in .ses file.
|
|
|
|
for( PCB_TRACK* track: locked )
|
|
|
|
aBoard->Add( track );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( m_session->placement )
|
2008-02-07 06:49:16 +00:00
|
|
|
{
|
2012-01-16 21:43:07 +00:00
|
|
|
// Walk the PLACEMENT object's COMPONENTs list, and for each PLACE within
|
|
|
|
// each COMPONENT, reposition and re-orient each component and put on
|
|
|
|
// correct side of the board.
|
2023-04-01 14:14:35 +00:00
|
|
|
COMPONENTS& components = m_session->placement->m_components;
|
2022-08-20 09:27:35 +00:00
|
|
|
|
2012-01-16 21:43:07 +00:00
|
|
|
for( COMPONENTS::iterator comp=components.begin(); comp!=components.end(); ++comp )
|
2008-02-07 17:10:12 +00:00
|
|
|
{
|
2023-04-01 14:14:35 +00:00
|
|
|
PLACES& places = comp->m_places;
|
2012-01-16 21:43:07 +00:00
|
|
|
for( unsigned i=0; i<places.size(); ++i )
|
2008-02-07 17:10:12 +00:00
|
|
|
{
|
2012-01-16 21:43:07 +00:00
|
|
|
PLACE* place = &places[i]; // '&' even though places[] holds a pointer!
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2023-09-09 04:10:57 +00:00
|
|
|
wxString reference = From_UTF8( place->m_component_id.c_str() );
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = aBoard->FindFootprintByReference( reference );
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( !footprint )
|
2012-01-16 21:43:07 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Reference '%s' not found." ),
|
|
|
|
reference ) );
|
2012-01-16 21:43:07 +00:00
|
|
|
}
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2023-04-01 14:14:35 +00:00
|
|
|
if( !place->m_hasVertex )
|
2012-01-16 21:43:07 +00:00
|
|
|
continue;
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2012-01-16 21:43:07 +00:00
|
|
|
UNIT_RES* resolution = place->GetUnits();
|
|
|
|
wxASSERT( resolution );
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2023-04-01 14:14:35 +00:00
|
|
|
VECTOR2I newPos = mapPt( place->m_vertex, resolution );
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->SetPosition( newPos );
|
2012-01-16 21:43:07 +00:00
|
|
|
|
2023-04-01 14:14:35 +00:00
|
|
|
if( place->m_side == T_front )
|
2008-02-07 20:23:58 +00:00
|
|
|
{
|
2012-01-16 21:43:07 +00:00
|
|
|
// convert from degrees to tenths of degrees used in KiCad.
|
2023-04-01 14:14:35 +00:00
|
|
|
EDA_ANGLE orientation( place->m_rotation, DEGREES_T );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( footprint->GetLayer() != F_Cu )
|
2012-01-16 21:43:07 +00:00
|
|
|
{
|
2020-11-14 22:00:12 +00:00
|
|
|
// footprint is on copper layer (back)
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Flip( footprint->GetPosition(), false );
|
2012-01-16 21:43:07 +00:00
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->SetOrientation( orientation );
|
2008-02-07 20:23:58 +00:00
|
|
|
}
|
2023-04-01 14:14:35 +00:00
|
|
|
else if( place->m_side == T_back )
|
2008-02-07 20:23:58 +00:00
|
|
|
{
|
2023-04-01 14:14:35 +00:00
|
|
|
EDA_ANGLE orientation( place->m_rotation + 180.0, DEGREES_T );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( footprint->GetLayer() != B_Cu )
|
2012-01-16 21:43:07 +00:00
|
|
|
{
|
2020-11-14 22:00:12 +00:00
|
|
|
// footprint is on component layer (front)
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Flip( footprint->GetPosition(), false );
|
2012-01-16 21:43:07 +00:00
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->SetOrientation( orientation );
|
2012-01-16 21:43:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// as I write this, the PARSER *is* catching this, so we should never see below:
|
|
|
|
wxFAIL_MSG( wxT("DSN::PARSER did not catch an illegal side := 'back|front'") );
|
2009-08-07 04:44:42 +00:00
|
|
|
}
|
2008-02-07 17:10:12 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-07 06:49:16 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_routeResolution = m_session->route->GetUnits();
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2008-02-07 20:23:58 +00:00
|
|
|
// Walk the NET_OUTs and create tracks and vias anew.
|
2020-11-14 21:21:54 +00:00
|
|
|
NET_OUTS& net_outs = m_session->route->net_outs;
|
2016-04-22 10:44:08 +00:00
|
|
|
for( NET_OUTS::iterator net = net_outs.begin(); net!=net_outs.end(); ++net )
|
2008-02-07 06:49:16 +00:00
|
|
|
{
|
2016-04-29 11:10:31 +00:00
|
|
|
int netoutCode = 0;
|
2008-02-07 20:23:58 +00:00
|
|
|
|
2008-02-09 08:34:45 +00:00
|
|
|
// page 143 of spec says wire's net_id is optional
|
|
|
|
if( net->net_id.size() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2023-09-09 04:10:57 +00:00
|
|
|
wxString netName = From_UTF8( net->net_id.c_str() );
|
2016-04-22 10:44:08 +00:00
|
|
|
NETINFO_ITEM* netinfo = aBoard->FindNet( netName );
|
2008-02-09 08:34:45 +00:00
|
|
|
|
2016-04-22 10:44:08 +00:00
|
|
|
if( netinfo )
|
2020-12-08 13:02:08 +00:00
|
|
|
netoutCode = netinfo->GetNetCode();
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WIRES& wires = net->wires;
|
2016-04-22 10:44:08 +00:00
|
|
|
for( unsigned i = 0; i<wires.size(); ++i )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
|
|
|
WIRE* wire = &wires[i];
|
2023-04-01 14:14:35 +00:00
|
|
|
DSN_T shape = wire->m_shape->Type();
|
2008-02-08 00:16:59 +00:00
|
|
|
|
|
|
|
if( shape != T_path )
|
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
/*
|
|
|
|
* shape == T_polygon is expected from freerouter if you have a zone on a non-
|
|
|
|
* "power" type layer, i.e. a T_signal layer and the design does a round-trip
|
|
|
|
* back in as session here. We kept our own zones in the BOARD, so ignore this
|
|
|
|
* so called 'wire'.
|
2008-02-29 06:49:34 +00:00
|
|
|
|
2023-09-09 04:10:57 +00:00
|
|
|
wxString netId = From_UTF8( wire->net_id.c_str() );
|
2022-08-20 09:27:35 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unsupported wire shape: '%s' for net: '%s'" ),
|
2015-12-10 08:13:35 +00:00
|
|
|
DLEX::GetTokenString(shape).GetData(),
|
2022-08-20 09:27:35 +00:00
|
|
|
netId.GetData() ) );
|
2008-02-29 06:49:34 +00:00
|
|
|
*/
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
2008-02-29 06:49:34 +00:00
|
|
|
else
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2023-04-01 14:14:35 +00:00
|
|
|
PATH* path = (PATH*) wire->m_shape;
|
2021-06-11 21:07:02 +00:00
|
|
|
|
2022-03-16 11:31:45 +00:00
|
|
|
for( unsigned pt=0; pt < path->points.size()-1; ++pt )
|
2008-02-29 06:49:34 +00:00
|
|
|
{
|
2022-03-16 11:31:45 +00:00
|
|
|
PCB_TRACK* track = makeTRACK( wire, path, pt, netoutCode );
|
2008-02-29 06:49:34 +00:00
|
|
|
aBoard->Add( track );
|
|
|
|
}
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WIRE_VIAS& wire_vias = net->wire_vias;
|
2020-11-14 21:21:54 +00:00
|
|
|
LIBRARY& library = *m_session->route->library;
|
2022-08-20 09:27:35 +00:00
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
for( unsigned i=0; i<wire_vias.size(); ++i )
|
|
|
|
{
|
2008-02-09 08:34:45 +00:00
|
|
|
int netCode = 0;
|
|
|
|
|
|
|
|
// page 144 of spec says wire_via's net_id is optional
|
|
|
|
if( net->net_id.size() )
|
|
|
|
{
|
2023-09-09 04:10:57 +00:00
|
|
|
wxString netName = From_UTF8( net->net_id.c_str() );
|
2016-04-29 11:10:31 +00:00
|
|
|
NETINFO_ITEM* netvia = aBoard->FindNet( netName );
|
2008-02-09 08:34:45 +00:00
|
|
|
|
2016-04-29 11:10:31 +00:00
|
|
|
if( netvia )
|
2020-12-08 13:02:08 +00:00
|
|
|
netCode = netvia->GetNetCode();
|
2008-02-09 08:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WIRE_VIA* wire_via = &wire_vias[i];
|
|
|
|
|
|
|
|
// example: (via Via_15:8_mil 149000 -71000 )
|
|
|
|
|
|
|
|
PADSTACK* padstack = library.FindPADSTACK( wire_via->GetPadstackId() );
|
|
|
|
if( !padstack )
|
|
|
|
{
|
2008-02-29 23:01:30 +00:00
|
|
|
// Dick Feb 29, 2008:
|
2022-08-20 09:27:35 +00:00
|
|
|
// Freerouter has a bug where it will not round trip all vias. Vias which have
|
|
|
|
// a (use_via) element will be round tripped. Vias which do not, don't come back
|
|
|
|
// in in the session library, even though they may be actually used in the
|
|
|
|
// pre-routed, protected wire_vias. So until that is fixed, create the padstack
|
|
|
|
// from its name as a work around.
|
2023-09-09 04:10:57 +00:00
|
|
|
wxString psid( From_UTF8( wire_via->GetPadstackId().c_str() ) );
|
2008-02-09 08:34:45 +00:00
|
|
|
|
2021-06-27 23:26:54 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "A wire_via refers to missing padstack '%s'." ),
|
|
|
|
psid ) );
|
2008-02-09 08:34:45 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NET_SETTINGS>& netSettings = aBoard->GetDesignSettings().m_NetSettings;
|
2015-06-23 08:37:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
int via_drill_default = netSettings->m_DefaultNetClass->GetViaDrill();
|
2015-06-23 08:37:54 +00:00
|
|
|
|
2023-04-01 14:14:35 +00:00
|
|
|
for( unsigned v = 0; v < wire_via->m_vertexes.size(); ++v )
|
2008-02-09 08:34:45 +00:00
|
|
|
{
|
2023-04-01 14:14:35 +00:00
|
|
|
PCB_VIA* via = makeVIA( wire_via, padstack, wire_via->m_vertexes[v], netCode,
|
2021-06-11 21:07:02 +00:00
|
|
|
via_drill_default );
|
2008-02-12 01:02:53 +00:00
|
|
|
aBoard->Add( via );
|
2008-02-09 08:34:45 +00:00
|
|
|
}
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
2008-02-07 06:49:16 +00:00
|
|
|
}
|
2008-02-06 22:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-20 03:06:27 +00:00
|
|
|
bool ImportSpecctraSession( BOARD* aBoard, const wxString& fullFileName )
|
|
|
|
{
|
|
|
|
SPECCTRA_DB db;
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
db.LoadSESSION( fullFileName );
|
|
|
|
db.FromSESSION( aBoard );
|
|
|
|
|
|
|
|
aBoard->GetConnectivity()->ClearRatsnest();
|
|
|
|
aBoard->BuildConnectivity();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2008-02-07 06:49:16 +00:00
|
|
|
} // namespace DSN
|