2019-04-08 00:09:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 CERN
|
2023-06-24 18:54:50 +00:00
|
|
|
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-04-08 00:09:07 +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
|
|
|
|
*/
|
|
|
|
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2019-04-08 00:09:07 +00:00
|
|
|
#include <pcb_edit_frame.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-14 18:11:28 +00:00
|
|
|
#include <board_item.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-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2019-04-08 00:09:07 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <vector>
|
|
|
|
#include <ki_exception.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2019-04-08 00:09:07 +00:00
|
|
|
#include <reporter.h>
|
|
|
|
#include <exporters/board_exporter_base.h>
|
2024-05-06 01:39:25 +00:00
|
|
|
#include <wx/log.h>
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
static double iu2hyp( double iu )
|
|
|
|
{
|
|
|
|
return iu / 1e9 / 0.0254;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class HYPERLYNX_EXPORTER;
|
|
|
|
|
|
|
|
class HYPERLYNX_PAD_STACK
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
friend class HYPERLYNX_EXPORTER;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
HYPERLYNX_PAD_STACK( BOARD* aBoard, const PAD* aPad );
|
2021-06-11 21:07:02 +00:00
|
|
|
HYPERLYNX_PAD_STACK( BOARD* aBoard, const PCB_VIA* aVia );
|
2019-04-08 00:09:07 +00:00
|
|
|
~HYPERLYNX_PAD_STACK(){};
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
bool IsThrough() const
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2021-05-01 14:46:50 +00:00
|
|
|
return m_type == PAD_ATTRIB::NPTH || m_type == PAD_ATTRIB::PTH;
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==( const HYPERLYNX_PAD_STACK& other ) const
|
|
|
|
{
|
|
|
|
if( m_shape != other.m_shape )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_type != other.m_type )
|
|
|
|
return false;
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
if( IsThrough() && other.IsThrough() && m_drill != other.m_drill )
|
2019-04-08 00:09:07 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_sx != other.m_sx )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_sy != other.m_sy )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_layers != other.m_layers )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_angle != other.m_angle )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetId( int id )
|
|
|
|
{
|
|
|
|
m_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetId() const
|
|
|
|
{
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
bool IsEmpty() const
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
LSET layerMask = LSET::AllCuMask() & m_board->GetEnabledLayers();
|
|
|
|
LSET outLayers = m_layers & layerMask;
|
|
|
|
|
|
|
|
return outLayers.none();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BOARD* m_board;
|
|
|
|
int m_id;
|
|
|
|
int m_drill;
|
2021-05-01 12:22:35 +00:00
|
|
|
PAD_SHAPE m_shape;
|
2019-04-08 00:09:07 +00:00
|
|
|
int m_sx, m_sy;
|
|
|
|
double m_angle;
|
|
|
|
LSET m_layers;
|
2021-05-01 14:46:50 +00:00
|
|
|
PAD_ATTRIB m_type;
|
2019-04-08 00:09:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class HYPERLYNX_EXPORTER : public BOARD_EXPORTER_BASE
|
|
|
|
{
|
|
|
|
public:
|
2020-01-12 13:00:42 +00:00
|
|
|
HYPERLYNX_EXPORTER() : m_polyId( 1 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-08 00:09:07 +00:00
|
|
|
~HYPERLYNX_EXPORTER(){};
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
HYPERLYNX_PAD_STACK* addPadStack( HYPERLYNX_PAD_STACK stack )
|
|
|
|
{
|
2020-08-22 21:03:43 +00:00
|
|
|
for( HYPERLYNX_PAD_STACK* p : m_padStacks )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
if( *p == stack )
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
stack.SetId( m_padStacks.size() );
|
|
|
|
m_padStacks.push_back( new HYPERLYNX_PAD_STACK( stack ) );
|
|
|
|
|
|
|
|
return m_padStacks.back();
|
|
|
|
}
|
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
const std::string formatPadShape( const HYPERLYNX_PAD_STACK& aStack )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
int shapeId = 0;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
switch( aStack.m_shape )
|
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::CIRCLE:
|
2022-05-27 23:18:46 +00:00
|
|
|
case PAD_SHAPE::OVAL:
|
2019-04-08 00:09:07 +00:00
|
|
|
shapeId = 0;
|
2022-05-27 23:18:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE::ROUNDRECT:
|
|
|
|
shapeId = 2;
|
|
|
|
break;
|
2019-04-09 17:56:36 +00:00
|
|
|
|
2023-06-02 09:10:48 +00:00
|
|
|
case PAD_SHAPE::RECTANGLE:
|
2022-05-27 23:18:46 +00:00
|
|
|
shapeId = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-04-08 00:09:07 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
m_reporter->Report( _( "File contains pad shapes that are not supported by the "
|
2022-05-27 23:18:46 +00:00
|
|
|
"Hyperlynx exporter (supported shapes are oval, rectangle, "
|
|
|
|
"rounded rectangle, and circle)." ),
|
2021-07-05 12:40:38 +00:00
|
|
|
RPT_SEVERITY_WARNING );
|
|
|
|
m_reporter->Report( _( "They have been exported as oval pads." ),
|
|
|
|
RPT_SEVERITY_INFO );
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
2022-05-27 23:18:46 +00:00
|
|
|
|
|
|
|
shapeId = 0;
|
2019-04-08 00:09:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
snprintf( buf, sizeof( buf ), "%d, %.9f, %.9f, %.1f, M",
|
|
|
|
shapeId,
|
|
|
|
iu2hyp( aStack.m_sx ),
|
|
|
|
iu2hyp( aStack.m_sy ),
|
|
|
|
aStack.m_angle );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool generateHeaders();
|
|
|
|
bool writeBoardInfo();
|
|
|
|
bool writeStackupInfo();
|
|
|
|
bool writeDevices();
|
|
|
|
bool writePadStacks();
|
|
|
|
bool writeNets();
|
|
|
|
bool writeNetObjects( const std::vector<BOARD_ITEM*>& aObjects );
|
|
|
|
|
|
|
|
|
|
|
|
void writeSinglePadStack( HYPERLYNX_PAD_STACK& aStack );
|
|
|
|
|
|
|
|
const std::vector<BOARD_ITEM*> collectNetObjects( int netcode );
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
private:
|
2019-04-08 00:09:07 +00:00
|
|
|
std::vector<HYPERLYNX_PAD_STACK*> m_padStacks;
|
|
|
|
std::map<BOARD_ITEM*, HYPERLYNX_PAD_STACK*> m_padMap;
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
std::shared_ptr<FILE_OUTPUTFORMATTER> m_out;
|
|
|
|
int m_polyId;
|
2019-04-08 00:09:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
HYPERLYNX_PAD_STACK::HYPERLYNX_PAD_STACK( BOARD* aBoard, const PAD* aPad )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
m_board = aBoard;
|
2020-01-12 13:00:42 +00:00
|
|
|
m_sx = aPad->GetSize().x;
|
|
|
|
m_sy = aPad->GetSize().y;
|
2022-01-13 13:45:48 +00:00
|
|
|
m_angle = 180.0 - aPad->GetOrientation().AsDegrees();
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
if( m_angle < 0.0 )
|
|
|
|
m_angle += 360.0;
|
|
|
|
|
|
|
|
m_layers = aPad->GetLayerSet();
|
2020-01-12 13:00:42 +00:00
|
|
|
m_drill = aPad->GetDrillSize().x;
|
|
|
|
m_shape = aPad->GetShape();
|
2021-05-01 14:46:50 +00:00
|
|
|
m_type = PAD_ATTRIB::PTH;
|
2020-01-12 13:00:42 +00:00
|
|
|
m_id = 0;
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
HYPERLYNX_PAD_STACK::HYPERLYNX_PAD_STACK( BOARD* aBoard, const PCB_VIA* aVia )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-01-12 13:00:42 +00:00
|
|
|
m_board = aBoard;
|
|
|
|
m_sx = aVia->GetWidth();
|
|
|
|
m_sy = aVia->GetWidth();
|
|
|
|
m_angle = 0;
|
2022-05-27 23:18:46 +00:00
|
|
|
m_layers = aVia->GetLayerSet();
|
2020-01-12 13:00:42 +00:00
|
|
|
m_drill = aVia->GetDrillValue();
|
2021-05-01 12:22:35 +00:00
|
|
|
m_shape = PAD_SHAPE::CIRCLE;
|
2021-05-01 14:46:50 +00:00
|
|
|
m_type = PAD_ATTRIB::PTH;
|
2020-01-12 13:00:42 +00:00
|
|
|
m_id = 0;
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HYPERLYNX_EXPORTER::generateHeaders()
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "{VERSION=2.14}\n" );
|
|
|
|
m_out->Print( 0, "{UNITS=ENGLISH LENGTH}\n\n" );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HYPERLYNX_EXPORTER::writeSinglePadStack( HYPERLYNX_PAD_STACK& aStack )
|
|
|
|
{
|
|
|
|
LSET layerMask = LSET::AllCuMask() & m_board->GetEnabledLayers();
|
|
|
|
LSET outLayers = aStack.m_layers & layerMask;
|
|
|
|
|
|
|
|
if( outLayers.none() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_out->Print( 0, "{PADSTACK=%d, %.9f\n", aStack.m_id, iu2hyp( aStack.m_drill ) );
|
|
|
|
|
|
|
|
if( outLayers == layerMask )
|
|
|
|
{
|
2022-05-27 23:09:47 +00:00
|
|
|
m_out->Print( 1, "(\"MDEF\", %s)\n", formatPadShape( aStack ).c_str() );
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-22 21:03:43 +00:00
|
|
|
for( PCB_LAYER_ID l : outLayers.Seq() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2022-05-27 23:09:47 +00:00
|
|
|
m_out->Print( 1, "(\"%s\", %s)\n",
|
|
|
|
(const char*) m_board->GetLayerName( l ).c_str(),
|
|
|
|
formatPadShape( aStack ).c_str() );
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "}\n\n" );
|
|
|
|
}
|
|
|
|
|
2019-04-09 17:56:36 +00:00
|
|
|
|
2019-04-08 00:09:07 +00:00
|
|
|
bool HYPERLYNX_EXPORTER::writeBoardInfo()
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET outlines;
|
|
|
|
|
|
|
|
m_out->Print( 0, "{BOARD \"%s\"\n", (const char*) m_board->GetFileName().c_str() );
|
|
|
|
|
2020-10-22 20:27:46 +00:00
|
|
|
if( !m_board->GetBoardPolygonOutlines( outlines ) )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-11-20 13:55:10 +00:00
|
|
|
wxLogError( _( "Board outline is malformed. Run DRC for a full analysis." ) );
|
2019-04-08 00:09:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int o = 0; o < outlines.OutlineCount(); o++ )
|
|
|
|
{
|
2020-08-22 21:03:43 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outl = outlines.COutline( o );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < outl.SegmentCount(); i++ )
|
|
|
|
{
|
2022-05-27 23:09:47 +00:00
|
|
|
const SEG& s = outl.CSegment( i );
|
2019-04-08 00:09:07 +00:00
|
|
|
m_out->Print( 1, "(PERIMETER_SEGMENT X1=%.9f Y1=%.9f X2=%.9f Y2=%.9f)\n",
|
2022-05-27 23:09:47 +00:00
|
|
|
iu2hyp( s.A.x ),
|
|
|
|
iu2hyp( s.A.y ),
|
|
|
|
iu2hyp( s.B.x ),
|
|
|
|
iu2hyp( s.B.y ) );
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "}\n\n" );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HYPERLYNX_EXPORTER::writeStackupInfo()
|
|
|
|
{
|
2020-07-10 15:30:56 +00:00
|
|
|
/* Format:
|
|
|
|
* {STACKUP
|
2020-08-22 21:03:43 +00:00
|
|
|
* (SIGNAL T=thickness [P=plating_thickness] [C=constant] L=layer_name [M=material_name]) [comment]
|
2020-07-10 15:30:56 +00:00
|
|
|
* (DIELECTRIC T=thickness [C=constant] [L=layer_name] [M=material_name]) [comment]
|
|
|
|
* }
|
2021-06-10 01:24:15 +00:00
|
|
|
* name length is <= 20 chars
|
2020-07-10 15:30:56 +00:00
|
|
|
*/
|
|
|
|
|
2020-08-22 21:03:43 +00:00
|
|
|
LSEQ layers = m_board->GetDesignSettings().GetEnabledLayers().CuStack();
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2020-07-10 15:30:56 +00:00
|
|
|
// Get the board physical stackup structure
|
2020-12-20 18:44:13 +00:00
|
|
|
const BOARD_STACKUP& stackup = m_board->GetDesignSettings().GetStackupDescriptor();
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2020-07-10 15:30:56 +00:00
|
|
|
m_out->Print( 0, "{STACKUP\n" );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2020-07-10 15:30:56 +00:00
|
|
|
wxString layer_name; // The last copper layer name used in stackup
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2020-07-10 15:30:56 +00:00
|
|
|
for( BOARD_STACKUP_ITEM* item: stackup.GetList() )
|
|
|
|
{
|
|
|
|
if( item->GetType() == BS_ITEM_TYPE_COPPER )
|
|
|
|
{
|
|
|
|
layer_name = m_board->GetLayerName( item->GetBrdLayerId() );
|
|
|
|
int plating_thickness = 0;
|
|
|
|
double resistivity = 1.724e-8; // Good for copper
|
|
|
|
m_out->Print( 1, "(SIGNAL T=%g P=%g C=%g L=\"%.20s\" M=COPPER)\n",
|
|
|
|
iu2hyp( item->GetThickness( 0 ) ),
|
|
|
|
iu2hyp( plating_thickness ),
|
|
|
|
resistivity,
|
|
|
|
TO_UTF8( layer_name ) );
|
|
|
|
}
|
|
|
|
else if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-07-10 15:30:56 +00:00
|
|
|
if( item->GetSublayersCount() < 2 )
|
|
|
|
{
|
|
|
|
m_out->Print( 1, "(DIELECTRIC T=%g C=%g L=\"DE_%.17s\" M=\"%.20s\")\n",
|
|
|
|
iu2hyp( item->GetThickness( 0 ) ),
|
|
|
|
item->GetEpsilonR( 0 ),
|
|
|
|
TO_UTF8( layer_name ),
|
|
|
|
TO_UTF8( item->GetMaterial( 0 ) ) );
|
|
|
|
}
|
|
|
|
else for( int idx = 0; idx < item->GetSublayersCount(); idx++ )
|
|
|
|
{
|
|
|
|
m_out->Print( 1, "(DIELECTRIC T=%g C=%g L=\"DE%d_%.16s\" M=\"%.20s\")\n",
|
|
|
|
iu2hyp( item->GetThickness( idx ) ),
|
|
|
|
item->GetEpsilonR( idx ),
|
2022-05-27 23:09:47 +00:00
|
|
|
idx,
|
|
|
|
TO_UTF8( layer_name ),
|
2020-07-10 15:30:56 +00:00
|
|
|
TO_UTF8( item->GetMaterial( idx ) ) );
|
|
|
|
}
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-10 15:30:56 +00:00
|
|
|
|
2019-04-08 00:09:07 +00:00
|
|
|
m_out->Print( 0, "}\n\n" );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HYPERLYNX_EXPORTER::writeDevices()
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "{DEVICES\n" );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
wxString ref = footprint->GetReference();
|
|
|
|
wxString layerName = m_board->GetLayerName( footprint->GetLayer() );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
if( ref.IsEmpty() )
|
2022-02-05 02:06:25 +00:00
|
|
|
ref = wxT( "EMPTY" );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
m_out->Print( 1, "(? REF=\"%s\" L=\"%s\")\n",
|
|
|
|
(const char*) ref.c_str(),
|
|
|
|
(const char*) layerName.c_str() );
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
m_out->Print( 0, "}\n\n" );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HYPERLYNX_EXPORTER::writePadStacks()
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-08-22 21:03:43 +00:00
|
|
|
HYPERLYNX_PAD_STACK* ps = addPadStack( HYPERLYNX_PAD_STACK( m_board, pad ) );
|
2019-04-08 00:09:07 +00:00
|
|
|
m_padMap[pad] = ps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
if( PCB_VIA* via = dyn_cast<PCB_VIA*>( track ) )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-08-22 21:03:43 +00:00
|
|
|
HYPERLYNX_PAD_STACK* ps = addPadStack( HYPERLYNX_PAD_STACK( m_board, via ) );
|
2019-04-08 00:09:07 +00:00
|
|
|
m_padMap[via] = ps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-22 21:03:43 +00:00
|
|
|
for( HYPERLYNX_PAD_STACK* pstack : m_padStacks )
|
2019-04-08 00:09:07 +00:00
|
|
|
writeSinglePadStack( *pstack );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HYPERLYNX_EXPORTER::writeNetObjects( const std::vector<BOARD_ITEM*>& aObjects )
|
|
|
|
{
|
2020-08-22 21:03:43 +00:00
|
|
|
for( BOARD_ITEM* item : aObjects )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
if( PAD* pad = dyn_cast<PAD*>( item ) )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
auto pstackIter = m_padMap.find( pad );
|
|
|
|
|
|
|
|
if( pstackIter != m_padMap.end() )
|
|
|
|
{
|
2023-06-24 18:54:50 +00:00
|
|
|
wxString ref = pad->GetParentFootprint()->GetReference();
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
if( ref.IsEmpty() )
|
2022-02-05 02:06:25 +00:00
|
|
|
ref = wxT( "EMPTY" );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
wxString padName = pad->GetNumber();
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
if( padName.IsEmpty() )
|
2022-02-05 02:06:25 +00:00
|
|
|
padName = wxT( "1" );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
m_out->Print( 1, "(PIN X=%.10f Y=%.10f R=\"%s.%s\" P=%d)\n",
|
2022-05-27 23:09:47 +00:00
|
|
|
iu2hyp( pad->GetPosition().x ),
|
|
|
|
iu2hyp( pad->GetPosition().y ),
|
|
|
|
(const char*) ref.c_str(),
|
|
|
|
(const char*) padName.c_str(),
|
|
|
|
pstackIter->second->GetId() );
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-11 21:07:02 +00:00
|
|
|
else if( PCB_VIA* via = dyn_cast<PCB_VIA*>( item ) )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
auto pstackIter = m_padMap.find( via );
|
|
|
|
|
|
|
|
if( pstackIter != m_padMap.end() )
|
|
|
|
{
|
2022-05-27 23:09:47 +00:00
|
|
|
m_out->Print( 1, "(VIA X=%.10f Y=%.10f P=%d)\n",
|
|
|
|
iu2hyp( via->GetPosition().x ),
|
|
|
|
iu2hyp( via->GetPosition().y ),
|
|
|
|
pstackIter->second->GetId() );
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-11 21:07:02 +00:00
|
|
|
else if( PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item ) )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-08-22 21:03:43 +00:00
|
|
|
const wxString layerName = m_board->GetLayerName( track->GetLayer() );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
m_out->Print( 1, "(SEG X1=%.10f Y1=%.10f X2=%.10f Y2=%.10f W=%.10f L=\"%s\")\n",
|
2022-05-27 23:09:47 +00:00
|
|
|
iu2hyp( track->GetStart().x ),
|
|
|
|
iu2hyp( track->GetStart().y ),
|
|
|
|
iu2hyp( track->GetEnd().x ),
|
|
|
|
iu2hyp( track->GetEnd().y ),
|
|
|
|
iu2hyp( track->GetWidth() ),
|
|
|
|
(const char*) layerName.c_str() );
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
2022-05-27 23:18:46 +00:00
|
|
|
else if( PCB_ARC* arc = dyn_cast<PCB_ARC*>( item ) )
|
|
|
|
{
|
2022-05-31 23:34:13 +00:00
|
|
|
const wxString layerName = m_board->GetLayerName( arc->GetLayer() );
|
2022-06-20 11:46:49 +00:00
|
|
|
VECTOR2I start = arc->GetStart();
|
|
|
|
VECTOR2I end = arc->GetEnd();
|
|
|
|
|
2022-06-22 16:57:42 +00:00
|
|
|
if( arc->IsCCW() )
|
2022-06-20 11:46:49 +00:00
|
|
|
std::swap( start, end );
|
2022-05-31 23:34:13 +00:00
|
|
|
|
|
|
|
m_out->Print( 1, "(ARC X1=%.10f Y1=%.10f X2=%.10f Y2=%.10f XC=%.10f YC=%.10f R=%.10f W=%.10f L=\"%s\")\n",
|
2022-06-20 11:46:49 +00:00
|
|
|
iu2hyp( start.x ),
|
|
|
|
iu2hyp( start.y ),
|
|
|
|
iu2hyp( end.x ),
|
|
|
|
iu2hyp( end.y ),
|
2022-05-31 23:34:13 +00:00
|
|
|
iu2hyp( arc->GetCenter().x ),
|
|
|
|
iu2hyp( arc->GetCenter().y ),
|
|
|
|
iu2hyp( arc->GetRadius() ),
|
|
|
|
iu2hyp( arc->GetWidth() ),
|
|
|
|
(const char*) layerName.c_str() );
|
2022-05-27 23:18:46 +00:00
|
|
|
}
|
2020-11-11 23:05:59 +00:00
|
|
|
else if( ZONE* zone = dyn_cast<ZONE*>( item ) )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-08-22 21:03:43 +00:00
|
|
|
const wxString layerName = m_board->GetLayerName( layer );
|
2022-03-14 15:52:12 +00:00
|
|
|
SHAPE_POLY_SET fill = zone->GetFilledPolysList( layer )->CloneDropTriangulation();
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2022-03-14 15:52:12 +00:00
|
|
|
fill.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2022-03-14 15:52:12 +00:00
|
|
|
for( int i = 0; i < fill.OutlineCount(); i++ )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2022-03-14 15:52:12 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outl = fill.COutline( i );
|
2022-05-27 23:09:47 +00:00
|
|
|
const VECTOR2I p0 = outl.CPoint( 0 );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
m_out->Print( 1, "{POLYGON T=POUR L=\"%s\" ID=%d X=%.10f Y=%.10f\n",
|
2022-03-14 15:52:12 +00:00
|
|
|
(const char*) layerName.c_str(),
|
|
|
|
m_polyId,
|
|
|
|
iu2hyp( p0.x ),
|
|
|
|
iu2hyp( p0.y ) );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
for( int v = 0; v < outl.PointCount(); v++ )
|
|
|
|
{
|
2022-03-14 15:52:12 +00:00
|
|
|
m_out->Print( 2, "(LINE X=%.10f Y=%.10f)\n",
|
|
|
|
iu2hyp( outl.CPoint( v ).x ),
|
|
|
|
iu2hyp( outl.CPoint( v ).y ) );
|
2020-06-24 02:19:08 +00:00
|
|
|
}
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
m_out->Print( 2, "(LINE X=%.10f Y=%.10f)\n", iu2hyp( p0.x ), iu2hyp( p0.y ) );
|
|
|
|
m_out->Print( 1, "}\n" );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2022-03-14 15:52:12 +00:00
|
|
|
for( int h = 0; h < fill.HoleCount( i ); h++ )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2022-03-14 15:52:12 +00:00
|
|
|
const SHAPE_LINE_CHAIN& holeShape = fill.CHole( i, h );
|
2022-05-27 23:09:47 +00:00
|
|
|
const VECTOR2I ph0 = holeShape.CPoint( 0 );
|
2020-06-24 02:19:08 +00:00
|
|
|
|
2022-03-14 15:52:12 +00:00
|
|
|
m_out->Print( 1, "{POLYVOID ID=%d X=%.10f Y=%.10f\n",
|
|
|
|
m_polyId,
|
|
|
|
iu2hyp( ph0.x ),
|
|
|
|
iu2hyp( ph0.y ) );
|
2020-06-24 02:19:08 +00:00
|
|
|
|
|
|
|
for( int v = 0; v < holeShape.PointCount(); v++ )
|
|
|
|
{
|
|
|
|
m_out->Print( 2, "(LINE X=%.10f Y=%.10f)\n",
|
2022-03-14 15:52:12 +00:00
|
|
|
iu2hyp( holeShape.CPoint( v ).x ),
|
|
|
|
iu2hyp( holeShape.CPoint( v ).y ) );
|
2020-06-24 02:19:08 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 21:03:43 +00:00
|
|
|
m_out->Print( 2, "(LINE X=%.10f Y=%.10f)\n",
|
2022-03-14 15:52:12 +00:00
|
|
|
iu2hyp( ph0.x ),
|
|
|
|
iu2hyp( ph0.y ) );
|
2020-06-24 02:19:08 +00:00
|
|
|
m_out->Print( 1, "}\n" );
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
m_polyId++;
|
2019-04-08 00:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<BOARD_ITEM*> HYPERLYNX_EXPORTER::collectNetObjects( int netcode )
|
|
|
|
{
|
|
|
|
std::vector<BOARD_ITEM*> rv;
|
|
|
|
|
2020-08-22 21:03:43 +00:00
|
|
|
auto check =
|
|
|
|
[&]( BOARD_CONNECTED_ITEM* item ) -> bool
|
|
|
|
{
|
|
|
|
if( ( item->GetLayerSet() & LSET::AllCuMask() ).none() )
|
|
|
|
return false;
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2020-08-22 21:03:43 +00:00
|
|
|
if( item->GetNetCode() == netcode || ( netcode < 0 && item->GetNetCode() <= 0 ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
if( check( pad ) )
|
|
|
|
rv.push_back( pad );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* item : m_board->Tracks() )
|
2020-08-22 21:03:43 +00:00
|
|
|
{
|
2019-04-08 00:09:07 +00:00
|
|
|
if( check( item ) )
|
|
|
|
rv.push_back( item );
|
2020-08-22 21:03:43 +00:00
|
|
|
}
|
2019-04-08 00:09:07 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_board->Zones() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
if( check( zone ) )
|
|
|
|
rv.push_back( zone );
|
|
|
|
}
|
2020-08-22 21:03:43 +00:00
|
|
|
|
2019-04-08 00:09:07 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HYPERLYNX_EXPORTER::writeNets()
|
|
|
|
{
|
|
|
|
m_polyId = 1;
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
for( const NETINFO_ITEM* netInfo : m_board->GetNetInfo() )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
2022-05-27 23:09:47 +00:00
|
|
|
int netcode = netInfo->GetNetCode();
|
2020-12-08 13:02:08 +00:00
|
|
|
bool isNullNet = netInfo->GetNetCode() <= 0 || netInfo->GetNetname().IsEmpty();
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
if( isNullNet )
|
|
|
|
continue;
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
const std::vector<BOARD_ITEM*> netObjects = collectNetObjects( netcode );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
if( netObjects.size() )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "{NET=\"%s\"\n", (const char*) netInfo->GetNetname().c_str() );
|
|
|
|
writeNetObjects( netObjects );
|
|
|
|
m_out->Print( 0, "}\n\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
const std::vector<BOARD_ITEM*> nullNetObjects = collectNetObjects( -1 );
|
2019-04-08 00:09:07 +00:00
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
|
2022-05-27 23:09:47 +00:00
|
|
|
for( BOARD_ITEM* item : nullNetObjects )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, "{NET=\"EmptyNet%d\"\n", idx );
|
|
|
|
writeNetObjects( { item } );
|
|
|
|
m_out->Print( 0, "}\n\n" );
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HYPERLYNX_EXPORTER::Run()
|
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_out.reset( new FILE_OUTPUTFORMATTER( m_outputFilePath.GetFullPath() ) );
|
|
|
|
|
|
|
|
generateHeaders();
|
|
|
|
writeBoardInfo();
|
|
|
|
writeStackupInfo();
|
|
|
|
writeDevices();
|
|
|
|
writePadStacks();
|
|
|
|
writeNets();
|
|
|
|
}
|
2020-02-29 21:53:51 +00:00
|
|
|
catch( IO_ERROR& )
|
2019-04-08 00:09:07 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ExportBoardToHyperlynx( BOARD* aBoard, const wxFileName& aPath )
|
|
|
|
{
|
|
|
|
HYPERLYNX_EXPORTER exporter;
|
|
|
|
exporter.SetBoard( aBoard );
|
|
|
|
exporter.SetOutputFilename( aPath );
|
|
|
|
return exporter.Run();
|
|
|
|
}
|