2020-04-03 23:22:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019-2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
|
2024-01-07 11:56:37 +00:00
|
|
|
* Copyright (C) 2021-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-04-03 23:22:24 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "altium_pcb.h"
|
|
|
|
#include "altium_parser_pcb.h"
|
2024-02-04 17:14:19 +00:00
|
|
|
#include <io/altium/altium_binary_parser.h>
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <io/altium/altium_parser_utils.h>
|
2020-04-03 23:22:24 +00:00
|
|
|
|
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-06-11 16:59:28 +00:00
|
|
|
#include <pcb_dimension.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
|
|
|
#include <pcb_text.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2023-09-07 11:22:10 +00:00
|
|
|
#include <core/profile.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <zone.h>
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
#include <board_stackup_manager/stackup_predefined_prms.h>
|
|
|
|
|
|
|
|
#include <compoundfilereader.h>
|
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2023-07-21 00:08:03 +00:00
|
|
|
#include <font/outline_font.h>
|
2020-04-21 13:34:06 +00:00
|
|
|
#include <project.h>
|
2024-05-01 01:21:48 +00:00
|
|
|
#include <reporter.h>
|
2020-04-03 23:22:24 +00:00
|
|
|
#include <trigo.h>
|
|
|
|
#include <utf.h>
|
2020-04-21 13:34:06 +00:00
|
|
|
#include <wx/docview.h>
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
2020-04-21 13:34:06 +00:00
|
|
|
#include <wx/mstream.h>
|
|
|
|
#include <wx/wfstream.h>
|
|
|
|
#include <wx/zstream.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2023-06-16 00:41:56 +00:00
|
|
|
#include <magic_enum.hpp>
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
|
2021-07-24 19:23:59 +00:00
|
|
|
constexpr double BOLD_FACTOR = 1.75; // CSS font-weight-normal is 400; bold is 700
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
bool IsAltiumLayerCopper( ALTIUM_LAYER aLayer )
|
|
|
|
{
|
2022-01-17 18:49:06 +00:00
|
|
|
return ( aLayer >= ALTIUM_LAYER::TOP_LAYER && aLayer <= ALTIUM_LAYER::BOTTOM_LAYER )
|
|
|
|
|| aLayer == ALTIUM_LAYER::MULTI_LAYER; // TODO: add IsAltiumLayerAPlane?
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
bool IsAltiumLayerAPlane( ALTIUM_LAYER aLayer )
|
|
|
|
{
|
|
|
|
return aLayer >= ALTIUM_LAYER::INTERNAL_PLANE_1 && aLayer <= ALTIUM_LAYER::INTERNAL_PLANE_16;
|
|
|
|
}
|
|
|
|
|
2022-01-10 16:45:37 +00:00
|
|
|
FOOTPRINT* ALTIUM_PCB::HelperGetFootprint( uint16_t aComponent ) const
|
|
|
|
{
|
|
|
|
if( aComponent == ALTIUM_COMPONENT_NONE || m_components.size() <= aComponent )
|
|
|
|
{
|
2024-01-07 11:56:37 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( wxT( "Component creator tries to access component id %u "
|
|
|
|
"of %u existing components" ),
|
|
|
|
(unsigned)aComponent, (unsigned)m_components.size() ) );
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_components.at( aComponent );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2021-07-24 13:23:55 +00:00
|
|
|
void HelperShapeLineChainFromAltiumVertices( SHAPE_LINE_CHAIN& aLine,
|
|
|
|
const std::vector<ALTIUM_VERTICE>& aVertices )
|
2020-10-22 11:21:47 +00:00
|
|
|
{
|
2021-07-17 18:52:13 +00:00
|
|
|
for( const ALTIUM_VERTICE& vertex : aVertices )
|
2020-10-22 11:21:47 +00:00
|
|
|
{
|
2021-07-17 18:52:13 +00:00
|
|
|
if( vertex.isRound )
|
2020-10-22 11:21:47 +00:00
|
|
|
{
|
2022-01-14 15:34:41 +00:00
|
|
|
EDA_ANGLE angle( vertex.endangle - vertex.startangle, DEGREES_T );
|
|
|
|
angle.Normalize();
|
2020-10-22 11:21:47 +00:00
|
|
|
|
2021-07-17 18:52:13 +00:00
|
|
|
double startradiant = DEG2RAD( vertex.startangle );
|
|
|
|
double endradiant = DEG2RAD( vertex.endangle );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I arcStartOffset = VECTOR2I( KiROUND( std::cos( startradiant ) * vertex.radius ),
|
2021-07-17 18:52:13 +00:00
|
|
|
-KiROUND( std::sin( startradiant ) * vertex.radius ) );
|
2020-10-22 11:21:47 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I arcEndOffset = VECTOR2I( KiROUND( std::cos( endradiant ) * vertex.radius ),
|
2021-07-17 18:52:13 +00:00
|
|
|
-KiROUND( std::sin( endradiant ) * vertex.radius ) );
|
2020-10-22 11:21:47 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I arcStart = vertex.center + arcStartOffset;
|
|
|
|
VECTOR2I arcEnd = vertex.center + arcEndOffset;
|
2020-10-22 11:21:47 +00:00
|
|
|
|
2021-07-17 18:52:13 +00:00
|
|
|
if( GetLineLength( arcStart, vertex.position )
|
|
|
|
< GetLineLength( arcEnd, vertex.position ) )
|
2020-10-22 11:21:47 +00:00
|
|
|
{
|
2021-07-17 18:52:13 +00:00
|
|
|
aLine.Append( SHAPE_ARC( vertex.center, arcStart, -angle ) );
|
2020-10-22 11:21:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-17 18:52:13 +00:00
|
|
|
aLine.Append( SHAPE_ARC( vertex.center, arcEnd, angle ) );
|
2020-10-22 11:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-17 18:52:13 +00:00
|
|
|
aLine.Append( vertex.position );
|
2020-10-22 11:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-22 11:44:25 +00:00
|
|
|
aLine.SetClosed( true );
|
2020-10-22 11:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
PCB_LAYER_ID ALTIUM_PCB::GetKicadLayer( ALTIUM_LAYER aAltiumLayer ) const
|
|
|
|
{
|
|
|
|
auto override = m_layermap.find( aAltiumLayer );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( override != m_layermap.end() )
|
|
|
|
{
|
|
|
|
return override->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( aAltiumLayer )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case ALTIUM_LAYER::UNKNOWN: return UNDEFINED_LAYER;
|
|
|
|
|
|
|
|
case ALTIUM_LAYER::TOP_LAYER: return F_Cu;
|
2021-01-31 10:14:33 +00:00
|
|
|
case ALTIUM_LAYER::MID_LAYER_1: return In1_Cu;
|
2020-10-04 14:19:33 +00:00
|
|
|
case ALTIUM_LAYER::MID_LAYER_2: return In2_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_3: return In3_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_4: return In4_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_5: return In5_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_6: return In6_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_7: return In7_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_8: return In8_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_9: return In9_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_10: return In10_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_11: return In11_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_12: return In12_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_13: return In13_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_14: return In14_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_15: return In15_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_16: return In16_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_17: return In17_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_18: return In18_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_19: return In19_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_20: return In20_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_21: return In21_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_22: return In22_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_23: return In23_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_24: return In24_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_25: return In25_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_26: return In26_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_27: return In27_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_28: return In28_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_29: return In29_Cu;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_30: return In30_Cu;
|
|
|
|
case ALTIUM_LAYER::BOTTOM_LAYER: return B_Cu;
|
|
|
|
|
|
|
|
case ALTIUM_LAYER::TOP_OVERLAY: return F_SilkS;
|
|
|
|
case ALTIUM_LAYER::BOTTOM_OVERLAY: return B_SilkS;
|
|
|
|
case ALTIUM_LAYER::TOP_PASTE: return F_Paste;
|
|
|
|
case ALTIUM_LAYER::BOTTOM_PASTE: return B_Paste;
|
|
|
|
case ALTIUM_LAYER::TOP_SOLDER: return F_Mask;
|
|
|
|
case ALTIUM_LAYER::BOTTOM_SOLDER: return B_Mask;
|
|
|
|
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_1: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_2: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_3: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_4: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_5: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_6: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_7: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_8: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_9: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_10: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_11: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_12: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_13: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_14: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_15: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::INTERNAL_PLANE_16: return UNDEFINED_LAYER;
|
|
|
|
|
|
|
|
case ALTIUM_LAYER::DRILL_GUIDE: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::KEEP_OUT_LAYER: return Margin;
|
|
|
|
|
2021-01-31 10:14:33 +00:00
|
|
|
case ALTIUM_LAYER::MECHANICAL_1: return User_1; //Edge_Cuts;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_2: return User_2;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_3: return User_3;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_4: return User_4;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_5: return User_5;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_6: return User_6;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_7: return User_7;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_8: return User_8;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_9: return User_9;
|
2020-10-04 14:19:33 +00:00
|
|
|
case ALTIUM_LAYER::MECHANICAL_10: return Dwgs_User;
|
2021-10-22 19:29:53 +00:00
|
|
|
case ALTIUM_LAYER::MECHANICAL_11: return Eco2_User; //Eco1 is used for unknown elements
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_12: return F_Fab;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_13: return B_Fab; // Don't use courtyard layers for other purposes
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_14: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_15: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_16: return UNDEFINED_LAYER;
|
2020-10-04 14:19:33 +00:00
|
|
|
|
|
|
|
case ALTIUM_LAYER::DRILL_DRAWING: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MULTI_LAYER: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::CONNECTIONS: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::BACKGROUND: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::DRC_ERROR_MARKERS: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::SELECTIONS: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::VISIBLE_GRID_1: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::VISIBLE_GRID_2: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::PAD_HOLES: return UNDEFINED_LAYER;
|
|
|
|
case ALTIUM_LAYER::VIA_HOLES: return UNDEFINED_LAYER;
|
|
|
|
|
|
|
|
default: return UNDEFINED_LAYER;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-10 16:45:37 +00:00
|
|
|
std::vector<PCB_LAYER_ID> ALTIUM_PCB::GetKicadLayersToIterate( ALTIUM_LAYER aAltiumLayer ) const
|
|
|
|
{
|
|
|
|
static std::set<ALTIUM_LAYER> altiumLayersWithWarning;
|
|
|
|
|
2023-09-14 16:15:15 +00:00
|
|
|
if( aAltiumLayer == ALTIUM_LAYER::MULTI_LAYER || aAltiumLayer == ALTIUM_LAYER::KEEP_OUT_LAYER )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
|
|
|
std::vector<PCB_LAYER_ID> layers;
|
2023-09-14 16:15:15 +00:00
|
|
|
layers.reserve( MAX_CU_LAYERS );
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : LSET::AllCuMask().Seq() )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
2023-09-15 13:53:48 +00:00
|
|
|
if( !m_board || m_board->IsLayerEnabled( layer ) )
|
2023-09-14 16:15:15 +00:00
|
|
|
layers.emplace_back( layer );
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return layers;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aAltiumLayer );
|
|
|
|
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-05-04 15:27:52 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format(
|
|
|
|
_( "Altium layer (%d) has no KiCad equivalent. It has been moved to KiCad "
|
|
|
|
"layer Eco1_User." ), aAltiumLayer ), RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
|
2022-01-10 16:45:37 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { klayer };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-01 01:21:48 +00:00
|
|
|
ALTIUM_PCB::ALTIUM_PCB( BOARD* aBoard, PROGRESS_REPORTER* aProgressReporter, REPORTER* aReporter,
|
2024-02-19 12:24:13 +00:00
|
|
|
const wxString& aLibrary, const wxString& aFootprintName )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2024-02-19 12:24:13 +00:00
|
|
|
m_board = aBoard;
|
2021-06-26 10:49:58 +00:00
|
|
|
m_progressReporter = aProgressReporter;
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter = aReporter;
|
2021-06-26 10:49:58 +00:00
|
|
|
m_doneCount = 0;
|
|
|
|
m_lastProgressCount = 0;
|
|
|
|
m_totalCount = 0;
|
2020-05-10 17:30:03 +00:00
|
|
|
m_highest_pour_index = 0;
|
2024-02-19 12:24:13 +00:00
|
|
|
m_library = aLibrary;
|
|
|
|
m_footprintName = aFootprintName;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ALTIUM_PCB::~ALTIUM_PCB()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
void ALTIUM_PCB::checkpoint()
|
|
|
|
{
|
|
|
|
const unsigned PROGRESS_DELTA = 250;
|
|
|
|
|
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
if( ++m_doneCount > m_lastProgressCount + PROGRESS_DELTA )
|
|
|
|
{
|
|
|
|
m_progressReporter->SetCurrentProgress( ( (double) m_doneCount )
|
|
|
|
/ std::max( 1U, m_totalCount ) );
|
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( _( "Open cancelled by user." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
|
|
|
m_lastProgressCount = m_doneCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::Parse( const ALTIUM_COMPOUND_FILE& altiumPcbFile,
|
|
|
|
const std::map<ALTIUM_PCB_DIR, std::string>& aFileMapping )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
// this vector simply declares in which order which functions to call.
|
|
|
|
const std::vector<std::tuple<bool, ALTIUM_PCB_DIR, PARSE_FUNCTION_POINTER_fp>> parserOrder = {
|
|
|
|
{ true, ALTIUM_PCB_DIR::FILE_HEADER,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseFileHeader( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::BOARD6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseBoard6Data( aFile, fileHeader );
|
|
|
|
} },
|
2022-02-20 19:18:22 +00:00
|
|
|
{ false, ALTIUM_PCB_DIR::EXTENDPRIMITIVEINFORMATION,
|
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseExtendedPrimitiveInformationData( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::COMPONENTS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseComponents6Data( aFile, fileHeader );
|
|
|
|
} },
|
2024-01-14 08:59:49 +00:00
|
|
|
{ false, ALTIUM_PCB_DIR::MODELS,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this, aFileMapping]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
2022-02-19 15:45:55 +00:00
|
|
|
std::vector<std::string> dir{ aFileMapping.at( ALTIUM_PCB_DIR::MODELS ) };
|
2022-01-06 15:27:09 +00:00
|
|
|
this->ParseModelsData( aFile, fileHeader, dir );
|
|
|
|
} },
|
2020-04-21 13:34:06 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::COMPONENTBODIES6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseComponentsBodies6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::NETS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseNets6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::CLASSES6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseClasses6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::RULES6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseRules6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::DIMENSIONS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseDimensions6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::POLYGONS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParsePolygons6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::ARCS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseArcs6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::PADS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParsePads6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::VIAS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseVias6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::TRACKS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseTracks6Data( aFile, fileHeader );
|
|
|
|
} },
|
2021-11-10 16:46:01 +00:00
|
|
|
{ false, ALTIUM_PCB_DIR::WIDESTRINGS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseWideStrings6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::TEXTS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseTexts6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::FILLS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseFills6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ false, ALTIUM_PCB_DIR::BOARDREGIONS,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseBoardRegionsData( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::SHAPEBASEDREGIONS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseShapeBasedRegions6Data( aFile, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::REGIONS6,
|
2022-01-06 15:27:09 +00:00
|
|
|
[this]( const ALTIUM_COMPOUND_FILE& aFile, auto fileHeader )
|
|
|
|
{
|
|
|
|
this->ParseRegions6Data( aFile, fileHeader );
|
|
|
|
} }
|
2020-04-03 23:22:24 +00:00
|
|
|
};
|
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter != nullptr )
|
|
|
|
{
|
|
|
|
// Count number of records we will read for the progress reporter
|
|
|
|
for( const std::tuple<bool, ALTIUM_PCB_DIR, PARSE_FUNCTION_POINTER_fp>& cur : parserOrder )
|
|
|
|
{
|
|
|
|
bool isRequired;
|
|
|
|
ALTIUM_PCB_DIR directory;
|
|
|
|
PARSE_FUNCTION_POINTER_fp fp;
|
|
|
|
std::tie( isRequired, directory, fp ) = cur;
|
|
|
|
|
|
|
|
if( directory == ALTIUM_PCB_DIR::FILE_HEADER )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto& mappedDirectory = aFileMapping.find( directory );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
if( mappedDirectory == aFileMapping.end() )
|
|
|
|
continue;
|
|
|
|
|
2022-02-19 15:45:55 +00:00
|
|
|
const std::vector<std::string> mappedFile{ mappedDirectory->second, "Header" };
|
2022-01-06 15:27:09 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file = altiumPcbFile.FindStream( mappedFile );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
if( file == nullptr )
|
|
|
|
continue;
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( altiumPcbFile, file );
|
|
|
|
uint32_t numOfRecords = reader.Read<uint32_t>();
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
if( reader.HasParsingError() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( _( "'%s' was not parsed correctly." ),
|
|
|
|
FormatPath( mappedFile ) ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
m_totalCount += numOfRecords;
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( _( "'%s' was not fully parsed." ),
|
|
|
|
FormatPath( mappedFile ) ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-21 16:22:20 +00:00
|
|
|
const auto& boardDirectory = aFileMapping.find( ALTIUM_PCB_DIR::BOARD6 );
|
|
|
|
|
|
|
|
if( boardDirectory != aFileMapping.end() )
|
|
|
|
{
|
|
|
|
std::vector<std::string> mappedFile{ boardDirectory->second, "Data" };
|
|
|
|
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file = altiumPcbFile.FindStream( mappedFile );
|
|
|
|
|
|
|
|
if( !file )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( _(
|
|
|
|
"This file does not appear to be in a valid PCB Binary Version 6.0 format. In "
|
|
|
|
"Altium Designer, "
|
|
|
|
"make sure to save as \"PCB Binary Files (*.PcbDoc)\"." ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
// Parse data in specified order
|
|
|
|
for( const std::tuple<bool, ALTIUM_PCB_DIR, PARSE_FUNCTION_POINTER_fp>& cur : parserOrder )
|
|
|
|
{
|
|
|
|
bool isRequired;
|
|
|
|
ALTIUM_PCB_DIR directory;
|
|
|
|
PARSE_FUNCTION_POINTER_fp fp;
|
|
|
|
std::tie( isRequired, directory, fp ) = cur;
|
|
|
|
|
|
|
|
const auto& mappedDirectory = aFileMapping.find( directory );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( mappedDirectory == aFileMapping.end() )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxASSERT_MSG( !isRequired, wxString::Format( wxT( "Altium Directory of kind %d was "
|
|
|
|
"expected, but no mapping is "
|
|
|
|
"present in the code" ),
|
2020-11-13 15:15:52 +00:00
|
|
|
directory ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-02-19 15:45:55 +00:00
|
|
|
std::vector<std::string> mappedFile{ mappedDirectory->second };
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
if( directory != ALTIUM_PCB_DIR::FILE_HEADER )
|
2022-02-19 15:45:55 +00:00
|
|
|
mappedFile.emplace_back( "Data" );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file = altiumPcbFile.FindStream( mappedFile );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( file != nullptr )
|
2023-06-16 00:41:56 +00:00
|
|
|
{
|
2022-01-06 15:27:09 +00:00
|
|
|
fp( altiumPcbFile, file );
|
2023-06-16 00:41:56 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
else if( isRequired )
|
2023-06-16 00:41:56 +00:00
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( _( "File not found: '%s' for directory '%s'." ),
|
|
|
|
FormatPath( mappedFile ),
|
|
|
|
magic_enum::enum_name( directory ) ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2023-06-16 00:41:56 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 17:30:03 +00:00
|
|
|
// fixup zone priorities since Altium stores them in the opposite order
|
2021-07-24 13:23:55 +00:00
|
|
|
for( ZONE* zone : m_polygons )
|
2020-05-10 17:30:03 +00:00
|
|
|
{
|
|
|
|
if( !zone )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Altium "fills" - not poured in Altium
|
2022-03-01 14:53:35 +00:00
|
|
|
if( zone->GetAssignedPriority() == 1000 )
|
2020-05-10 17:30:03 +00:00
|
|
|
{
|
|
|
|
// Unlikely, but you never know
|
|
|
|
if( m_highest_pour_index >= 1000 )
|
2022-03-01 14:53:35 +00:00
|
|
|
zone->SetAssignedPriority( m_highest_pour_index + 1 );
|
2020-05-10 17:30:03 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-03-01 14:53:35 +00:00
|
|
|
int priority = m_highest_pour_index - zone->GetAssignedPriority();
|
2020-05-10 17:30:03 +00:00
|
|
|
|
2022-03-01 14:53:35 +00:00
|
|
|
zone->SetAssignedPriority( priority >= 0 ? priority : 0 );
|
2020-05-10 17:30:03 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
// change priority of outer zone to zero
|
2021-07-24 13:23:55 +00:00
|
|
|
for( std::pair<const ALTIUM_LAYER, ZONE*>& zone : m_outer_plane )
|
2022-03-01 14:53:35 +00:00
|
|
|
zone.second->SetAssignedPriority( 0 );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2023-11-25 21:23:34 +00:00
|
|
|
// Simplify and fracture zone fills in case we constructed them from tracks (hatched fill)
|
|
|
|
for( ZONE* zone : m_polygons )
|
|
|
|
{
|
|
|
|
if( !zone )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
if( !zone->HasFilledPolysForLayer( layer ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
zone->GetFilledPolysList( layer )->Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 13:23:55 +00:00
|
|
|
// Altium doesn't appear to store either the dimension value nor the dimensioned object in
|
|
|
|
// the dimension record. (Yes, there is a REFERENCE0OBJECTID, but it doesn't point to the
|
|
|
|
// dimensioned object.) We attempt to plug this gap by finding a colocated arc or circle
|
|
|
|
// and using its radius. If there are more than one such arcs/circles, well, :shrug:.
|
2021-07-24 19:05:34 +00:00
|
|
|
for( PCB_DIM_RADIAL* dim : m_radialDimensions )
|
2021-07-24 13:23:55 +00:00
|
|
|
{
|
|
|
|
int radius = 0;
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : m_board->Drawings() )
|
|
|
|
{
|
|
|
|
if( item->Type() != PCB_SHAPE_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
|
|
|
|
|
|
|
|
if( shape->GetShape() != SHAPE_T::ARC && shape->GetShape() != SHAPE_T::CIRCLE )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( shape->GetPosition() == dim->GetPosition() )
|
|
|
|
{
|
|
|
|
radius = shape->GetRadius();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( radius == 0 )
|
|
|
|
{
|
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
|
|
|
{
|
|
|
|
if( track->Type() != PCB_ARC_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PCB_ARC* arc = static_cast<PCB_ARC*>( track );
|
|
|
|
|
|
|
|
if( arc->GetCenter() == dim->GetPosition() )
|
|
|
|
{
|
|
|
|
radius = arc->GetRadius();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 19:05:34 +00:00
|
|
|
// Move the radius point onto the circumference
|
2021-07-24 13:23:55 +00:00
|
|
|
VECTOR2I radialLine = dim->GetEnd() - dim->GetStart();
|
2021-07-24 19:05:34 +00:00
|
|
|
int totalLength = radialLine.EuclideanNorm();
|
|
|
|
|
|
|
|
// Enforce a minimum on the radialLine else we won't have enough precision to get the
|
|
|
|
// angle from it.
|
|
|
|
radialLine = radialLine.Resize( std::max( radius, 2 ) );
|
2022-01-01 06:04:08 +00:00
|
|
|
dim->SetEnd( dim->GetStart() + (VECTOR2I) radialLine );
|
2021-07-24 19:05:34 +00:00
|
|
|
dim->SetLeaderLength( totalLength - radius );
|
|
|
|
dim->Update();
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 15:54:08 +00:00
|
|
|
// center board
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbbox = m_board->GetBoardEdgesBoundingBox();
|
2021-01-30 15:54:08 +00:00
|
|
|
|
2022-09-16 23:25:07 +00:00
|
|
|
int w = m_board->GetPageSettings().GetWidthIU( pcbIUScale.IU_PER_MILS );
|
|
|
|
int h = m_board->GetPageSettings().GetHeightIU( pcbIUScale.IU_PER_MILS );
|
2021-01-30 15:54:08 +00:00
|
|
|
|
|
|
|
int desired_x = ( w - bbbox.GetWidth() ) / 2;
|
|
|
|
int desired_y = ( h - bbbox.GetHeight() ) / 2;
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I movementVector( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() );
|
2021-01-30 15:54:08 +00:00
|
|
|
m_board->Move( movementVector );
|
2021-11-09 03:36:40 +00:00
|
|
|
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
bds.SetAuxOrigin( bds.GetAuxOrigin() + movementVector );
|
|
|
|
bds.SetGridOrigin( bds.GetGridOrigin() + movementVector );
|
2021-01-30 15:54:08 +00:00
|
|
|
|
2020-04-21 13:34:06 +00:00
|
|
|
m_board->SetModified();
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-19 15:45:55 +00:00
|
|
|
|
2023-08-31 16:16:35 +00:00
|
|
|
FOOTPRINT* ALTIUM_PCB::ParseFootprint( ALTIUM_COMPOUND_FILE& altiumLibFile,
|
2022-01-10 13:31:23 +00:00
|
|
|
const wxString& aFootprintName )
|
|
|
|
{
|
2022-01-10 16:45:37 +00:00
|
|
|
std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( m_board );
|
|
|
|
|
|
|
|
// TODO: what should we do with those layers?
|
|
|
|
m_layermap.emplace( ALTIUM_LAYER::MECHANICAL_14, Eco2_User );
|
|
|
|
m_layermap.emplace( ALTIUM_LAYER::MECHANICAL_15, Eco2_User );
|
|
|
|
m_layermap.emplace( ALTIUM_LAYER::MECHANICAL_16, Eco2_User );
|
|
|
|
|
|
|
|
m_unicodeStrings.clear();
|
2022-02-20 19:18:22 +00:00
|
|
|
m_extendedPrimitiveInformationMaps.clear();
|
2023-07-22 03:55:49 +00:00
|
|
|
|
2022-01-10 16:45:37 +00:00
|
|
|
// TODO: WideStrings are stored as parameterMap in the case of footprints, not as binary
|
|
|
|
// std::string unicodeStringsStreamName = aFootprintName.ToStdString() + "\\WideStrings";
|
|
|
|
// const CFB::COMPOUND_FILE_ENTRY* unicodeStringsData = altiumLibFile.FindStream( unicodeStringsStreamName );
|
|
|
|
// if( unicodeStringsData != nullptr )
|
|
|
|
// {
|
|
|
|
// ParseWideStrings6Data( altiumLibFile, unicodeStringsData );
|
|
|
|
// }
|
2022-01-10 13:31:23 +00:00
|
|
|
|
2023-08-18 20:42:39 +00:00
|
|
|
std::tuple<wxString, const CFB::COMPOUND_FILE_ENTRY*> ret = altiumLibFile.FindLibFootprintDirName(aFootprintName);
|
|
|
|
|
|
|
|
wxString fpDirName = std::get<0>( ret );
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* footprintStream = std::get<1>( ret );
|
2023-07-22 03:55:49 +00:00
|
|
|
|
|
|
|
if( fpDirName.IsEmpty() )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR(
|
|
|
|
wxString::Format( _( "Footprint directory not found: '%s'." ), aFootprintName ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::string> streamName{ fpDirName.ToStdString(), "Data" };
|
2023-08-18 20:42:39 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* footprintData = altiumLibFile.FindStream( footprintStream, { "Data" } );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-10 13:31:23 +00:00
|
|
|
if( footprintData == nullptr )
|
|
|
|
{
|
2022-03-22 10:23:29 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "File not found: '%s'." ),
|
|
|
|
FormatPath( streamName ) ) );
|
2022-01-10 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER parser( altiumLibFile, footprintData );
|
2022-01-10 13:31:23 +00:00
|
|
|
|
|
|
|
parser.ReadAndSetSubrecordLength();
|
2023-07-22 03:55:49 +00:00
|
|
|
//wxString footprintName = parser.ReadWxString(); // Not used (single-byte char set)
|
2022-01-10 13:31:23 +00:00
|
|
|
parser.SkipSubrecord();
|
|
|
|
|
2023-07-22 03:55:49 +00:00
|
|
|
LIB_ID fpID = AltiumToKiCadLibID( "", aFootprintName ); // TODO: library name
|
2022-01-10 13:31:23 +00:00
|
|
|
footprint->SetFPID( fpID );
|
|
|
|
|
2023-07-22 03:55:49 +00:00
|
|
|
const std::vector<std::string> parametersStreamName{ fpDirName.ToStdString(),
|
2022-02-19 15:45:55 +00:00
|
|
|
"Parameters" };
|
2022-02-06 15:23:46 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* parametersData =
|
2023-08-18 20:42:39 +00:00
|
|
|
altiumLibFile.FindStream( footprintStream, { "Parameters" } );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-02-06 15:23:46 +00:00
|
|
|
if( parametersData != nullptr )
|
|
|
|
{
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER parametersReader( altiumLibFile, parametersData );
|
2022-02-06 15:23:46 +00:00
|
|
|
std::map<wxString, wxString> parameterProperties = parametersReader.ReadProperties();
|
2024-02-04 17:14:19 +00:00
|
|
|
wxString description = ALTIUM_PROPS_UTILS::ReadString( parameterProperties,
|
|
|
|
wxT( "DESCRIPTION" ), wxT( "" ) );
|
2023-06-19 17:08:18 +00:00
|
|
|
footprint->SetLibDescription( description );
|
2022-02-06 15:23:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( _( "File not found: '%s'." ),
|
|
|
|
FormatPath( parametersStreamName ) ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2023-06-19 17:08:18 +00:00
|
|
|
footprint->SetLibDescription( wxT( "" ) );
|
2022-02-06 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2022-02-19 15:45:55 +00:00
|
|
|
const std::vector<std::string> extendedPrimitiveInformationStreamName{
|
2023-08-18 20:42:39 +00:00
|
|
|
"ExtendedPrimitiveInformation", "Data"
|
2022-02-19 15:45:55 +00:00
|
|
|
};
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* extendedPrimitiveInformationData =
|
2023-08-18 20:42:39 +00:00
|
|
|
altiumLibFile.FindStream( footprintStream, extendedPrimitiveInformationStreamName );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-02-19 15:45:55 +00:00
|
|
|
if( extendedPrimitiveInformationData != nullptr )
|
2022-02-20 19:18:22 +00:00
|
|
|
ParseExtendedPrimitiveInformationData( altiumLibFile, extendedPrimitiveInformationData );
|
2022-02-19 15:45:55 +00:00
|
|
|
|
2022-02-06 15:23:46 +00:00
|
|
|
footprint->SetReference( wxT( "REF**" ) );
|
2023-07-22 03:55:49 +00:00
|
|
|
footprint->SetValue( aFootprintName );
|
2022-01-16 13:40:23 +00:00
|
|
|
footprint->Reference().SetVisible( true ); // TODO: extract visibility information
|
|
|
|
footprint->Value().SetVisible( true );
|
2022-01-10 13:31:23 +00:00
|
|
|
|
2023-07-22 03:55:49 +00:00
|
|
|
const VECTOR2I defaultTextSize( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) );
|
|
|
|
const int defaultTextThickness( pcbIUScale.mmToIU( 0.15 ) );
|
|
|
|
|
|
|
|
for( PCB_FIELD* field : footprint->Fields() )
|
|
|
|
{
|
|
|
|
field->SetTextSize( defaultTextSize );
|
|
|
|
field->SetTextThickness( defaultTextThickness );
|
|
|
|
}
|
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
for( int primitiveIndex = 0; parser.GetRemainingBytes() >= 4; primitiveIndex++ )
|
2022-01-10 13:31:23 +00:00
|
|
|
{
|
|
|
|
ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( parser.Peek<uint8_t>() );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-10 13:31:23 +00:00
|
|
|
switch( recordtype )
|
|
|
|
{
|
|
|
|
case ALTIUM_RECORD::ARC:
|
|
|
|
{
|
|
|
|
AARC6 arc( parser );
|
2022-02-20 19:18:22 +00:00
|
|
|
ConvertArcs6ToFootprintItem( footprint.get(), arc, primitiveIndex, false );
|
2022-01-10 13:31:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ALTIUM_RECORD::PAD:
|
|
|
|
{
|
|
|
|
APAD6 pad( parser );
|
2022-01-16 14:37:25 +00:00
|
|
|
ConvertPads6ToFootprintItem( footprint.get(), pad );
|
2022-01-10 13:31:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ALTIUM_RECORD::VIA:
|
|
|
|
{
|
|
|
|
AVIA6 via( parser );
|
2022-01-16 14:37:25 +00:00
|
|
|
// TODO: implement
|
2022-01-10 13:31:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ALTIUM_RECORD::TRACK:
|
|
|
|
{
|
|
|
|
ATRACK6 track( parser );
|
2022-02-20 19:18:22 +00:00
|
|
|
ConvertTracks6ToFootprintItem( footprint.get(), track, primitiveIndex, false );
|
2022-01-10 13:31:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ALTIUM_RECORD::TEXT:
|
|
|
|
{
|
2022-01-10 16:45:37 +00:00
|
|
|
ATEXT6 text( parser, m_unicodeStrings );
|
2022-01-16 13:40:23 +00:00
|
|
|
ConvertTexts6ToFootprintItem( footprint.get(), text );
|
2022-01-10 13:31:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ALTIUM_RECORD::FILL:
|
|
|
|
{
|
|
|
|
AFILL6 fill( parser );
|
2022-01-17 18:49:06 +00:00
|
|
|
ConvertFills6ToFootprintItem( footprint.get(), fill, false );
|
2022-01-10 13:31:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ALTIUM_RECORD::REGION:
|
|
|
|
{
|
2022-01-25 20:53:42 +00:00
|
|
|
AREGION6 region( parser, false );
|
2023-07-21 15:02:59 +00:00
|
|
|
ConvertShapeBasedRegions6ToFootprintItem( footprint.get(), region, primitiveIndex );
|
2022-01-10 13:31:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ALTIUM_RECORD::MODEL:
|
|
|
|
{
|
|
|
|
ACOMPONENTBODY6 componentBody( parser );
|
2022-01-16 14:37:25 +00:00
|
|
|
// Won't be supported for now, as we would need to extract the model
|
2022-01-10 13:31:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Record of unknown type: '%d'." ), recordtype ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-22 03:55:49 +00:00
|
|
|
// Auto-position reference and value
|
2023-07-29 05:18:13 +00:00
|
|
|
footprint->AutoPositionFields();
|
2023-07-22 03:55:49 +00:00
|
|
|
|
2022-01-10 13:31:23 +00:00
|
|
|
if( parser.HasParsingError() )
|
|
|
|
{
|
2022-02-19 15:45:55 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( wxT( "%s stream was not parsed correctly" ),
|
|
|
|
FormatPath( streamName ) ) );
|
2022-01-10 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( parser.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2022-02-19 15:45:55 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( wxT( "%s stream is not fully parsed" ),
|
|
|
|
FormatPath( streamName ) ) );
|
2022-01-10 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return footprint.release();
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
int ALTIUM_PCB::GetNetCode( uint16_t aId ) const
|
|
|
|
{
|
|
|
|
if( aId == ALTIUM_NET_UNCONNECTED )
|
|
|
|
{
|
|
|
|
return NETINFO_LIST::UNCONNECTED;
|
|
|
|
}
|
2022-11-19 11:50:54 +00:00
|
|
|
else if( m_altiumToKicadNetcodes.size() < aId )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( wxT( "Netcode with id %d does not exist. Only %d nets "
|
|
|
|
"are known" ),
|
2022-11-19 11:50:54 +00:00
|
|
|
aId, m_altiumToKicadNetcodes.size() ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-19 11:50:54 +00:00
|
|
|
return m_altiumToKicadNetcodes[ aId ];
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ARULE6* ALTIUM_PCB::GetRule( ALTIUM_RULE_KIND aKind, const wxString& aName ) const
|
|
|
|
{
|
|
|
|
const auto rules = m_rules.find( aKind );
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( rules == m_rules.end() )
|
|
|
|
return nullptr;
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
for( const ARULE6& rule : rules->second )
|
|
|
|
{
|
|
|
|
if( rule.name == aName )
|
|
|
|
return &rule;
|
|
|
|
}
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ARULE6* ALTIUM_PCB::GetRuleDefault( ALTIUM_RULE_KIND aKind ) const
|
|
|
|
{
|
|
|
|
const auto rules = m_rules.find( aKind );
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( rules == m_rules.end() )
|
|
|
|
return nullptr;
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
for( const ARULE6& rule : rules->second )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
if( rule.scope1expr == wxT( "All" ) && rule.scope2expr == wxT( "All" ) )
|
2020-04-03 23:22:24 +00:00
|
|
|
return &rule;
|
|
|
|
}
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
reader.ReadAndSetSubrecordLength();
|
|
|
|
wxString header = reader.ReadWxString();
|
|
|
|
|
|
|
|
//std::cout << "HEADER: " << header << std::endl; // tells me: PCB 5.0 Binary File
|
|
|
|
|
|
|
|
//reader.SkipSubrecord();
|
|
|
|
|
|
|
|
// TODO: does not seem to work all the time at the moment
|
|
|
|
//if( reader.GetRemainingBytes() != 0 )
|
2020-04-05 09:22:40 +00:00
|
|
|
// THROW_IO_ERROR( "FileHeader stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2024-05-01 01:21:48 +00:00
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
void ALTIUM_PCB::ParseExtendedPrimitiveInformationData( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
|
|
|
{
|
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->Report( _( "Loading extended primitive information data..." ) );
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2022-02-20 19:18:22 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
checkpoint();
|
|
|
|
AEXTENDED_PRIMITIVE_INFORMATION elem( reader );
|
|
|
|
|
|
|
|
m_extendedPrimitiveInformationMaps[elem.primitiveObjectId].emplace( elem.primitiveIndex,
|
|
|
|
std::move( elem ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
THROW_IO_ERROR( wxT( "ExtendedPrimitiveInformation stream is not fully parsed" ) );
|
|
|
|
}
|
|
|
|
|
2024-05-01 01:21:48 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseBoard6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2022-02-05 02:06:25 +00:00
|
|
|
m_progressReporter->Report( _( "Loading board data..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
ABOARD6 elem( reader );
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Board6 stream is not fully parsed" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2021-11-09 03:36:40 +00:00
|
|
|
m_board->GetDesignSettings().SetAuxOrigin( elem.sheetpos );
|
|
|
|
m_board->GetDesignSettings().SetGridOrigin( elem.sheetpos );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
// read layercount from stackup, because LAYERSETSCOUNT is not always correct?!
|
|
|
|
size_t layercount = 0;
|
2022-11-19 11:53:11 +00:00
|
|
|
size_t layerid = static_cast<size_t>( ALTIUM_LAYER::TOP_LAYER );
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2022-11-19 11:53:11 +00:00
|
|
|
while( layerid < elem.stackup.size() && layerid != 0 )
|
2021-07-24 19:05:34 +00:00
|
|
|
{
|
2022-11-19 11:53:11 +00:00
|
|
|
layerid = elem.stackup[ layerid - 1 ].nextId;
|
2021-07-24 19:05:34 +00:00
|
|
|
layercount++;
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:01:02 +00:00
|
|
|
size_t kicadLayercount = ( layercount % 2 == 0 ) ? layercount : layercount + 1;
|
2020-04-15 13:18:51 +00:00
|
|
|
m_board->SetCopperLayerCount( kicadLayercount );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
|
|
|
|
BOARD_STACKUP& stackup = designSettings.GetStackupDescriptor();
|
|
|
|
|
|
|
|
// create board stackup
|
|
|
|
stackup.RemoveAll(); // Just to be sure
|
|
|
|
stackup.BuildDefaultStackupList( &designSettings, layercount );
|
|
|
|
|
|
|
|
auto it = stackup.GetList().begin();
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
// find first copper layer
|
|
|
|
for( ; it != stackup.GetList().end() && ( *it )->GetType() != BS_ITEM_TYPE_COPPER; ++it )
|
|
|
|
;
|
|
|
|
|
|
|
|
auto curLayer = static_cast<int>( F_Cu );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-19 12:49:19 +00:00
|
|
|
for( size_t altiumLayerId = static_cast<size_t>( ALTIUM_LAYER::TOP_LAYER );
|
|
|
|
altiumLayerId < elem.stackup.size() && altiumLayerId != 0;
|
|
|
|
altiumLayerId = elem.stackup[altiumLayerId - 1].nextId )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2020-04-19 12:49:19 +00:00
|
|
|
// array starts with 0, but stackup with 1
|
|
|
|
ABOARD6_LAYER_STACKUP& layer = elem.stackup.at( altiumLayerId - 1 );
|
2020-04-15 13:18:51 +00:00
|
|
|
|
2020-04-15 14:01:02 +00:00
|
|
|
// handle unused layer in case of odd layercount
|
|
|
|
if( layer.nextId == 0 && layercount != kicadLayercount )
|
2020-04-15 13:18:51 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
m_board->SetLayerName( ( *it )->GetBrdLayerId(), wxT( "[unused]" ) );
|
2020-04-15 14:01:02 +00:00
|
|
|
|
2020-04-15 13:18:51 +00:00
|
|
|
if( ( *it )->GetType() != BS_ITEM_TYPE_COPPER )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Board6 stream, unexpected item while parsing stackup" ) );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-15 13:18:51 +00:00
|
|
|
( *it )->SetThickness( 0 );
|
|
|
|
|
|
|
|
++it;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-15 13:18:51 +00:00
|
|
|
if( ( *it )->GetType() != BS_ITEM_TYPE_DIELECTRIC )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Board6 stream, unexpected item while parsing stackup" ) );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-15 13:18:51 +00:00
|
|
|
( *it )->SetThickness( 0, 0 );
|
2020-04-15 14:01:02 +00:00
|
|
|
( *it )->SetThicknessLocked( true, 0 );
|
2020-04-15 13:18:51 +00:00
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2020-04-19 12:49:19 +00:00
|
|
|
m_layermap.insert( { static_cast<ALTIUM_LAYER>( altiumLayerId ),
|
|
|
|
static_cast<PCB_LAYER_ID>( curLayer++ ) } );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
if( ( *it )->GetType() != BS_ITEM_TYPE_COPPER )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Board6 stream, unexpected item while parsing stackup" ) );
|
2021-10-22 19:29:53 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
( *it )->SetThickness( layer.copperthick );
|
|
|
|
|
2020-04-19 12:49:19 +00:00
|
|
|
ALTIUM_LAYER alayer = static_cast<ALTIUM_LAYER>( altiumLayerId );
|
|
|
|
PCB_LAYER_ID klayer = ( *it )->GetBrdLayerId();
|
|
|
|
|
|
|
|
m_board->SetLayerName( klayer, layer.name );
|
|
|
|
|
|
|
|
if( layer.copperthick == 0 )
|
|
|
|
m_board->SetLayerType( klayer, LAYER_T::LT_JUMPER ); // used for things like wirebonding
|
|
|
|
else if( IsAltiumLayerAPlane( alayer ) )
|
|
|
|
m_board->SetLayerType( klayer, LAYER_T::LT_POWER );
|
2020-04-15 14:01:02 +00:00
|
|
|
|
2020-04-19 12:49:19 +00:00
|
|
|
if( klayer == B_Cu )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
if( layer.nextId != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Board6 stream, unexpected id while parsing last stackup layer" ) );
|
2021-10-22 19:29:53 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
// overwrite entry from internal -> bottom
|
2020-04-19 12:49:19 +00:00
|
|
|
m_layermap[alayer] = B_Cu;
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
2021-10-22 19:29:53 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( ( *it )->GetType() != BS_ITEM_TYPE_DIELECTRIC )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Board6 stream, unexpected item while parsing stackup" ) );
|
2021-10-22 19:29:53 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
( *it )->SetThickness( layer.dielectricthick, 0 );
|
|
|
|
( *it )->SetMaterial( layer.dielectricmaterial.empty() ?
|
2022-03-22 10:23:29 +00:00
|
|
|
NotSpecifiedPrm() :
|
|
|
|
wxString( layer.dielectricmaterial ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
( *it )->SetEpsilonR( layer.dielectricconst, 0 );
|
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2021-01-31 10:14:33 +00:00
|
|
|
// Set name of all non-cu layers
|
|
|
|
for( size_t altiumLayerId = static_cast<size_t>( ALTIUM_LAYER::TOP_OVERLAY );
|
|
|
|
altiumLayerId <= static_cast<size_t>( ALTIUM_LAYER::BOTTOM_SOLDER ); altiumLayerId++ )
|
|
|
|
{
|
|
|
|
// array starts with 0, but stackup with 1
|
|
|
|
ABOARD6_LAYER_STACKUP& layer = elem.stackup.at( altiumLayerId - 1 );
|
|
|
|
|
|
|
|
ALTIUM_LAYER alayer = static_cast<ALTIUM_LAYER>( altiumLayerId );
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( alayer );
|
|
|
|
|
|
|
|
m_board->SetLayerName( klayer, layer.name );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( size_t altiumLayerId = static_cast<size_t>( ALTIUM_LAYER::MECHANICAL_1 );
|
|
|
|
altiumLayerId <= static_cast<size_t>( ALTIUM_LAYER::MECHANICAL_16 ); altiumLayerId++ )
|
|
|
|
{
|
|
|
|
// array starts with 0, but stackup with 1
|
|
|
|
ABOARD6_LAYER_STACKUP& layer = elem.stackup.at( altiumLayerId - 1 );
|
|
|
|
|
|
|
|
ALTIUM_LAYER alayer = static_cast<ALTIUM_LAYER>( altiumLayerId );
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( alayer );
|
|
|
|
|
|
|
|
m_board->SetLayerName( klayer, layer.name );
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
HelperCreateBoardOutline( elem.board_vertices );
|
|
|
|
}
|
|
|
|
|
2024-05-01 01:21:48 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
void ALTIUM_PCB::HelperCreateBoardOutline( const std::vector<ALTIUM_VERTICE>& aVertices )
|
|
|
|
{
|
2022-01-04 18:09:10 +00:00
|
|
|
SHAPE_LINE_CHAIN lineChain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( lineChain, aVertices );
|
|
|
|
|
|
|
|
STROKE_PARAMS stroke( m_board->GetDesignSettings().GetLineThickness( Edge_Cuts ),
|
2023-11-25 13:05:45 +00:00
|
|
|
LINE_STYLE::SOLID );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-01-04 18:09:10 +00:00
|
|
|
for( int i = 0; i <= lineChain.PointCount() && i != -1; i = lineChain.NextShape( i ) )
|
|
|
|
{
|
|
|
|
if( lineChain.IsArcStart( i ) )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-04 18:09:10 +00:00
|
|
|
const SHAPE_ARC& currentArc = lineChain.Arc( lineChain.ArcIndex( i ) );
|
|
|
|
int nextShape = lineChain.NextShape( i );
|
|
|
|
bool isLastShape = nextShape < 0;
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::ARC );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetStroke( stroke );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( Edge_Cuts );
|
2022-01-04 18:09:10 +00:00
|
|
|
shape->SetArcGeometry( currentArc.GetP0(), currentArc.GetArcMid(), currentArc.GetP1() );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( shape.release(), ADD_MODE::APPEND );
|
2022-01-04 18:09:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const SEG& seg = lineChain.Segment( i );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::SEGMENT );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-04 18:09:10 +00:00
|
|
|
shape->SetStroke( stroke );
|
|
|
|
shape->SetLayer( Edge_Cuts );
|
|
|
|
shape->SetStart( seg.A );
|
|
|
|
shape->SetEnd( seg.B );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( shape.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-01 01:21:48 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseClasses6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2022-02-05 02:06:25 +00:00
|
|
|
m_progressReporter->Report( _( "Loading netclasses..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
ACLASS6 elem( reader );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.kind == ALTIUM_CLASS_KIND::NET_CLASS )
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NETCLASS> nc = std::make_shared<NETCLASS>( elem.name );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const wxString& name : elem.names )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
m_board->GetDesignSettings().m_NetSettings->m_NetClassPatternAssignments.push_back(
|
|
|
|
{
|
|
|
|
std::make_unique<EDA_COMBINED_MATCHER>( name, CTX_NETCLASS ),
|
|
|
|
nc->GetName()
|
|
|
|
} );
|
2020-10-20 09:48:27 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_board->GetDesignSettings().m_NetSettings->m_NetClasses.count( nc->GetName() ) )
|
2020-10-20 09:48:27 +00:00
|
|
|
{
|
2023-06-23 12:08:27 +00:00
|
|
|
// Name conflict, happens in some unknown circumstances
|
2020-10-20 09:48:27 +00:00
|
|
|
// unique_ptr will delete nc on this code path
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "More than one Altium netclass with name '%s' found. "
|
|
|
|
"Only the first one will be imported." ), elem.name );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-08-14 11:03:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_board->GetDesignSettings().m_NetSettings->m_NetClasses[ nc->GetName() ] = nc;
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Classes6 stream is not fully parsed" ) );
|
2020-10-20 09:48:27 +00:00
|
|
|
|
|
|
|
m_board->m_LegacyNetclassesLoaded = true;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2024-05-01 01:21:48 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseComponents6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2022-02-05 02:06:25 +00:00
|
|
|
m_progressReporter->Report( _( "Loading components..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
uint16_t componentId = 0;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
ACOMPONENT6 elem( reader );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2021-03-01 23:59:40 +00:00
|
|
|
LIB_ID fpID = AltiumToKiCadLibID( elem.sourcefootprintlibrary, elem.pattern );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetFPID( fpID );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetPosition( elem.position );
|
|
|
|
footprint->SetOrientationDegrees( elem.rotation );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
// KiCad netlisting requires parts to have non-digit + digit annotation.
|
|
|
|
// If the reference begins with a number, we prepend 'UNK' (unknown) for the source designator
|
|
|
|
wxString reference = elem.sourcedesignator;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( reference.find_first_not_of( "0123456789" ) == wxString::npos )
|
2022-02-05 02:06:25 +00:00
|
|
|
reference.Prepend( wxT( "UNK" ) );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetReference( reference );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetLocked( elem.locked );
|
|
|
|
footprint->Reference().SetVisible( elem.nameon );
|
|
|
|
footprint->Value().SetVisible( elem.commenton );
|
|
|
|
footprint->SetLayer( elem.layer == ALTIUM_LAYER::TOP_LAYER ? F_Cu : B_Cu );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_components.emplace_back( footprint.get() );
|
|
|
|
m_board->Add( footprint.release(), ADD_MODE::APPEND );
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
componentId++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Components6 stream is not fully parsed" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-16 16:15:07 +00:00
|
|
|
/// Normalize angle to be aMin < angle <= aMax angle is in degrees.
|
|
|
|
double normalizeAngleDegrees( double Angle, double aMin, double aMax )
|
|
|
|
{
|
|
|
|
while( Angle < aMin )
|
|
|
|
Angle += 360.0;
|
|
|
|
|
|
|
|
while( Angle >= aMax )
|
|
|
|
Angle -= 360.0;
|
|
|
|
|
|
|
|
return Angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseComponentsBodies6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-21 13:34:06 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2022-02-05 02:06:25 +00:00
|
|
|
m_progressReporter->Report( _( "Loading component 3D models..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-21 13:34:06 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-21 13:34:06 +00:00
|
|
|
ACOMPONENTBODY6 elem( reader ); // TODO: implement
|
|
|
|
|
|
|
|
if( elem.component == ALTIUM_COMPONENT_NONE )
|
|
|
|
continue; // TODO: we do not support components for the board yet
|
|
|
|
|
|
|
|
if( m_components.size() <= elem.component )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( wxT( "ComponentsBodies6 stream tries to access "
|
|
|
|
"component id %d of %d existing components" ),
|
|
|
|
elem.component,
|
|
|
|
m_components.size() ) );
|
2020-04-21 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !elem.modelIsEmbedded )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto modelTuple = m_models.find( elem.modelId );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2020-04-21 13:34:06 +00:00
|
|
|
if( modelTuple == m_models.end() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "ComponentsBodies6 stream tries to access model id %s which does "
|
|
|
|
"not exist" ), elem.modelId );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2022-02-19 15:45:55 +00:00
|
|
|
continue;
|
2020-04-21 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = m_components.at( elem.component );
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& fpPosition = footprint->GetPosition();
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2020-11-13 00:43:45 +00:00
|
|
|
FP_3DMODEL modelSettings;
|
2020-04-21 13:34:06 +00:00
|
|
|
|
|
|
|
modelSettings.m_Filename = modelTuple->second;
|
|
|
|
|
2022-09-16 11:33:56 +00:00
|
|
|
modelSettings.m_Offset.x = pcbIUScale.IUTomm((int) elem.modelPosition.x - fpPosition.x );
|
|
|
|
modelSettings.m_Offset.y = -pcbIUScale.IUTomm((int) elem.modelPosition.y - fpPosition.y );
|
|
|
|
modelSettings.m_Offset.z = pcbIUScale.IUTomm( (int) elem.modelPosition.z );
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
EDA_ANGLE orientation = footprint->GetOrientation();
|
2020-04-24 19:05:39 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
if( footprint->IsFlipped() )
|
2020-04-24 19:05:39 +00:00
|
|
|
{
|
2020-05-05 11:25:02 +00:00
|
|
|
modelSettings.m_Offset.y = -modelSettings.m_Offset.y;
|
|
|
|
orientation = -orientation;
|
2020-04-24 19:05:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 11:25:02 +00:00
|
|
|
RotatePoint( &modelSettings.m_Offset.x, &modelSettings.m_Offset.y, orientation );
|
|
|
|
|
2022-01-16 16:15:07 +00:00
|
|
|
modelSettings.m_Rotation.x = normalizeAngleDegrees( -elem.modelRotation.x, -180, 180 );
|
|
|
|
modelSettings.m_Rotation.y = normalizeAngleDegrees( -elem.modelRotation.y, -180, 180 );
|
|
|
|
modelSettings.m_Rotation.z = normalizeAngleDegrees( -elem.modelRotation.z
|
|
|
|
+ elem.rotation
|
|
|
|
+ orientation.AsDegrees(),
|
|
|
|
-180, 180 );
|
2020-05-05 11:25:02 +00:00
|
|
|
modelSettings.m_Opacity = elem.bodyOpacity;
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Models().push_back( modelSettings );
|
2020-04-21 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "ComponentsBodies6 stream is not fully parsed" ) );
|
2020-04-21 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
void ALTIUM_PCB::HelperParseDimensions6Linear( const ADIMENSION6& aElem )
|
|
|
|
{
|
|
|
|
if( aElem.referencePoint.size() != 2 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Incorrect number of reference points for linear dimension object" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-05-04 15:27:52 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format(
|
|
|
|
_( "Dimension found on an Altium layer (%d) with no KiCad equivalent. "
|
|
|
|
"It has been moved to KiCad layer Eco1_User." ), aElem.layer ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I referencePoint0 = aElem.referencePoint.at( 0 );
|
|
|
|
VECTOR2I referencePoint1 = aElem.referencePoint.at( 1 );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_DIM_ALIGNED> dimension = std::make_unique<PCB_DIM_ALIGNED>( m_board, PCB_DIM_ALIGNED_T );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2023-03-05 13:27:22 +00:00
|
|
|
dimension->SetPrecision( static_cast<DIM_PRECISION>( aElem.textprecision ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
dimension->SetLayer( klayer );
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetStart( referencePoint0 );
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( referencePoint0 != aElem.xy1 )
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Basically REFERENCE0POINT and REFERENCE1POINT are the two end points of the dimension.
|
2021-07-24 13:23:55 +00:00
|
|
|
* XY1 is the position of the arrow above REFERENCE0POINT. those three points are not
|
|
|
|
* necessarily in 90degree angle, but KiCad requires this to show the correct measurements.
|
2020-04-03 23:22:24 +00:00
|
|
|
*
|
2021-07-24 13:23:55 +00:00
|
|
|
* Therefore, we take the vector of REFERENCE0POINT -> XY1, calculate the normal, and
|
|
|
|
* intersect it with REFERENCE1POINT pointing the same direction as REFERENCE0POINT -> XY1.
|
|
|
|
* This should give us a valid measurement point where we can place the drawsegment.
|
2020-04-03 23:22:24 +00:00
|
|
|
*/
|
2023-06-02 17:25:31 +00:00
|
|
|
VECTOR2I direction = aElem.xy1 - referencePoint0;
|
|
|
|
VECTOR2I directionNormalVector = VECTOR2I( -direction.y, direction.x );
|
|
|
|
SEG segm1( referencePoint0, referencePoint0 + directionNormalVector );
|
|
|
|
SEG segm2( referencePoint1, referencePoint1 + direction );
|
2022-08-30 20:58:43 +00:00
|
|
|
OPT_VECTOR2I intersection( segm1.Intersect( segm2, true, true ) );
|
|
|
|
|
|
|
|
if( !intersection )
|
|
|
|
THROW_IO_ERROR( wxT( "Invalid dimension. This should never happen." ) );
|
|
|
|
|
|
|
|
dimension->SetEnd( *intersection );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
int height = static_cast<int>( EuclideanNorm( direction ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2023-06-02 17:25:31 +00:00
|
|
|
if( ( direction.x > 0 || direction.y < 0 ) != ( aElem.angle >= 180.0 ) )
|
2020-04-03 23:22:24 +00:00
|
|
|
height = -height;
|
2020-09-09 03:17:08 +00:00
|
|
|
|
|
|
|
dimension->SetHeight( height );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetEnd( referencePoint1 );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetLineThickness( aElem.linewidth );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2023-06-02 17:25:31 +00:00
|
|
|
dimension->SetUnitsFormat( DIM_UNITS_FORMAT::NO_SUFFIX );
|
2021-07-24 13:23:55 +00:00
|
|
|
dimension->SetPrefix( aElem.textprefix );
|
|
|
|
|
2023-06-02 17:25:31 +00:00
|
|
|
// Suffix normally (but not always) holds the units
|
|
|
|
wxRegEx units( wxS( "(mm)|(in)|(mils)|(thou)|(')|(\")" ), wxRE_ADVANCED );
|
|
|
|
|
|
|
|
if( units.Matches( aElem.textsuffix ) )
|
|
|
|
dimension->SetUnitsFormat( DIM_UNITS_FORMAT::BARE_SUFFIX );
|
|
|
|
else
|
|
|
|
dimension->SetSuffix( aElem.textsuffix );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextThickness( aElem.textlinewidth );
|
|
|
|
dimension->SetTextSize( VECTOR2I( aElem.textheight, aElem.textheight ) );
|
|
|
|
dimension->SetItalic( aElem.textitalic );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2021-07-24 19:23:59 +00:00
|
|
|
#if 0 // we don't currently support bold; map to thicker text
|
|
|
|
dimension->Text().SetBold( aElem.textbold );
|
|
|
|
#else
|
|
|
|
if( aElem.textbold )
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextThickness( dimension->GetTextThickness() * BOLD_FACTOR );
|
2021-07-24 19:23:59 +00:00
|
|
|
#endif
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
switch( aElem.textunit )
|
|
|
|
{
|
|
|
|
case ALTIUM_UNIT::INCHES:
|
2020-10-02 20:51:24 +00:00
|
|
|
dimension->SetUnits( EDA_UNITS::INCHES );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_UNIT::MILS:
|
2020-10-02 22:04:16 +00:00
|
|
|
dimension->SetUnits( EDA_UNITS::MILS );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_UNIT::MILLIMETERS:
|
|
|
|
case ALTIUM_UNIT::CENTIMETER:
|
2020-10-02 20:51:24 +00:00
|
|
|
dimension->SetUnits( EDA_UNITS::MILLIMETRES );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( dimension.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 13:23:55 +00:00
|
|
|
|
|
|
|
void ALTIUM_PCB::HelperParseDimensions6Radial(const ADIMENSION6 &aElem)
|
|
|
|
{
|
|
|
|
if( aElem.referencePoint.size() < 2 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Not enough reference points for radial dimension object" ) );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
|
|
|
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-05-04 15:27:52 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format(
|
|
|
|
_( "Dimension found on an Altium layer (%d) with no KiCad equivalent. "
|
|
|
|
"It has been moved to KiCad layer Eco1_User." ),
|
|
|
|
aElem.layer ), RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
|
2021-07-24 13:23:55 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I referencePoint0 = aElem.referencePoint.at( 0 );
|
|
|
|
VECTOR2I referencePoint1 = aElem.referencePoint.at( 1 );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_DIM_RADIAL> dimension = std::make_unique<PCB_DIM_RADIAL>( m_board );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2023-03-05 13:27:22 +00:00
|
|
|
dimension->SetPrecision( static_cast<DIM_PRECISION>( aElem.textprecision ) );
|
2021-07-24 13:23:55 +00:00
|
|
|
dimension->SetLayer( klayer );
|
|
|
|
dimension->SetStart( referencePoint0 );
|
|
|
|
dimension->SetEnd( aElem.xy1 );
|
|
|
|
dimension->SetLineThickness( aElem.linewidth );
|
2021-07-24 19:05:34 +00:00
|
|
|
dimension->SetKeepTextAligned( false );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
|
|
|
dimension->SetPrefix( aElem.textprefix );
|
|
|
|
|
|
|
|
// Suffix normally holds the units
|
|
|
|
dimension->SetUnitsFormat( aElem.textsuffix.IsEmpty() ? DIM_UNITS_FORMAT::NO_SUFFIX
|
|
|
|
: DIM_UNITS_FORMAT::BARE_SUFFIX );
|
|
|
|
|
|
|
|
switch( aElem.textunit )
|
|
|
|
{
|
|
|
|
case ALTIUM_UNIT::INCHES:
|
|
|
|
dimension->SetUnits( EDA_UNITS::INCHES );
|
|
|
|
break;
|
|
|
|
case ALTIUM_UNIT::MILS:
|
|
|
|
dimension->SetUnits( EDA_UNITS::MILS );
|
|
|
|
break;
|
|
|
|
case ALTIUM_UNIT::MILLIMETERS:
|
|
|
|
case ALTIUM_UNIT::CENTIMETER:
|
|
|
|
dimension->SetUnits( EDA_UNITS::MILLIMETRES );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.textPoint.empty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxT( "No text position present for leader dimension object" ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2021-07-24 13:23:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( aElem.textPoint.at( 0 ) );
|
|
|
|
dimension->SetTextThickness( aElem.textlinewidth );
|
|
|
|
dimension->SetTextSize( VECTOR2I( aElem.textheight, aElem.textheight ) );
|
|
|
|
dimension->SetItalic( aElem.textitalic );
|
2021-07-24 19:23:59 +00:00
|
|
|
|
|
|
|
#if 0 // we don't currently support bold; map to thicker text
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetBold( aElem.textbold );
|
2021-07-24 19:23:59 +00:00
|
|
|
#else
|
|
|
|
if( aElem.textbold )
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextThickness( dimension->GetTextThickness() * BOLD_FACTOR );
|
2021-07-24 19:23:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// It's unclear exactly how Altium figures it's text positioning, but this gets us reasonably
|
|
|
|
// close.
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
dimension->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2023-03-04 23:15:43 +00:00
|
|
|
int yAdjust = dimension->GetTextBox().GetCenter().y - dimension->GetTextPos().y;
|
|
|
|
dimension->SetTextPos( dimension->GetTextPos() + VECTOR2I( 0, yAdjust + aElem.textgap ) );
|
|
|
|
dimension->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_radialDimensions.push_back( dimension.get() );
|
|
|
|
m_board->Add( dimension.release(), ADD_MODE::APPEND );
|
2021-07-24 13:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
void ALTIUM_PCB::HelperParseDimensions6Leader( const ADIMENSION6& aElem )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Dimension found on an Altium layer (%d) with no KiCad equivalent. "
|
|
|
|
"It has been moved to KiCad layer Eco1_User." ), aElem.layer );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aElem.referencePoint.empty() )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I referencePoint0 = aElem.referencePoint.at( 0 );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
// line
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I last = referencePoint0;
|
2020-04-03 23:22:24 +00:00
|
|
|
for( size_t i = 1; i < aElem.referencePoint.size(); i++ )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::SEGMENT );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( klayer );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( aElem.linewidth, LINE_STYLE::SOLID ) );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetStart( last );
|
|
|
|
shape->SetEnd( aElem.referencePoint.at( i ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
last = aElem.referencePoint.at( i );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( shape.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// arrow
|
|
|
|
if( aElem.referencePoint.size() >= 2 )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I dirVec = aElem.referencePoint.at( 1 ) - referencePoint0;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( dirVec.x != 0 || dirVec.y != 0 )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
double scaling = EuclideanNorm( dirVec ) / aElem.arrowsize;
|
2024-03-30 23:03:03 +00:00
|
|
|
VECTOR2I arrVec =
|
|
|
|
VECTOR2I( KiROUND( dirVec.x / scaling ), KiROUND( dirVec.y / scaling ) );
|
2022-01-18 02:21:34 +00:00
|
|
|
RotatePoint( arrVec, EDA_ANGLE( 20.0, DEGREES_T ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
{
|
|
|
|
std::unique_ptr<PCB_SHAPE> shape1 =
|
|
|
|
std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::SEGMENT );
|
|
|
|
|
|
|
|
shape1->SetLayer( klayer );
|
|
|
|
shape1->SetStroke( STROKE_PARAMS( aElem.linewidth, LINE_STYLE::SOLID ) );
|
|
|
|
shape1->SetStart( referencePoint0 );
|
|
|
|
shape1->SetEnd( referencePoint0 + arrVec );
|
|
|
|
|
|
|
|
m_board->Add( shape1.release(), ADD_MODE::APPEND );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-18 02:21:34 +00:00
|
|
|
RotatePoint( arrVec, EDA_ANGLE( -40.0, DEGREES_T ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
{
|
|
|
|
std::unique_ptr<PCB_SHAPE> shape2 =
|
|
|
|
std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::SEGMENT );
|
|
|
|
|
|
|
|
shape2->SetLayer( klayer );
|
|
|
|
shape2->SetStroke( STROKE_PARAMS( aElem.linewidth, LINE_STYLE::SOLID ) );
|
|
|
|
shape2->SetStart( referencePoint0 );
|
|
|
|
shape2->SetEnd( referencePoint0 + arrVec );
|
|
|
|
|
|
|
|
m_board->Add( shape2.release(), ADD_MODE::APPEND );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.textPoint.empty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxT( "No text position present for leader dimension object" ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_TEXT> text = std::make_unique<PCB_TEXT>( m_board );
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
text->SetText( aElem.textformat );
|
|
|
|
text->SetPosition( aElem.textPoint.at( 0 ) );
|
|
|
|
text->SetLayer( klayer );
|
2023-02-19 03:40:07 +00:00
|
|
|
text->SetTextSize( VECTOR2I( aElem.textheight, aElem.textheight ) ); // TODO: parse text width
|
2020-04-14 12:25:00 +00:00
|
|
|
text->SetTextThickness( aElem.textlinewidth );
|
2021-12-28 22:13:54 +00:00
|
|
|
text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( text.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
void ALTIUM_PCB::HelperParseDimensions6Datum( const ADIMENSION6& aElem )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Dimension found on an Altium layer (%d) with no KiCad equivalent. "
|
|
|
|
"It has been moved to KiCad layer Eco1_User." ), aElem.layer );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( size_t i = 0; i < aElem.referencePoint.size(); i++ )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::SEGMENT );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( klayer );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( aElem.linewidth, LINE_STYLE::SOLID ) );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetStart( aElem.referencePoint.at( i ) );
|
|
|
|
// shape->SetEnd( /* TODO: seems to be based on TEXTY */ );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( shape.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
void ALTIUM_PCB::HelperParseDimensions6Center( const ADIMENSION6& aElem )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Dimension found on an Altium layer (%d) with no KiCad equivalent. "
|
|
|
|
"It has been moved to KiCad layer Eco1_User." ), aElem.layer );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I vec = VECTOR2I( 0, aElem.height / 2 );
|
2022-01-18 02:21:34 +00:00
|
|
|
RotatePoint( vec, EDA_ANGLE( aElem.angle, DEGREES_T ) );
|
2020-10-26 13:11:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_DIM_CENTER> dimension = std::make_unique<PCB_DIM_CENTER>( m_board );
|
|
|
|
|
2020-10-26 13:11:24 +00:00
|
|
|
dimension->SetLayer( klayer );
|
|
|
|
dimension->SetLineThickness( aElem.linewidth );
|
|
|
|
dimension->SetStart( aElem.xy1 );
|
|
|
|
dimension->SetEnd( aElem.xy1 + vec );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( dimension.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseDimensions6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2022-02-05 02:06:25 +00:00
|
|
|
m_progressReporter->Report( _( "Loading dimension drawings..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
ADIMENSION6 elem( reader );
|
|
|
|
|
|
|
|
switch( elem.kind )
|
|
|
|
{
|
|
|
|
case ALTIUM_DIMENSION_KIND::LINEAR:
|
|
|
|
HelperParseDimensions6Linear( elem );
|
|
|
|
break;
|
2021-07-24 13:23:55 +00:00
|
|
|
case ALTIUM_DIMENSION_KIND::RADIAL:
|
|
|
|
HelperParseDimensions6Radial( elem );
|
|
|
|
break;
|
2020-04-03 23:22:24 +00:00
|
|
|
case ALTIUM_DIMENSION_KIND::LEADER:
|
|
|
|
HelperParseDimensions6Leader( elem );
|
|
|
|
break;
|
|
|
|
case ALTIUM_DIMENSION_KIND::DATUM:
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Ignored dimension of kind %d (not yet supported)." ), elem.kind );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
// HelperParseDimensions6Datum( elem );
|
|
|
|
break;
|
|
|
|
case ALTIUM_DIMENSION_KIND::CENTER:
|
|
|
|
HelperParseDimensions6Center( elem );
|
|
|
|
break;
|
|
|
|
default:
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Ignored dimension of kind %d (not yet supported)." ), elem.kind );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Dimensions6 stream is not fully parsed" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseModelsData( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2022-02-19 15:45:55 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry,
|
|
|
|
const std::vector<std::string>& aRootDir )
|
2020-04-21 13:34:06 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2022-02-05 02:06:25 +00:00
|
|
|
m_progressReporter->Report( _( "Loading 3D models..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2020-05-05 12:30:50 +00:00
|
|
|
if( reader.GetRemainingBytes() == 0 )
|
2021-07-10 15:37:19 +00:00
|
|
|
return;
|
2020-05-05 12:30:50 +00:00
|
|
|
|
|
|
|
wxString projectPath = wxPathOnly( m_board->GetFileName() );
|
|
|
|
// TODO: set KIPRJMOD always after import (not only when loading project)?
|
|
|
|
wxSetEnv( PROJECT_VAR_NAME, projectPath );
|
|
|
|
|
|
|
|
// TODO: make this path configurable?
|
2022-02-05 02:06:25 +00:00
|
|
|
const wxString altiumModelDir = wxT( "ALTIUM_EMBEDDED_MODELS" );
|
2020-05-05 12:30:50 +00:00
|
|
|
|
|
|
|
wxFileName altiumModelsPath = wxFileName::DirName( projectPath );
|
2022-02-05 02:06:25 +00:00
|
|
|
wxString kicadModelPrefix = wxT( "${KIPRJMOD}/" ) + altiumModelDir + wxT( "/" );
|
2021-07-10 15:37:19 +00:00
|
|
|
|
2020-05-05 12:30:50 +00:00
|
|
|
if( !altiumModelsPath.AppendDir( altiumModelDir ) )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Cannot construct directory path for step models" ) );
|
2020-05-05 12:30:50 +00:00
|
|
|
|
|
|
|
// Create dir if it does not exist
|
|
|
|
if( !altiumModelsPath.DirExists() )
|
|
|
|
{
|
|
|
|
if( !altiumModelsPath.Mkdir() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Failed to create folder '%s'." ) + wxS( " " )
|
|
|
|
+ _( "No 3D-models will be imported." ),
|
|
|
|
altiumModelsPath.GetFullPath() );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2020-05-05 12:30:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2021-11-10 17:56:24 +00:00
|
|
|
int idx = 0;
|
|
|
|
wxString invalidChars = wxFileName::GetForbiddenChars();
|
2021-07-10 15:37:19 +00:00
|
|
|
|
2020-04-21 13:34:06 +00:00
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-21 13:34:06 +00:00
|
|
|
AMODEL elem( reader );
|
|
|
|
|
2022-02-19 15:45:55 +00:00
|
|
|
std::vector<std::string> stepPath = aRootDir;
|
|
|
|
stepPath.emplace_back( std::to_string( idx ) );
|
|
|
|
|
2021-11-10 17:56:24 +00:00
|
|
|
bool validName = !elem.name.IsEmpty() && elem.name.IsAscii() &&
|
|
|
|
wxString::npos == elem.name.find_first_of( invalidChars );
|
2022-02-05 02:06:25 +00:00
|
|
|
wxString storageName = !validName ? wxString::Format( wxT( "model_%d" ), idx )
|
|
|
|
: elem.name;
|
2021-11-10 17:56:24 +00:00
|
|
|
wxFileName storagePath( altiumModelsPath.GetPath(), storageName );
|
2021-07-10 15:37:19 +00:00
|
|
|
|
|
|
|
idx++;
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2022-02-19 15:45:55 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* stepEntry = aAltiumPcbFile.FindStream( stepPath );
|
2021-07-10 15:37:19 +00:00
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
if( stepEntry == nullptr )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "File not found: '%s'. 3D-model not imported." ),
|
|
|
|
FormatPath( stepPath ) );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
size_t stepSize = static_cast<size_t>( stepEntry->size );
|
|
|
|
std::vector<char> stepContent( stepSize );
|
2020-04-21 13:34:06 +00:00
|
|
|
|
|
|
|
// read file into buffer
|
2022-01-06 15:27:09 +00:00
|
|
|
aAltiumPcbFile.GetCompoundFileReader().ReadFile( stepEntry, 0, stepContent.data(),
|
|
|
|
stepSize );
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2020-05-05 12:30:50 +00:00
|
|
|
if( !storagePath.IsDirWritable() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Insufficient permissions to save file '%s'." ),
|
|
|
|
storagePath.GetFullPath() );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2020-05-05 12:30:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-21 13:34:06 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
wxMemoryInputStream stepStream( stepContent.data(), stepSize );
|
2020-04-21 13:34:06 +00:00
|
|
|
wxZlibInputStream zlibInputStream( stepStream );
|
|
|
|
|
2020-12-12 23:51:35 +00:00
|
|
|
wxFFileOutputStream outputStream( storagePath.GetFullPath() );
|
2024-02-16 11:35:22 +00:00
|
|
|
|
|
|
|
if( !outputStream.IsOk() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Unable to write file '%s'." ), storagePath.GetFullPath() );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2024-02-16 11:35:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-21 13:34:06 +00:00
|
|
|
outputStream.Write( zlibInputStream );
|
|
|
|
outputStream.Close();
|
|
|
|
|
2021-11-10 17:56:24 +00:00
|
|
|
m_models.insert( { elem.id, kicadModelPrefix + storageName } );
|
2020-04-21 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Models stream is not fully parsed" ) );
|
2020-04-21 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseNets6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading nets..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-11-19 11:50:54 +00:00
|
|
|
wxASSERT( m_altiumToKicadNetcodes.empty() );
|
2024-05-01 01:21:48 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
ANET6 elem( reader );
|
|
|
|
|
2022-11-19 11:50:54 +00:00
|
|
|
NETINFO_ITEM* netInfo = new NETINFO_ITEM( m_board, elem.name, 0 );
|
|
|
|
m_board->Add( netInfo, ADD_MODE::APPEND );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
// needs to be called after m_board->Add() as assign us the NetCode
|
2022-11-19 11:50:54 +00:00
|
|
|
m_altiumToKicadNetcodes.push_back( netInfo->GetNetCode() );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Nets6 stream is not fully parsed" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParsePolygons6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading polygons..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
APOLYGON6 elem( reader );
|
|
|
|
|
2020-10-22 15:23:12 +00:00
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, elem.vertices );
|
|
|
|
|
2023-07-21 03:00:24 +00:00
|
|
|
if( linechain.PointCount() < 3 )
|
2020-10-22 15:23:12 +00:00
|
|
|
{
|
2021-07-04 10:02:05 +00:00
|
|
|
// We have found multiple Altium files with polygon records containing nothing but two
|
|
|
|
// coincident vertices. These polygons do not appear when opening the file in Altium.
|
|
|
|
// https://gitlab.com/kicad/code/kicad/-/issues/8183
|
2023-07-21 03:00:24 +00:00
|
|
|
// Also, polygons with less than 3 points are not supported in KiCad.
|
2021-07-04 10:02:05 +00:00
|
|
|
//
|
|
|
|
// wxLogError( _( "Polygon has only %d point extracted from %ld vertices. At least 2 "
|
|
|
|
// "points are required." ),
|
|
|
|
// linechain.PointCount(),
|
|
|
|
// elem.vertices.size() );
|
|
|
|
|
2020-10-22 15:23:12 +00:00
|
|
|
m_polygons.emplace_back( nullptr );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( m_board );
|
|
|
|
m_polygons.emplace_back( zone.get() );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
zone->SetNetCode( GetNetCode( elem.net ) );
|
|
|
|
zone->SetPosition( elem.vertices.at( 0 ).position );
|
|
|
|
zone->SetLocked( elem.locked );
|
2022-03-01 14:53:35 +00:00
|
|
|
zone->SetAssignedPriority( elem.pourindex > 0 ? elem.pourindex : 0 );
|
2020-10-22 15:23:12 +00:00
|
|
|
zone->Outline()->AddOutline( linechain );
|
2020-05-10 17:30:03 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
HelperSetZoneLayers( *zone, elem.layer );
|
2022-02-19 13:37:05 +00:00
|
|
|
|
2020-05-10 17:30:03 +00:00
|
|
|
if( elem.pourindex > m_highest_pour_index )
|
|
|
|
m_highest_pour_index = elem.pourindex;
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2023-10-25 21:24:08 +00:00
|
|
|
const ARULE6* planeClearanceRule = GetRuleDefault( ALTIUM_RULE_KIND::PLANE_CLEARANCE );
|
|
|
|
const ARULE6* zoneClearanceRule = GetRule( ALTIUM_RULE_KIND::CLEARANCE,
|
|
|
|
wxT( "PolygonClearance" ) );
|
|
|
|
int planeLayers = 0;
|
|
|
|
int signalLayers = 0;
|
|
|
|
int clearance = 0;
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
LAYER_T layerType = m_board->GetLayerType( layer );
|
|
|
|
|
2023-10-26 09:43:21 +00:00
|
|
|
if( layerType == LT_POWER || layerType == LT_MIXED )
|
2023-10-25 21:24:08 +00:00
|
|
|
planeLayers++;
|
|
|
|
|
2023-10-26 09:43:21 +00:00
|
|
|
if( layerType == LT_SIGNAL || layerType == LT_MIXED )
|
2023-10-25 21:24:08 +00:00
|
|
|
signalLayers++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( planeLayers > 0 && planeClearanceRule )
|
|
|
|
clearance = std::max( clearance, planeClearanceRule->planeclearanceClearance );
|
|
|
|
|
|
|
|
if( signalLayers > 0 && zoneClearanceRule )
|
|
|
|
clearance = std::max( clearance, zoneClearanceRule->clearanceGap );
|
2020-05-10 17:30:03 +00:00
|
|
|
|
2023-10-25 21:24:08 +00:00
|
|
|
if( clearance > 0 )
|
|
|
|
zone->SetLocalClearance( clearance );
|
2020-05-10 17:30:03 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
const ARULE6* polygonConnectRule = GetRuleDefault( ALTIUM_RULE_KIND::POLYGON_CONNECT );
|
2020-05-10 17:30:03 +00:00
|
|
|
|
2020-04-06 15:45:02 +00:00
|
|
|
if( polygonConnectRule != nullptr )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2020-05-10 17:30:03 +00:00
|
|
|
switch( polygonConnectRule->polygonconnectStyle )
|
|
|
|
{
|
|
|
|
case ALTIUM_CONNECT_STYLE::DIRECT:
|
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::FULL );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_CONNECT_STYLE::NONE:
|
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::NONE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case ALTIUM_CONNECT_STYLE::RELIEF:
|
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::THERMAL );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
// TODO: correct variables?
|
2020-09-17 13:14:45 +00:00
|
|
|
zone->SetThermalReliefSpokeWidth(
|
2020-04-03 23:22:24 +00:00
|
|
|
polygonConnectRule->polygonconnectReliefconductorwidth );
|
|
|
|
zone->SetThermalReliefGap( polygonConnectRule->polygonconnectAirgapwidth );
|
2020-05-10 17:30:03 +00:00
|
|
|
|
|
|
|
if( polygonConnectRule->polygonconnectReliefconductorwidth < zone->GetMinThickness() )
|
|
|
|
zone->SetMinThickness( polygonConnectRule->polygonconnectReliefconductorwidth );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( IsAltiumLayerAPlane( elem.layer ) )
|
|
|
|
{
|
|
|
|
// outer zone will be set to priority 0 later.
|
2022-03-01 14:53:35 +00:00
|
|
|
zone->SetAssignedPriority( 1 );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
// check if this is the outer zone by simply comparing the BBOX
|
2021-07-24 13:23:55 +00:00
|
|
|
const auto& outer_plane = m_outer_plane.find( elem.layer );
|
|
|
|
if( outer_plane == m_outer_plane.end()
|
|
|
|
|| zone->GetBoundingBox().Contains( outer_plane->second->GetBoundingBox() ) )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
m_outer_plane[elem.layer] = zone.get();
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
if( elem.hatchstyle != ALTIUM_POLYGON_HATCHSTYLE::SOLID
|
|
|
|
&& elem.hatchstyle != ALTIUM_POLYGON_HATCHSTYLE::UNKNOWN )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetHatchThickness( elem.trackwidth );
|
2020-05-09 21:13:53 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.hatchstyle == ALTIUM_POLYGON_HATCHSTYLE::NONE )
|
|
|
|
{
|
|
|
|
// use a small hack to get us only an outline (hopefully)
|
2022-08-31 16:17:14 +00:00
|
|
|
const BOX2I& bbox = zone->GetBoundingBox();
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetHatchGap( std::max( bbox.GetHeight(), bbox.GetWidth() ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetHatchGap( elem.gridsize - elem.trackwidth );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2020-05-09 21:13:53 +00:00
|
|
|
|
2022-01-19 00:22:40 +00:00
|
|
|
if( elem.hatchstyle == ALTIUM_POLYGON_HATCHSTYLE::DEGREE_45 )
|
|
|
|
zone->SetHatchOrientation( ANGLE_45 );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE::GetDefaultHatchPitch(), true );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( zone.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Polygons6 stream is not fully parsed" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseRules6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading rules..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
ARULE6 elem( reader );
|
|
|
|
|
|
|
|
m_rules[elem.kind].emplace_back( elem );
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort rules by priority
|
2022-03-22 10:23:29 +00:00
|
|
|
for( std::pair<const ALTIUM_RULE_KIND, std::vector<ARULE6>>& val : m_rules )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
std::sort( val.second.begin(), val.second.end(),
|
2022-03-22 10:23:29 +00:00
|
|
|
[]( const ARULE6& lhs, const ARULE6& rhs )
|
2020-11-13 15:15:52 +00:00
|
|
|
{
|
|
|
|
return lhs.priority < rhs.priority;
|
|
|
|
} );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2023-10-25 15:06:26 +00:00
|
|
|
const ARULE6* clearanceRule = GetRuleDefault( ALTIUM_RULE_KIND::CLEARANCE );
|
|
|
|
const ARULE6* trackWidthRule = GetRuleDefault( ALTIUM_RULE_KIND::WIDTH );
|
|
|
|
const ARULE6* routingViasRule = GetRuleDefault( ALTIUM_RULE_KIND::ROUTING_VIAS );
|
|
|
|
const ARULE6* holeSizeRule = GetRuleDefault( ALTIUM_RULE_KIND::HOLE_SIZE );
|
|
|
|
const ARULE6* holeToHoleRule = GetRuleDefault( ALTIUM_RULE_KIND::HOLE_TO_HOLE_CLEARANCE );
|
|
|
|
|
|
|
|
if( clearanceRule )
|
|
|
|
m_board->GetDesignSettings().m_MinClearance = clearanceRule->clearanceGap;
|
|
|
|
|
|
|
|
if( trackWidthRule )
|
|
|
|
{
|
|
|
|
m_board->GetDesignSettings().m_TrackMinWidth = trackWidthRule->minLimit;
|
|
|
|
// TODO: construct a custom rule for preferredWidth and maxLimit values
|
|
|
|
}
|
|
|
|
|
|
|
|
if( routingViasRule )
|
|
|
|
{
|
|
|
|
m_board->GetDesignSettings().m_ViasMinSize = routingViasRule->minWidth;
|
|
|
|
m_board->GetDesignSettings().m_MinThroughDrill = routingViasRule->minHoleWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( holeSizeRule )
|
|
|
|
{
|
|
|
|
// TODO: construct a custom rule for minLimit / maxLimit values
|
|
|
|
}
|
|
|
|
|
|
|
|
if( holeToHoleRule )
|
|
|
|
m_board->GetDesignSettings().m_HoleToHoleMin = holeToHoleRule->clearanceGap;
|
|
|
|
|
2023-07-21 15:02:59 +00:00
|
|
|
const ARULE6* soldermaskRule = GetRuleDefault( ALTIUM_RULE_KIND::SOLDER_MASK_EXPANSION );
|
|
|
|
const ARULE6* pastemaskRule = GetRuleDefault( ALTIUM_RULE_KIND::PASTE_MASK_EXPANSION );
|
|
|
|
|
|
|
|
if( soldermaskRule )
|
|
|
|
m_board->GetDesignSettings().m_SolderMaskExpansion = soldermaskRule->soldermaskExpansion;
|
|
|
|
|
|
|
|
if( pastemaskRule )
|
|
|
|
m_board->GetDesignSettings().m_SolderPasteMargin = pastemaskRule->pastemaskExpansion;
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Rules6 stream is not fully parsed" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseBoardRegionsData( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading board regions..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
AREGION6 elem( reader, false );
|
|
|
|
|
|
|
|
// TODO: implement?
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "BoardRegions stream is not fully parsed" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseShapeBasedRegions6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2023-07-21 15:02:59 +00:00
|
|
|
m_progressReporter->Report( _( "Loading polygons..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2023-07-21 15:02:59 +00:00
|
|
|
/* TODO: use Header section of file */
|
|
|
|
for( int primitiveIndex = 0; reader.GetRemainingBytes() >= 4; primitiveIndex++ )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
AREGION6 elem( reader, true );
|
|
|
|
|
2022-01-25 20:53:42 +00:00
|
|
|
if( elem.component == ALTIUM_COMPONENT_NONE
|
|
|
|
|| elem.kind == ALTIUM_REGION_KIND::BOARD_CUTOUT )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-25 20:53:42 +00:00
|
|
|
// TODO: implement all different types for footprints
|
|
|
|
ConvertShapeBasedRegions6ToBoardItem( elem );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
else
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-25 20:53:42 +00:00
|
|
|
FOOTPRINT* footprint = HelperGetFootprint( elem.component );
|
2023-07-21 15:02:59 +00:00
|
|
|
ConvertShapeBasedRegions6ToFootprintItem( footprint, elem, primitiveIndex );
|
2022-01-25 20:53:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-22 15:23:12 +00:00
|
|
|
|
2022-01-25 20:53:42 +00:00
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
THROW_IO_ERROR( "ShapeBasedRegions6 stream is not fully parsed" );
|
|
|
|
}
|
2020-10-22 15:23:12 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-25 20:53:42 +00:00
|
|
|
void ALTIUM_PCB::ConvertShapeBasedRegions6ToBoardItem( const AREGION6& aElem )
|
|
|
|
{
|
|
|
|
if( aElem.kind == ALTIUM_REGION_KIND::BOARD_CUTOUT )
|
|
|
|
{
|
|
|
|
HelperCreateBoardOutline( aElem.outline );
|
|
|
|
}
|
|
|
|
else if( aElem.kind == ALTIUM_REGION_KIND::POLYGON_CUTOUT || aElem.is_keepout )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, aElem.outline );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2023-07-21 03:00:24 +00:00
|
|
|
if( linechain.PointCount() < 3 )
|
2022-01-25 20:53:42 +00:00
|
|
|
{
|
|
|
|
// We have found multiple Altium files with polygon records containing nothing but
|
|
|
|
// two coincident vertices. These polygons do not appear when opening the file in
|
|
|
|
// Altium. https://gitlab.com/kicad/code/kicad/-/issues/8183
|
2023-07-21 03:00:24 +00:00
|
|
|
// Also, polygons with less than 3 points are not supported in KiCad.
|
2022-01-25 20:53:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-22 15:23:12 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( m_board );
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2022-01-25 20:53:42 +00:00
|
|
|
zone->SetIsRuleArea( true );
|
2022-03-11 18:15:34 +00:00
|
|
|
|
2023-09-06 05:43:01 +00:00
|
|
|
if( aElem.is_keepout )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
HelperSetZoneKeepoutRestrictions( *zone, aElem.keepoutrestrictions );
|
2023-09-06 05:43:01 +00:00
|
|
|
}
|
|
|
|
else if( aElem.kind == ALTIUM_REGION_KIND::POLYGON_CUTOUT )
|
|
|
|
{
|
|
|
|
zone->SetDoNotAllowCopperPour( true );
|
|
|
|
zone->SetDoNotAllowVias( false );
|
|
|
|
zone->SetDoNotAllowTracks( false );
|
|
|
|
zone->SetDoNotAllowPads( false );
|
|
|
|
zone->SetDoNotAllowFootprints( false );
|
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
|
|
|
|
zone->SetPosition( aElem.outline.at( 0 ).position );
|
|
|
|
zone->Outline()->AddOutline( linechain );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
HelperSetZoneLayers( *zone, aElem.layer );
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2022-01-25 20:53:42 +00:00
|
|
|
zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
|
|
|
ZONE::GetDefaultHatchPitch(), true );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( zone.release(), ADD_MODE::APPEND );
|
2022-01-25 20:53:42 +00:00
|
|
|
}
|
2023-07-22 17:37:50 +00:00
|
|
|
else if( aElem.kind == ALTIUM_REGION_KIND::DASHED_OUTLINE )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
|
|
|
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Dashed outline found on an Altium layer (%d) with no KiCad equivalent. "
|
|
|
|
"It has been moved to KiCad layer Eco1_User." ), aElem.layer );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
2023-07-22 17:37:50 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, aElem.outline );
|
|
|
|
|
|
|
|
if( linechain.PointCount() < 3 )
|
|
|
|
{
|
|
|
|
// We have found multiple Altium files with polygon records containing nothing but
|
|
|
|
// two coincident vertices. These polygons do not appear when opening the file in
|
|
|
|
// Altium. https://gitlab.com/kicad/code/kicad/-/issues/8183
|
|
|
|
// Also, polygons with less than 3 points are not supported in KiCad.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::POLY );
|
2023-07-22 17:37:50 +00:00
|
|
|
|
|
|
|
shape->SetPolyShape( linechain );
|
|
|
|
shape->SetFilled( false );
|
|
|
|
shape->SetLayer( klayer );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( pcbIUScale.mmToIU( 0.1 ), LINE_STYLE::DASH ) );
|
2023-07-22 17:37:50 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( shape.release(), ADD_MODE::APPEND );
|
2023-07-22 17:37:50 +00:00
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
else if( aElem.kind == ALTIUM_REGION_KIND::COPPER )
|
|
|
|
{
|
2023-11-25 21:23:34 +00:00
|
|
|
if( aElem.polygon == ALTIUM_POLYGON_NONE )
|
2022-01-25 20:53:42 +00:00
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
|
|
|
ConvertShapeBasedRegions6ToBoardItemOnLayer( aElem, klayer );
|
|
|
|
}
|
|
|
|
}
|
2023-08-31 16:14:29 +00:00
|
|
|
else if( aElem.kind == ALTIUM_REGION_KIND::BOARD_CUTOUT )
|
|
|
|
{
|
|
|
|
ConvertShapeBasedRegions6ToBoardItemOnLayer( aElem, Edge_Cuts );
|
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Ignored polygon shape of kind %d (not yet supported)." ), aElem.kind );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-10-22 15:23:12 +00:00
|
|
|
|
2022-01-25 20:53:42 +00:00
|
|
|
void ALTIUM_PCB::ConvertShapeBasedRegions6ToFootprintItem( FOOTPRINT* aFootprint,
|
2023-07-21 15:02:59 +00:00
|
|
|
const AREGION6& aElem,
|
|
|
|
const int aPrimitiveIndex )
|
2022-01-25 20:53:42 +00:00
|
|
|
{
|
|
|
|
if( aElem.kind == ALTIUM_REGION_KIND::POLYGON_CUTOUT || aElem.is_keepout )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, aElem.outline );
|
2021-07-04 10:02:05 +00:00
|
|
|
|
2023-07-21 03:00:24 +00:00
|
|
|
if( linechain.PointCount() < 3 )
|
2022-01-25 20:53:42 +00:00
|
|
|
{
|
|
|
|
// We have found multiple Altium files with polygon records containing nothing but
|
|
|
|
// two coincident vertices. These polygons do not appear when opening the file in
|
|
|
|
// Altium. https://gitlab.com/kicad/code/kicad/-/issues/8183
|
2023-07-21 03:00:24 +00:00
|
|
|
// Also, polygons with less than 3 points are not supported in KiCad.
|
2022-01-25 20:53:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-22 15:23:12 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aFootprint );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-25 20:53:42 +00:00
|
|
|
zone->SetIsRuleArea( true );
|
2022-03-11 18:15:34 +00:00
|
|
|
|
2023-09-06 05:43:01 +00:00
|
|
|
if( aElem.is_keepout )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
HelperSetZoneKeepoutRestrictions( *zone, aElem.keepoutrestrictions );
|
2023-09-06 05:43:01 +00:00
|
|
|
}
|
|
|
|
else if( aElem.kind == ALTIUM_REGION_KIND::POLYGON_CUTOUT )
|
|
|
|
{
|
|
|
|
zone->SetDoNotAllowCopperPour( true );
|
|
|
|
zone->SetDoNotAllowVias( false );
|
|
|
|
zone->SetDoNotAllowTracks( false );
|
|
|
|
zone->SetDoNotAllowPads( false );
|
|
|
|
zone->SetDoNotAllowFootprints( false );
|
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
|
|
|
|
zone->SetPosition( aElem.outline.at( 0 ).position );
|
|
|
|
zone->Outline()->AddOutline( linechain );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
HelperSetZoneLayers( *zone, aElem.layer );
|
2022-01-25 20:53:42 +00:00
|
|
|
|
|
|
|
zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
|
|
|
ZONE::GetDefaultHatchPitch(), true );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
aFootprint->Add( zone.release(), ADD_MODE::APPEND );
|
2022-01-25 20:53:42 +00:00
|
|
|
}
|
|
|
|
else if( aElem.kind == ALTIUM_REGION_KIND::COPPER )
|
|
|
|
{
|
2023-11-25 21:23:34 +00:00
|
|
|
if( aElem.polygon == ALTIUM_POLYGON_NONE )
|
2022-01-25 20:53:42 +00:00
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
2023-09-14 16:15:15 +00:00
|
|
|
{
|
2023-07-21 15:02:59 +00:00
|
|
|
ConvertShapeBasedRegions6ToFootprintItemOnLayer( aFootprint, aElem, klayer,
|
|
|
|
aPrimitiveIndex );
|
2023-09-14 16:15:15 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-31 16:14:29 +00:00
|
|
|
else if( aElem.kind == ALTIUM_REGION_KIND::DASHED_OUTLINE
|
|
|
|
|| aElem.kind == ALTIUM_REGION_KIND::BOARD_CUTOUT )
|
2023-07-22 17:37:50 +00:00
|
|
|
{
|
2023-08-31 16:14:29 +00:00
|
|
|
PCB_LAYER_ID klayer = aElem.kind == ALTIUM_REGION_KIND::BOARD_CUTOUT
|
|
|
|
? Edge_Cuts
|
|
|
|
: GetKicadLayer( aElem.layer );
|
2023-07-22 17:37:50 +00:00
|
|
|
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s contains a dashed outline on Altium layer (%d) with "
|
|
|
|
"no KiCad equivalent. It has been moved to KiCad layer Eco1_User." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.layer );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s contains a dashed outline on Altium layer (%d) with "
|
2024-02-19 12:24:13 +00:00
|
|
|
"no KiCad equivalent. It has been moved to KiCad layer Eco1_User." ),
|
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.layer );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-22 17:37:50 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, aElem.outline );
|
|
|
|
|
|
|
|
if( linechain.PointCount() < 3 )
|
|
|
|
{
|
|
|
|
// We have found multiple Altium files with polygon records containing nothing but
|
|
|
|
// two coincident vertices. These polygons do not appear when opening the file in
|
|
|
|
// Altium. https://gitlab.com/kicad/code/kicad/-/issues/8183
|
|
|
|
// Also, polygons with less than 3 points are not supported in KiCad.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aFootprint, SHAPE_T::POLY );
|
2023-07-22 17:37:50 +00:00
|
|
|
|
|
|
|
shape->SetPolyShape( linechain );
|
|
|
|
shape->SetFilled( false );
|
|
|
|
shape->SetLayer( klayer );
|
2023-08-31 16:14:29 +00:00
|
|
|
|
|
|
|
if( aElem.kind == ALTIUM_REGION_KIND::DASHED_OUTLINE )
|
2023-11-25 13:05:45 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( pcbIUScale.mmToIU( 0.1 ), LINE_STYLE::DASH ) );
|
2023-08-31 16:14:29 +00:00
|
|
|
else
|
2023-11-25 13:05:45 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( pcbIUScale.mmToIU( 0.1 ), LINE_STYLE::SOLID ) );
|
2023-07-22 17:37:50 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( shape.release(), ADD_MODE::APPEND );
|
2023-07-22 17:37:50 +00:00
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
else
|
|
|
|
{
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s contains polygon shape of kind %d (not yet supported)." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.kind );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s contains polygon shape of kind %d (not yet supported)." ),
|
2024-02-19 12:24:13 +00:00
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.kind );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-25 20:53:42 +00:00
|
|
|
|
|
|
|
void ALTIUM_PCB::ConvertShapeBasedRegions6ToBoardItemOnLayer( const AREGION6& aElem,
|
|
|
|
PCB_LAYER_ID aLayer )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, aElem.outline );
|
|
|
|
|
2023-07-21 03:00:24 +00:00
|
|
|
if( linechain.PointCount() < 3 )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-25 20:53:42 +00:00
|
|
|
// We have found multiple Altium files with polygon records containing nothing
|
|
|
|
// but two coincident vertices. These polygons do not appear when opening the
|
|
|
|
// file in Altium. https://gitlab.com/kicad/code/kicad/-/issues/8183
|
2023-07-21 03:00:24 +00:00
|
|
|
// Also, polygons with less than 3 points are not supported in KiCad.
|
2022-01-25 20:53:42 +00:00
|
|
|
return;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
|
2023-07-21 03:02:21 +00:00
|
|
|
SHAPE_POLY_SET polySet;
|
|
|
|
polySet.AddOutline( linechain );
|
|
|
|
|
|
|
|
for( const std::vector<ALTIUM_VERTICE>& hole : aElem.holes )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN hole_linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( hole_linechain, hole );
|
|
|
|
|
|
|
|
if( hole_linechain.PointCount() < 3 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
polySet.AddHole( hole_linechain );
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::POLY );
|
2022-01-25 20:53:42 +00:00
|
|
|
|
2023-07-21 03:02:21 +00:00
|
|
|
shape->SetPolyShape( polySet );
|
2022-01-25 20:53:42 +00:00
|
|
|
shape->SetFilled( true );
|
|
|
|
shape->SetLayer( aLayer );
|
|
|
|
shape->SetStroke( STROKE_PARAMS( 0 ) );
|
|
|
|
|
2023-08-18 12:51:33 +00:00
|
|
|
if( IsCopperLayer( aLayer ) && aElem.net != ALTIUM_NET_UNCONNECTED )
|
|
|
|
{
|
2023-08-18 09:59:35 +00:00
|
|
|
shape->SetNetCode( GetNetCode( aElem.net ) );
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( shape.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 20:53:42 +00:00
|
|
|
|
|
|
|
void ALTIUM_PCB::ConvertShapeBasedRegions6ToFootprintItemOnLayer( FOOTPRINT* aFootprint,
|
|
|
|
const AREGION6& aElem,
|
2023-07-21 15:02:59 +00:00
|
|
|
PCB_LAYER_ID aLayer,
|
|
|
|
const int aPrimitiveIndex )
|
2022-01-25 20:53:42 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, aElem.outline );
|
|
|
|
|
2023-07-21 03:00:24 +00:00
|
|
|
if( linechain.PointCount() < 3 )
|
2022-01-25 20:53:42 +00:00
|
|
|
{
|
|
|
|
// We have found multiple Altium files with polygon records containing nothing
|
|
|
|
// but two coincident vertices. These polygons do not appear when opening the
|
|
|
|
// file in Altium. https://gitlab.com/kicad/code/kicad/-/issues/8183
|
2023-07-21 03:00:24 +00:00
|
|
|
// Also, polygons with less than 3 points are not supported in KiCad.
|
2022-01-25 20:53:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-21 15:02:59 +00:00
|
|
|
SHAPE_POLY_SET polySet;
|
|
|
|
polySet.AddOutline( linechain );
|
2022-01-25 20:53:42 +00:00
|
|
|
|
2023-07-21 15:02:59 +00:00
|
|
|
for( const std::vector<ALTIUM_VERTICE>& hole : aElem.holes )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN hole_linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( hole_linechain, hole );
|
|
|
|
|
|
|
|
if( hole_linechain.PointCount() < 3 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
polySet.AddHole( hole_linechain );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aLayer == F_Cu || aLayer == B_Cu )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PAD> pad = std::make_unique<PAD>( aFootprint );
|
2023-07-21 15:02:59 +00:00
|
|
|
|
|
|
|
LSET padLayers;
|
|
|
|
padLayers.set( aLayer );
|
2022-01-25 20:53:42 +00:00
|
|
|
|
2023-07-21 15:02:59 +00:00
|
|
|
pad->SetKeepTopBottom( false ); // TODO: correct? This seems to be KiCad default on import
|
|
|
|
pad->SetAttribute( PAD_ATTRIB::SMD );
|
|
|
|
pad->SetShape( PAD_SHAPE::CUSTOM );
|
2024-04-27 17:25:47 +00:00
|
|
|
pad->SetThermalSpokeAngle( ANGLE_90 );
|
2023-07-21 15:02:59 +00:00
|
|
|
|
|
|
|
int anchorSize = 1;
|
|
|
|
VECTOR2I anchorPos = linechain.CPoint( 0 );
|
|
|
|
|
|
|
|
pad->SetShape( PAD_SHAPE::CUSTOM );
|
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE::CIRCLE );
|
|
|
|
pad->SetSize( { anchorSize, anchorSize } );
|
|
|
|
pad->SetPosition( anchorPos );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET shapePolys = polySet;
|
|
|
|
shapePolys.Move( -anchorPos );
|
|
|
|
pad->AddPrimitivePoly( shapePolys, 0, true );
|
|
|
|
|
|
|
|
auto& map = m_extendedPrimitiveInformationMaps[ALTIUM_RECORD::REGION];
|
|
|
|
auto it = map.find( aPrimitiveIndex );
|
|
|
|
|
|
|
|
if( it != map.end() )
|
|
|
|
{
|
|
|
|
const AEXTENDED_PRIMITIVE_INFORMATION& info = it->second;
|
|
|
|
|
|
|
|
if( info.pastemaskexpansionmode == ALTIUM_MODE::MANUAL )
|
|
|
|
{
|
|
|
|
pad->SetLocalSolderPasteMargin(
|
|
|
|
info.pastemaskexpansionmanual ? info.pastemaskexpansionmanual : 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( info.soldermaskexpansionmode == ALTIUM_MODE::MANUAL )
|
|
|
|
{
|
|
|
|
pad->SetLocalSolderMaskMargin(
|
|
|
|
info.soldermaskexpansionmanual ? info.soldermaskexpansionmanual : 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( info.pastemaskexpansionmode != ALTIUM_MODE::NONE )
|
|
|
|
padLayers.set( aLayer == F_Cu ? F_Paste : B_Paste );
|
|
|
|
|
|
|
|
if( info.soldermaskexpansionmode != ALTIUM_MODE::NONE )
|
|
|
|
padLayers.set( aLayer == F_Cu ? F_Mask : B_Mask );
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetLayerSet( padLayers );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( pad.release(), ADD_MODE::APPEND );
|
2023-07-21 15:02:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aFootprint, SHAPE_T::POLY );
|
2023-07-21 15:02:59 +00:00
|
|
|
|
|
|
|
shape->SetPolyShape( polySet );
|
|
|
|
shape->SetFilled( true );
|
|
|
|
shape->SetLayer( aLayer );
|
|
|
|
shape->SetStroke( STROKE_PARAMS( 0 ) );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( shape.release(), ADD_MODE::APPEND );
|
2023-07-21 15:02:59 +00:00
|
|
|
}
|
2022-01-25 20:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseRegions6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading zone fills..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
AREGION6 elem( reader, false );
|
|
|
|
|
2023-11-25 21:23:34 +00:00
|
|
|
if( elem.polygon != ALTIUM_POLYGON_NONE )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2023-11-25 21:23:34 +00:00
|
|
|
if( m_polygons.size() <= elem.polygon )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 19:21:30 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( "Region stream tries to access polygon id %d "
|
|
|
|
"of %d existing polygons.",
|
2023-11-25 21:23:34 +00:00
|
|
|
elem.polygon,
|
2021-06-26 19:21:30 +00:00
|
|
|
m_polygons.size() ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 21:23:34 +00:00
|
|
|
ZONE* zone = m_polygons.at( elem.polygon );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
if( zone == nullptr )
|
|
|
|
{
|
2022-03-22 10:23:29 +00:00
|
|
|
continue; // we know the zone id, but because we do not know the layer we did not
|
|
|
|
// add it!
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-06 22:06:23 +00:00
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
2022-02-11 12:42:09 +00:00
|
|
|
|
2021-02-06 22:06:23 +00:00
|
|
|
if( klayer == UNDEFINED_LAYER )
|
2021-06-09 19:32:58 +00:00
|
|
|
continue; // Just skip it for now. Users can fill it themselves.
|
2021-02-06 22:06:23 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
SHAPE_LINE_CHAIN linechain;
|
2022-02-11 12:42:09 +00:00
|
|
|
|
2021-02-06 22:06:23 +00:00
|
|
|
for( const ALTIUM_VERTICE& vertice : elem.outline )
|
2020-04-03 23:22:24 +00:00
|
|
|
linechain.Append( vertice.position );
|
2022-02-11 12:42:09 +00:00
|
|
|
|
2021-02-06 22:06:23 +00:00
|
|
|
linechain.Append( elem.outline.at( 0 ).position );
|
2020-04-03 23:22:24 +00:00
|
|
|
linechain.SetClosed( true );
|
|
|
|
|
2022-02-16 15:33:12 +00:00
|
|
|
SHAPE_POLY_SET fill;
|
|
|
|
fill.AddOutline( linechain );
|
2021-02-06 22:06:23 +00:00
|
|
|
|
|
|
|
for( const std::vector<ALTIUM_VERTICE>& hole : elem.holes )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN hole_linechain;
|
2022-02-11 12:42:09 +00:00
|
|
|
|
2021-02-06 22:06:23 +00:00
|
|
|
for( const ALTIUM_VERTICE& vertice : hole )
|
|
|
|
hole_linechain.Append( vertice.position );
|
2022-02-11 12:42:09 +00:00
|
|
|
|
2021-02-06 22:06:23 +00:00
|
|
|
hole_linechain.Append( hole.at( 0 ).position );
|
|
|
|
hole_linechain.SetClosed( true );
|
2022-02-16 15:33:12 +00:00
|
|
|
fill.AddHole( hole_linechain );
|
2021-02-06 22:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( zone->HasFilledPolysForLayer( klayer ) )
|
2022-02-16 15:33:12 +00:00
|
|
|
fill.BooleanAdd( *zone->GetFill( klayer ), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2021-02-06 22:06:23 +00:00
|
|
|
|
2022-02-16 15:33:12 +00:00
|
|
|
fill.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-02-16 15:33:12 +00:00
|
|
|
zone->SetFilledPolysList( klayer, fill );
|
2020-04-03 23:22:24 +00:00
|
|
|
zone->SetIsFilled( true );
|
2021-02-06 22:06:23 +00:00
|
|
|
zone->SetNeedRefill( false );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Regions6 stream is not fully parsed" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseArcs6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-10-04 23:34:59 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading arcs..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
for( int primitiveIndex = 0; reader.GetRemainingBytes() >= 4; primitiveIndex++ )
|
2022-01-10 19:45:42 +00:00
|
|
|
{
|
|
|
|
checkpoint();
|
|
|
|
AARC6 elem( reader );
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
if( elem.component == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2022-02-20 19:18:22 +00:00
|
|
|
ConvertArcs6ToBoardItem( elem, primitiveIndex );
|
2022-01-10 19:45:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FOOTPRINT* footprint = HelperGetFootprint( elem.component );
|
2022-02-20 19:18:22 +00:00
|
|
|
ConvertArcs6ToFootprintItem( footprint, elem, primitiveIndex, true );
|
2022-01-10 19:45:42 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-24 19:05:34 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
THROW_IO_ERROR( "Arcs6 stream is not fully parsed" );
|
|
|
|
}
|
2021-07-24 19:05:34 +00:00
|
|
|
|
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
void ALTIUM_PCB::ConvertArcs6ToPcbShape( const AARC6& aElem, PCB_SHAPE* aShape )
|
|
|
|
{
|
|
|
|
if( aElem.startangle == 0. && aElem.endangle == 360. )
|
|
|
|
{
|
|
|
|
aShape->SetShape( SHAPE_T::CIRCLE );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
// TODO: other variants to define circle?
|
|
|
|
aShape->SetStart( aElem.center );
|
|
|
|
aShape->SetEnd( aElem.center - VECTOR2I( 0, aElem.radius ) );
|
|
|
|
}
|
|
|
|
else
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-10 19:45:42 +00:00
|
|
|
aShape->SetShape( SHAPE_T::ARC );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
EDA_ANGLE includedAngle( aElem.endangle - aElem.startangle, DEGREES_T );
|
|
|
|
EDA_ANGLE startAngle( aElem.endangle, DEGREES_T );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
VECTOR2I startOffset = VECTOR2I( KiROUND( startAngle.Cos() * aElem.radius ),
|
|
|
|
-KiROUND( startAngle.Sin() * aElem.radius ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
aShape->SetCenter( aElem.center );
|
|
|
|
aShape->SetStart( aElem.center + startOffset );
|
|
|
|
aShape->SetArcAngleAndEnd( includedAngle.Normalize(), true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
void ALTIUM_PCB::ConvertArcs6ToBoardItem( const AARC6& aElem, const int aPrimitiveIndex )
|
2022-01-10 19:45:42 +00:00
|
|
|
{
|
2024-02-01 09:14:51 +00:00
|
|
|
if( aElem.polygon != ALTIUM_POLYGON_NONE && aElem.polygon != ALTIUM_POLYGON_BOARD )
|
2023-11-25 21:23:34 +00:00
|
|
|
{
|
|
|
|
if( m_polygons.size() <= aElem.polygon )
|
|
|
|
{
|
2024-01-25 12:50:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( "Tracks stream tries to access polygon id %u "
|
|
|
|
"of %zu existing polygons.",
|
2023-11-25 21:23:34 +00:00
|
|
|
aElem.polygon, m_polygons.size() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
ZONE* zone = m_polygons.at( aElem.polygon );
|
|
|
|
|
|
|
|
if( zone == nullptr )
|
|
|
|
{
|
|
|
|
return; // we know the zone id, but because we do not know the layer we did not
|
|
|
|
// add it!
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
|
|
|
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
return; // Just skip it for now. Users can fill it themselves.
|
|
|
|
|
|
|
|
SHAPE_POLY_SET* fill = zone->GetFill( klayer );
|
|
|
|
|
|
|
|
// This is not the actual board item. We can use it to create the polygon for the region
|
|
|
|
PCB_SHAPE shape( nullptr );
|
|
|
|
|
|
|
|
ConvertArcs6ToPcbShape( aElem, &shape );
|
|
|
|
shape.SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
|
|
|
|
|
|
|
shape.EDA_SHAPE::TransformShapeToPolygon( *fill, 0, ARC_HIGH_DEF, ERROR_INSIDE );
|
|
|
|
// Will be simplified and fractured later
|
|
|
|
|
|
|
|
zone->SetIsFilled( true );
|
|
|
|
zone->SetNeedRefill( false );
|
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
return;
|
2023-11-25 21:23:34 +00:00
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2022-04-02 16:04:45 +00:00
|
|
|
if( aElem.is_keepout || aElem.layer == ALTIUM_LAYER::KEEP_OUT_LAYER
|
|
|
|
|| IsAltiumLayerAPlane( aElem.layer ) )
|
2022-01-10 19:45:42 +00:00
|
|
|
{
|
|
|
|
// This is not the actual board item. We can use it to create the polygon for the region
|
|
|
|
PCB_SHAPE shape( nullptr );
|
|
|
|
|
|
|
|
ConvertArcs6ToPcbShape( aElem, &shape );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape.SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
2022-01-10 19:45:42 +00:00
|
|
|
|
2022-03-11 18:15:34 +00:00
|
|
|
HelperPcpShapeAsBoardKeepoutRegion( shape, aElem.layer, aElem.keepoutrestrictions );
|
2022-01-10 19:45:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
|
|
|
ConvertArcs6ToBoardItemOnLayer( aElem, klayer );
|
|
|
|
}
|
2022-02-20 19:18:22 +00:00
|
|
|
|
2023-06-15 21:57:05 +00:00
|
|
|
for( const auto& layerExpansionMask :
|
2022-02-20 19:18:22 +00:00
|
|
|
HelperGetSolderAndPasteMaskExpansions( ALTIUM_RECORD::ARC, aPrimitiveIndex, aElem.layer ) )
|
|
|
|
{
|
|
|
|
int width = aElem.width + ( layerExpansionMask.second * 2 );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
if( width > 1 )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> arc = std::make_unique<PCB_SHAPE>( m_board );
|
2022-02-20 19:18:22 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
ConvertArcs6ToPcbShape( aElem, arc.get() );
|
2023-11-25 13:05:45 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( width, LINE_STYLE::SOLID ) );
|
2022-02-20 19:18:22 +00:00
|
|
|
arc->SetLayer( layerExpansionMask.first );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( arc.release(), ADD_MODE::APPEND );
|
2022-02-20 19:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-10 19:45:42 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
void ALTIUM_PCB::ConvertArcs6ToFootprintItem( FOOTPRINT* aFootprint, const AARC6& aElem,
|
2022-02-20 19:18:22 +00:00
|
|
|
const int aPrimitiveIndex, const bool aIsBoardImport )
|
2022-01-10 19:45:42 +00:00
|
|
|
{
|
2023-11-25 21:23:34 +00:00
|
|
|
if( aElem.polygon != ALTIUM_POLYGON_NONE )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxString::Format( "Altium: Unexpected footprint Arc with polygon id %d",
|
|
|
|
aElem.polygon ) );
|
2022-01-10 19:45:42 +00:00
|
|
|
return;
|
2023-11-25 21:23:34 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-04-02 16:04:45 +00:00
|
|
|
if( aElem.is_keepout || aElem.layer == ALTIUM_LAYER::KEEP_OUT_LAYER
|
|
|
|
|| IsAltiumLayerAPlane( aElem.layer ) )
|
2022-01-10 19:45:42 +00:00
|
|
|
{
|
|
|
|
// This is not the actual board item. We can use it to create the polygon for the region
|
|
|
|
PCB_SHAPE shape( nullptr );
|
|
|
|
|
|
|
|
ConvertArcs6ToPcbShape( aElem, &shape );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape.SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
2022-01-10 19:45:42 +00:00
|
|
|
|
2022-03-11 18:15:34 +00:00
|
|
|
HelperPcpShapeAsFootprintKeepoutRegion( aFootprint, shape, aElem.layer,
|
|
|
|
aElem.keepoutrestrictions );
|
2022-01-10 19:45:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
|
|
|
{
|
|
|
|
if( aIsBoardImport && IsCopperLayer( klayer ) && aElem.net != ALTIUM_NET_UNCONNECTED )
|
2020-10-20 08:35:58 +00:00
|
|
|
{
|
2022-01-10 19:45:42 +00:00
|
|
|
// Special case: do to not lose net connections in footprints
|
|
|
|
ConvertArcs6ToBoardItemOnLayer( aElem, klayer );
|
2020-10-20 08:35:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-10 19:45:42 +00:00
|
|
|
ConvertArcs6ToFootprintItemOnLayer( aFootprint, aElem, klayer );
|
2020-10-20 08:35:58 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-10 19:45:42 +00:00
|
|
|
}
|
2022-02-20 19:18:22 +00:00
|
|
|
|
2023-06-15 21:57:05 +00:00
|
|
|
for( const auto& layerExpansionMask :
|
2022-02-20 19:18:22 +00:00
|
|
|
HelperGetSolderAndPasteMaskExpansions( ALTIUM_RECORD::ARC, aPrimitiveIndex, aElem.layer ) )
|
|
|
|
{
|
|
|
|
int width = aElem.width + ( layerExpansionMask.second * 2 );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
if( width > 1 )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> arc = std::make_unique<PCB_SHAPE>( aFootprint );
|
2022-02-20 19:18:22 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
ConvertArcs6ToPcbShape( aElem, arc.get() );
|
2023-11-25 13:05:45 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( width, LINE_STYLE::SOLID ) );
|
2022-02-20 19:18:22 +00:00
|
|
|
arc->SetLayer( layerExpansionMask.first );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( arc.release(), ADD_MODE::APPEND );
|
2022-02-20 19:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-10 19:45:42 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-10-20 08:35:58 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
void ALTIUM_PCB::ConvertArcs6ToBoardItemOnLayer( const AARC6& aElem, PCB_LAYER_ID aLayer )
|
|
|
|
{
|
|
|
|
if( IsCopperLayer( aLayer ) && aElem.net != ALTIUM_NET_UNCONNECTED )
|
|
|
|
{
|
2022-01-25 21:24:01 +00:00
|
|
|
// TODO: This is not the actual board item. We use it for now to calculate the arc points. This could be improved!
|
|
|
|
PCB_SHAPE shape( nullptr, SHAPE_T::ARC );
|
2022-01-14 15:34:41 +00:00
|
|
|
|
2022-01-25 21:24:01 +00:00
|
|
|
EDA_ANGLE includedAngle( aElem.endangle - aElem.startangle, DEGREES_T );
|
2022-01-16 11:22:00 +00:00
|
|
|
EDA_ANGLE startAngle( aElem.endangle, DEGREES_T );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-25 21:24:01 +00:00
|
|
|
VECTOR2I startOffset = VECTOR2I( KiROUND( startAngle.Cos() * aElem.radius ),
|
|
|
|
-KiROUND( startAngle.Sin() * aElem.radius ) );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2022-01-25 21:24:01 +00:00
|
|
|
shape.SetCenter( aElem.center );
|
|
|
|
shape.SetStart( aElem.center + startOffset );
|
|
|
|
shape.SetArcAngleAndEnd( includedAngle.Normalize(), true );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2022-01-25 21:24:01 +00:00
|
|
|
// Create actual arc
|
|
|
|
SHAPE_ARC shapeArc( shape.GetCenter(), shape.GetStart(), shape.GetArcAngle(), aElem.width );
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_ARC> arc = std::make_unique<PCB_ARC>( m_board, &shapeArc );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
arc->SetWidth( aElem.width );
|
|
|
|
arc->SetLayer( aLayer );
|
|
|
|
arc->SetNetCode( GetNetCode( aElem.net ) );
|
2021-07-24 13:23:55 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( arc.release(), ADD_MODE::APPEND );
|
2022-01-10 19:45:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> arc = std::make_unique<PCB_SHAPE>( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
ConvertArcs6ToPcbShape( aElem, arc.get() );
|
2023-11-25 13:05:45 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
2022-01-10 19:45:42 +00:00
|
|
|
arc->SetLayer( aLayer );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( arc.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-10 19:45:42 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
|
|
|
|
void ALTIUM_PCB::ConvertArcs6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, const AARC6& aElem,
|
|
|
|
PCB_LAYER_ID aLayer )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> arc = std::make_unique<PCB_SHAPE>( aFootprint );
|
2022-01-10 19:45:42 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
ConvertArcs6ToPcbShape( aElem, arc.get() );
|
2023-11-25 13:05:45 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
2022-01-10 19:45:42 +00:00
|
|
|
arc->SetLayer( aLayer );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( arc.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParsePads6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-10-04 23:34:59 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading pads..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
APAD6 elem( reader );
|
|
|
|
|
|
|
|
if( elem.component == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2022-01-16 14:37:25 +00:00
|
|
|
ConvertPads6ToBoardItem( elem );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-16 14:37:25 +00:00
|
|
|
FOOTPRINT* footprint = HelperGetFootprint( elem.component );
|
|
|
|
ConvertPads6ToFootprintItem( footprint, elem );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-16 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Pads6 stream is not fully parsed" ) );
|
2022-01-16 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ALTIUM_PCB::ConvertPads6ToBoardItem( const APAD6& aElem )
|
|
|
|
{
|
|
|
|
// It is possible to place altium pads on non-copper layers -> we need to interpolate them using drawings!
|
|
|
|
if( !IsAltiumLayerCopper( aElem.layer ) && !IsAltiumLayerAPlane( aElem.layer )
|
|
|
|
&& aElem.layer != ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
ConvertPads6ToBoardItemOnNonCopper( aElem );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We cannot add a pad directly into the PCB
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( m_board );
|
2022-01-16 14:37:25 +00:00
|
|
|
footprint->SetPosition( aElem.position );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
ConvertPads6ToFootprintItemOnCopper( footprint.get(), aElem );
|
2022-01-16 14:37:25 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( footprint.release(), ADD_MODE::APPEND );
|
2022-01-16 14:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ALTIUM_PCB::ConvertPads6ToFootprintItem( FOOTPRINT* aFootprint, const APAD6& aElem )
|
|
|
|
{
|
|
|
|
// It is possible to place altium pads on non-copper layers -> we need to interpolate them using drawings!
|
|
|
|
if( !IsAltiumLayerCopper( aElem.layer ) && !IsAltiumLayerAPlane( aElem.layer )
|
|
|
|
&& aElem.layer != ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
ConvertPads6ToFootprintItemOnNonCopper( aFootprint, aElem );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConvertPads6ToFootprintItemOnCopper( aFootprint, aElem );
|
|
|
|
}
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
void ALTIUM_PCB::ConvertPads6ToFootprintItemOnCopper( FOOTPRINT* aFootprint, const APAD6& aElem )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PAD> pad = std::make_unique<PAD>( aFootprint );
|
2022-01-16 14:37:25 +00:00
|
|
|
|
2022-02-12 15:45:35 +00:00
|
|
|
pad->SetKeepTopBottom( false ); // TODO: correct? This seems to be KiCad default on import
|
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetNumber( aElem.name );
|
|
|
|
pad->SetNetCode( GetNetCode( aElem.net ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetPosition( aElem.position );
|
|
|
|
pad->SetOrientationDegrees( aElem.direction );
|
|
|
|
pad->SetSize( aElem.topsize );
|
2024-04-27 17:25:47 +00:00
|
|
|
pad->SetThermalSpokeAngle( ANGLE_90 );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
if( aElem.holesize == 0 )
|
|
|
|
{
|
|
|
|
pad->SetAttribute( PAD_ATTRIB::SMD );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aElem.layer != ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
// TODO: I assume other values are possible as well?
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s pad %s is not marked as multilayer, but is a TH pad." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.name );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s pad %s is not marked as multilayer, but is a TH pad." ),
|
2024-02-19 12:24:13 +00:00
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.name );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
2022-01-16 14:37:25 +00:00
|
|
|
}
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetAttribute( aElem.plated ? PAD_ATTRIB::PTH : PAD_ATTRIB::NPTH );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
if( !aElem.sizeAndShape || aElem.sizeAndShape->holeshape == ALTIUM_PAD_HOLE_SHAPE::ROUND )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_CIRCLE );
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetDrillSize( VECTOR2I( aElem.holesize, aElem.holesize ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-16 14:37:25 +00:00
|
|
|
switch( aElem.sizeAndShape->holeshape )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-16 14:37:25 +00:00
|
|
|
case ALTIUM_PAD_HOLE_SHAPE::ROUND:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Round holes are handled before the switch" ) );
|
2022-01-16 14:37:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_PAD_HOLE_SHAPE::SQUARE:
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s pad %s has a square hole (not yet supported)." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.name );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s pad %s has a square hole (not yet supported)." ),
|
2024-02-19 12:24:13 +00:00
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.name );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_CIRCLE );
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetDrillSize( VECTOR2I( aElem.holesize, aElem.holesize ) ); // Workaround
|
2022-03-22 10:23:29 +00:00
|
|
|
// TODO: elem.sizeAndShape->slotsize was 0 in testfile. Either use holesize in
|
|
|
|
// this case or rect holes have a different id
|
2022-01-16 14:37:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_PAD_HOLE_SHAPE::SLOT:
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_OBLONG );
|
|
|
|
EDA_ANGLE slotRotation( aElem.sizeAndShape->slotrotation, DEGREES_T );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
slotRotation.Normalize();
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-03-22 18:06:43 +00:00
|
|
|
if( slotRotation.IsHorizontal() )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetDrillSize( VECTOR2I( aElem.sizeAndShape->slotsize, aElem.holesize ) );
|
2022-01-16 14:37:25 +00:00
|
|
|
}
|
2022-03-22 18:06:43 +00:00
|
|
|
else if( slotRotation.IsVertical() )
|
2022-01-16 14:37:25 +00:00
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetDrillSize( VECTOR2I( aElem.holesize, aElem.sizeAndShape->slotsize ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-03-22 18:06:43 +00:00
|
|
|
else
|
|
|
|
{
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s pad %s has a hole-rotation of %f degrees. "
|
|
|
|
"KiCad only supports 90 degree rotations." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.name,
|
|
|
|
slotRotation.AsDegrees() );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s pad %s has a hole-rotation of %f degrees. "
|
2024-02-19 12:24:13 +00:00
|
|
|
"KiCad only supports 90 degree rotations." ),
|
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.name,
|
|
|
|
slotRotation.AsDegrees() );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
2022-03-22 18:06:43 +00:00
|
|
|
}
|
|
|
|
|
2022-03-22 10:23:29 +00:00
|
|
|
break;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2020-05-06 07:17:43 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
default:
|
|
|
|
case ALTIUM_PAD_HOLE_SHAPE::UNKNOWN:
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s pad %s uses a hole of unknown kind %d." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.name,
|
|
|
|
aElem.sizeAndShape->holeshape );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s pad %s uses a hole of unknown kind %d." ),
|
2024-02-19 12:24:13 +00:00
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.name,
|
|
|
|
aElem.sizeAndShape->holeshape );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_CIRCLE );
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetDrillSize( VECTOR2I( aElem.holesize, aElem.holesize ) ); // Workaround
|
2022-01-16 14:37:25 +00:00
|
|
|
break;
|
2020-05-06 07:17:43 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
if( aElem.sizeAndShape )
|
|
|
|
pad->SetOffset( aElem.sizeAndShape->holeoffset[0] );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
if( aElem.padmode != ALTIUM_PAD_MODE::SIMPLE )
|
|
|
|
{
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s pad %s uses a complex pad stack (not yet supported)." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.name );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s pad %s uses a complex pad stack (not yet supported)." ),
|
2024-02-19 12:24:13 +00:00
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.name );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
2022-01-16 14:37:25 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
switch( aElem.topshape )
|
|
|
|
{
|
2022-03-22 10:23:29 +00:00
|
|
|
case ALTIUM_PAD_SHAPE::RECT:
|
2023-06-02 09:10:48 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECTANGLE );
|
2022-03-22 10:23:29 +00:00
|
|
|
break;
|
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
case ALTIUM_PAD_SHAPE::CIRCLE:
|
|
|
|
if( aElem.sizeAndShape
|
|
|
|
&& aElem.sizeAndShape->alt_shape[0] == ALTIUM_PAD_SHAPE_ALT::ROUNDRECT )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::ROUNDRECT ); // 100 = round, 0 = rectangular
|
|
|
|
double ratio = aElem.sizeAndShape->cornerradius[0] / 200.;
|
|
|
|
pad->SetRoundRectRadiusRatio( ratio );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-16 14:37:25 +00:00
|
|
|
else if( aElem.topsize.x == aElem.topsize.y )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CIRCLE );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-16 14:37:25 +00:00
|
|
|
else
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::OVAL );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-03-22 18:06:43 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
break;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
case ALTIUM_PAD_SHAPE::OCTAGONAL:
|
|
|
|
pad->SetShape( PAD_SHAPE::CHAMFERED_RECT );
|
|
|
|
pad->SetChamferPositions( RECT_CHAMFER_ALL );
|
|
|
|
pad->SetChamferRectRatio( 0.25 );
|
|
|
|
break;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
case ALTIUM_PAD_SHAPE::UNKNOWN:
|
|
|
|
default:
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s pad %s uses an unknown pad-shape." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.name );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s pad %s uses an unknown pad-shape." ),
|
2024-02-19 12:24:13 +00:00
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.name );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
2022-01-16 14:37:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-07-15 15:14:11 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB::NPTH && pad->HasHole() )
|
2022-03-22 18:06:43 +00:00
|
|
|
{
|
|
|
|
// KiCad likes NPTH pads to be the same size & shape as their holes
|
|
|
|
pad->SetShape( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE ? PAD_SHAPE::CIRCLE
|
|
|
|
: PAD_SHAPE::OVAL );
|
|
|
|
pad->SetSize( pad->GetDrillSize() );
|
|
|
|
}
|
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
switch( aElem.layer )
|
|
|
|
{
|
|
|
|
case ALTIUM_LAYER::TOP_LAYER:
|
|
|
|
pad->SetLayer( F_Cu );
|
|
|
|
pad->SetLayerSet( PAD::SMDMask() );
|
|
|
|
break;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
case ALTIUM_LAYER::BOTTOM_LAYER:
|
|
|
|
pad->SetLayer( B_Cu );
|
|
|
|
pad->SetLayerSet( FlipLayerMask( PAD::SMDMask() ) );
|
|
|
|
break;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
case ALTIUM_LAYER::MULTI_LAYER:
|
|
|
|
pad->SetLayerSet( aElem.plated ? PAD::PTHMask() : PAD::UnplatedHoleMask() );
|
|
|
|
break;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
default:
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
|
|
|
pad->SetLayer( klayer );
|
|
|
|
pad->SetLayerSet( LSET( 1, klayer ) );
|
|
|
|
break;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
if( aElem.pastemaskexpansionmode == ALTIUM_MODE::MANUAL )
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetLocalSolderPasteMargin( aElem.pastemaskexpansionmanual );
|
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
if( aElem.soldermaskexpansionmode == ALTIUM_MODE::MANUAL )
|
2022-01-16 14:37:25 +00:00
|
|
|
pad->SetLocalSolderMaskMargin( aElem.soldermaskexpansionmanual );
|
|
|
|
|
|
|
|
if( aElem.is_tent_top )
|
|
|
|
pad->SetLayerSet( pad->GetLayerSet().reset( F_Mask ) );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
if( aElem.is_tent_bottom )
|
|
|
|
pad->SetLayerSet( pad->GetLayerSet().reset( B_Mask ) );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( pad.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
void ALTIUM_PCB::ConvertPads6ToBoardItemOnNonCopper( const APAD6& aElem )
|
2020-04-18 21:47:53 +00:00
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Non-copper pad %s found on an Altium layer (%d) with no KiCad "
|
2022-02-05 02:06:25 +00:00
|
|
|
"equivalent. It has been moved to KiCad layer Eco1_User." ),
|
|
|
|
aElem.name, aElem.layer );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> pad = std::make_unique<PCB_SHAPE>( m_board );
|
2022-01-16 14:37:25 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
HelperParsePad6NonCopper( aElem, klayer, pad.get() );
|
2022-01-16 14:37:25 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( pad.release(), ADD_MODE::APPEND );
|
2022-01-16 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ALTIUM_PCB::ConvertPads6ToFootprintItemOnNonCopper( FOOTPRINT* aFootprint, const APAD6& aElem )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
|
|
|
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s non-copper pad %s found on an Altium layer (%d) with no "
|
|
|
|
"KiCad equivalent. It has been moved to KiCad layer Eco1_User." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.name,
|
|
|
|
aElem.layer );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s non-copper pad %s found on an Altium layer (%d) with no "
|
2024-02-19 12:24:13 +00:00
|
|
|
"KiCad equivalent. It has been moved to KiCad layer Eco1_User." ),
|
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.name,
|
|
|
|
aElem.layer );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> pad = std::make_unique<PCB_SHAPE>( aFootprint );
|
2022-01-16 14:37:25 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
HelperParsePad6NonCopper( aElem, klayer, pad.get() );
|
2022-01-16 14:37:25 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( pad.release(), ADD_MODE::APPEND );
|
2022-01-16 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ALTIUM_PCB::HelperParsePad6NonCopper( const APAD6& aElem, PCB_LAYER_ID aLayer,
|
|
|
|
PCB_SHAPE* aShape )
|
|
|
|
{
|
2020-04-18 21:47:53 +00:00
|
|
|
if( aElem.net != ALTIUM_NET_UNCONNECTED )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Non-copper pad %s is connected to a net, which is not supported." ),
|
2021-06-26 19:21:30 +00:00
|
|
|
aElem.name );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.holesize != 0 )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Non-copper pad %s has a hole, which is not supported." ), aElem.name );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.padmode != ALTIUM_PAD_MODE::SIMPLE )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Non-copper pad %s has a complex pad stack (not yet supported)." ),
|
|
|
|
aElem.name );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( aElem.topshape )
|
|
|
|
{
|
|
|
|
case ALTIUM_PAD_SHAPE::RECT:
|
|
|
|
{
|
|
|
|
// filled rect
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetShape( SHAPE_T::POLY );
|
|
|
|
aShape->SetFilled( true );
|
|
|
|
aShape->SetLayer( aLayer );
|
|
|
|
aShape->SetStroke( STROKE_PARAMS( 0 ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetPolyPoints(
|
|
|
|
{ aElem.position + VECTOR2I( aElem.topsize.x / 2, aElem.topsize.y / 2 ),
|
|
|
|
aElem.position + VECTOR2I( aElem.topsize.x / 2, -aElem.topsize.y / 2 ),
|
|
|
|
aElem.position + VECTOR2I( -aElem.topsize.x / 2, -aElem.topsize.y / 2 ),
|
|
|
|
aElem.position + VECTOR2I( -aElem.topsize.x / 2, aElem.topsize.y / 2 ) } );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
|
|
|
if( aElem.direction != 0 )
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->Rotate( aElem.position, EDA_ANGLE( aElem.direction, DEGREES_T ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
case ALTIUM_PAD_SHAPE::CIRCLE:
|
|
|
|
if( aElem.sizeAndShape
|
|
|
|
&& aElem.sizeAndShape->alt_shape[0] == ALTIUM_PAD_SHAPE_ALT::ROUNDRECT )
|
|
|
|
{
|
|
|
|
// filled roundrect
|
|
|
|
int cornerradius = aElem.sizeAndShape->cornerradius[0];
|
|
|
|
int offset = ( std::min( aElem.topsize.x, aElem.topsize.y ) * cornerradius ) / 200;
|
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetLayer( aLayer );
|
2023-11-25 13:05:45 +00:00
|
|
|
aShape->SetStroke( STROKE_PARAMS( offset * 2, LINE_STYLE::SOLID ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
|
|
|
if( cornerradius < 100 )
|
|
|
|
{
|
|
|
|
int offsetX = aElem.topsize.x / 2 - offset;
|
|
|
|
int offsetY = aElem.topsize.y / 2 - offset;
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I p11 = aElem.position + VECTOR2I( offsetX, offsetY );
|
|
|
|
VECTOR2I p12 = aElem.position + VECTOR2I( offsetX, -offsetY );
|
|
|
|
VECTOR2I p22 = aElem.position + VECTOR2I( -offsetX, -offsetY );
|
|
|
|
VECTOR2I p21 = aElem.position + VECTOR2I( -offsetX, offsetY );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetShape( SHAPE_T::POLY );
|
|
|
|
aShape->SetFilled( true );
|
|
|
|
aShape->SetPolyPoints( { p11, p12, p22, p21 } );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else if( aElem.topsize.x == aElem.topsize.y )
|
|
|
|
{
|
|
|
|
// circle
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetShape( SHAPE_T::CIRCLE );
|
|
|
|
aShape->SetFilled( true );
|
|
|
|
aShape->SetStart( aElem.position );
|
|
|
|
aShape->SetEnd( aElem.position - VECTOR2I( 0, aElem.topsize.x / 4 ) );
|
2023-11-25 13:05:45 +00:00
|
|
|
aShape->SetStroke( STROKE_PARAMS( aElem.topsize.x / 2, LINE_STYLE::SOLID ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else if( aElem.topsize.x < aElem.topsize.y )
|
|
|
|
{
|
|
|
|
// short vertical line
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetShape( SHAPE_T::SEGMENT );
|
2022-01-01 18:57:44 +00:00
|
|
|
VECTOR2I pointOffset( 0, ( aElem.topsize.y - aElem.topsize.x ) / 2 );
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetStart( aElem.position + pointOffset );
|
|
|
|
aShape->SetEnd( aElem.position - pointOffset );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// short horizontal line
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetShape( SHAPE_T::SEGMENT );
|
2022-01-01 18:57:44 +00:00
|
|
|
VECTOR2I pointOffset( ( aElem.topsize.x - aElem.topsize.y ) / 2, 0 );
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetStart( aElem.position + pointOffset );
|
|
|
|
aShape->SetEnd( aElem.position - pointOffset );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.direction != 0 )
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->Rotate( aElem.position, EDA_ANGLE( aElem.direction, DEGREES_T ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else if( aElem.topsize.x == aElem.topsize.y )
|
|
|
|
{
|
|
|
|
// filled circle
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetShape( SHAPE_T::CIRCLE );
|
|
|
|
aShape->SetFilled( true );
|
|
|
|
aShape->SetLayer( aLayer );
|
|
|
|
aShape->SetStart( aElem.position );
|
|
|
|
aShape->SetEnd( aElem.position - VECTOR2I( 0, aElem.topsize.x / 4 ) );
|
2023-11-25 13:05:45 +00:00
|
|
|
aShape->SetStroke( STROKE_PARAMS( aElem.topsize.x / 2, LINE_STYLE::SOLID ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// short line
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetShape( SHAPE_T::SEGMENT );
|
|
|
|
aShape->SetLayer( aLayer );
|
|
|
|
aShape->SetStroke( STROKE_PARAMS( std::min( aElem.topsize.x, aElem.topsize.y ),
|
2023-11-25 13:05:45 +00:00
|
|
|
LINE_STYLE::SOLID ) );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
if( aElem.topsize.x < aElem.topsize.y )
|
|
|
|
{
|
2022-01-01 18:57:44 +00:00
|
|
|
VECTOR2I offset( 0, ( aElem.topsize.y - aElem.topsize.x ) / 2 );
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetStart( aElem.position + offset );
|
|
|
|
aShape->SetEnd( aElem.position - offset );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 18:57:44 +00:00
|
|
|
VECTOR2I offset( ( aElem.topsize.x - aElem.topsize.y ) / 2, 0 );
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetStart( aElem.position + offset );
|
|
|
|
aShape->SetEnd( aElem.position - offset );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
if( aElem.direction != 0 )
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->Rotate( aElem.position, EDA_ANGLE( aElem.direction, DEGREES_T ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
case ALTIUM_PAD_SHAPE::OCTAGONAL:
|
|
|
|
{
|
|
|
|
// filled octagon
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetShape( SHAPE_T::POLY );
|
|
|
|
aShape->SetFilled( true );
|
|
|
|
aShape->SetLayer( aLayer );
|
|
|
|
aShape->SetStroke( STROKE_PARAMS( 0 ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2022-01-11 00:49:49 +00:00
|
|
|
VECTOR2I p11 = aElem.position + VECTOR2I( aElem.topsize.x / 2, aElem.topsize.y / 2 );
|
|
|
|
VECTOR2I p12 = aElem.position + VECTOR2I( aElem.topsize.x / 2, -aElem.topsize.y / 2 );
|
|
|
|
VECTOR2I p22 = aElem.position + VECTOR2I( -aElem.topsize.x / 2, -aElem.topsize.y / 2 );
|
|
|
|
VECTOR2I p21 = aElem.position + VECTOR2I( -aElem.topsize.x / 2, aElem.topsize.y / 2 );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
|
|
|
int chamfer = std::min( aElem.topsize.x, aElem.topsize.y ) / 4;
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I chamferX( chamfer, 0 );
|
|
|
|
VECTOR2I chamferY( 0, chamfer );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->SetPolyPoints( { p11 - chamferX, p11 - chamferY, p12 + chamferY, p12 - chamferX,
|
|
|
|
p22 + chamferX, p22 + chamferY, p21 - chamferY, p21 + chamferX } );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
|
|
|
if( aElem.direction != 0. )
|
2022-01-16 14:37:25 +00:00
|
|
|
aShape->Rotate( aElem.position, EDA_ANGLE( aElem.direction, DEGREES_T ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
break;
|
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
case ALTIUM_PAD_SHAPE::UNKNOWN:
|
|
|
|
default:
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Non-copper pad %s uses an unknown pad-shape." ), aElem.name );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 14:37:25 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseVias6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-10-04 23:34:59 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading vias..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
AVIA6 elem( reader );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_VIA> via = std::make_unique<PCB_VIA>( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
via->SetPosition( elem.position );
|
|
|
|
via->SetWidth( elem.diameter );
|
|
|
|
via->SetDrill( elem.holesize );
|
|
|
|
via->SetNetCode( GetNetCode( elem.net ) );
|
|
|
|
via->SetLocked( elem.is_locked );
|
|
|
|
|
|
|
|
bool start_layer_outside = elem.layer_start == ALTIUM_LAYER::TOP_LAYER
|
|
|
|
|| elem.layer_start == ALTIUM_LAYER::BOTTOM_LAYER;
|
|
|
|
bool end_layer_outside = elem.layer_end == ALTIUM_LAYER::TOP_LAYER
|
|
|
|
|| elem.layer_end == ALTIUM_LAYER::BOTTOM_LAYER;
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( start_layer_outside && end_layer_outside )
|
|
|
|
{
|
|
|
|
via->SetViaType( VIATYPE::THROUGH );
|
|
|
|
}
|
|
|
|
else if( ( !start_layer_outside ) && ( !end_layer_outside ) )
|
|
|
|
{
|
|
|
|
via->SetViaType( VIATYPE::BLIND_BURIED );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
via->SetViaType( VIATYPE::MICROVIA ); // TODO: always a microvia?
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_LAYER_ID start_klayer = GetKicadLayer( elem.layer_start );
|
|
|
|
PCB_LAYER_ID end_klayer = GetKicadLayer( elem.layer_end );
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( !IsCopperLayer( start_klayer ) || !IsCopperLayer( end_klayer ) )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Via from layer %d to %d uses a non-copper layer, which is not "
|
|
|
|
"supported." ),
|
2021-06-26 19:21:30 +00:00
|
|
|
elem.layer_start,
|
|
|
|
elem.layer_end );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
continue; // just assume through-hole instead.
|
|
|
|
}
|
|
|
|
|
|
|
|
// we need VIATYPE set!
|
|
|
|
via->SetLayerPair( start_klayer, end_klayer );
|
2024-03-30 23:03:03 +00:00
|
|
|
|
|
|
|
m_board->Add( via.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Vias6 stream is not fully parsed" ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseTracks6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-10-04 23:34:59 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading tracks..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
for( int primitiveIndex = 0; reader.GetRemainingBytes() >= 4; primitiveIndex++ )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
ATRACK6 elem( reader );
|
|
|
|
|
2022-01-10 16:45:37 +00:00
|
|
|
if( elem.component == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2022-02-20 19:18:22 +00:00
|
|
|
ConvertTracks6ToBoardItem( elem, primitiveIndex );
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FOOTPRINT* footprint = HelperGetFootprint( elem.component );
|
2022-02-20 19:18:22 +00:00
|
|
|
ConvertTracks6ToFootprintItem( footprint, elem, primitiveIndex, true );
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-10 16:45:37 +00:00
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
THROW_IO_ERROR( "Tracks6 stream is not fully parsed" );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
void ALTIUM_PCB::ConvertTracks6ToBoardItem( const ATRACK6& aElem, const int aPrimitiveIndex )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
2024-02-01 09:14:51 +00:00
|
|
|
if( aElem.polygon != ALTIUM_POLYGON_NONE && aElem.polygon != ALTIUM_POLYGON_BOARD )
|
2023-11-25 21:23:34 +00:00
|
|
|
{
|
|
|
|
if( m_polygons.size() <= aElem.polygon )
|
|
|
|
{
|
2024-01-07 11:56:37 +00:00
|
|
|
// Can happen when reading old Altium files: just skip this item
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "ATRACK6 stream tries to access polygon id %u "
|
|
|
|
"of %u existing polygons; skipping it" ),
|
|
|
|
static_cast<unsigned>( aElem.polygon ),
|
|
|
|
static_cast<unsigned>( m_polygons.size() ) );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
|
|
|
|
2024-01-07 11:56:37 +00:00
|
|
|
return;
|
2023-11-25 21:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ZONE* zone = m_polygons.at( aElem.polygon );
|
|
|
|
|
|
|
|
if( zone == nullptr )
|
|
|
|
{
|
|
|
|
return; // we know the zone id, but because we do not know the layer we did not
|
|
|
|
// add it!
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
|
|
|
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
return; // Just skip it for now. Users can fill it themselves.
|
|
|
|
|
|
|
|
SHAPE_POLY_SET* fill = zone->GetFill( klayer );
|
|
|
|
|
|
|
|
PCB_SHAPE shape( nullptr, SHAPE_T::SEGMENT );
|
|
|
|
shape.SetStart( aElem.start );
|
|
|
|
shape.SetEnd( aElem.end );
|
|
|
|
shape.SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
|
|
|
|
|
|
|
shape.EDA_SHAPE::TransformShapeToPolygon( *fill, 0, ARC_HIGH_DEF, ERROR_INSIDE );
|
|
|
|
// Will be simplified and fractured later
|
|
|
|
|
|
|
|
zone->SetIsFilled( true );
|
|
|
|
zone->SetNeedRefill( false );
|
|
|
|
|
2022-01-10 16:45:37 +00:00
|
|
|
return;
|
2023-11-25 21:23:34 +00:00
|
|
|
}
|
2022-01-10 16:45:37 +00:00
|
|
|
|
2022-04-02 16:04:45 +00:00
|
|
|
if( aElem.is_keepout || aElem.layer == ALTIUM_LAYER::KEEP_OUT_LAYER
|
|
|
|
|| IsAltiumLayerAPlane( aElem.layer ) )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
|
|
|
// This is not the actual board item. We can use it to create the polygon for the region
|
|
|
|
PCB_SHAPE shape( nullptr, SHAPE_T::SEGMENT );
|
|
|
|
shape.SetStart( aElem.start );
|
|
|
|
shape.SetEnd( aElem.end );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape.SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
2022-03-07 18:58:43 +00:00
|
|
|
HelperPcpShapeAsBoardKeepoutRegion( shape, aElem.layer, aElem.keepoutrestrictions );
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
2022-01-10 19:45:42 +00:00
|
|
|
ConvertTracks6ToBoardItemOnLayer( aElem, klayer );
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
2022-02-20 19:18:22 +00:00
|
|
|
|
2023-06-15 21:57:05 +00:00
|
|
|
for( const auto& layerExpansionMask : HelperGetSolderAndPasteMaskExpansions(
|
2022-02-20 19:18:22 +00:00
|
|
|
ALTIUM_RECORD::TRACK, aPrimitiveIndex, aElem.layer ) )
|
|
|
|
{
|
|
|
|
int width = aElem.width + ( layerExpansionMask.second * 2 );
|
|
|
|
if( width > 1 )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> seg = std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::SEGMENT );
|
2022-02-20 19:18:22 +00:00
|
|
|
|
|
|
|
seg->SetStart( aElem.start );
|
|
|
|
seg->SetEnd( aElem.end );
|
2023-11-25 13:05:45 +00:00
|
|
|
seg->SetStroke( STROKE_PARAMS( width, LINE_STYLE::SOLID ) );
|
2022-02-20 19:18:22 +00:00
|
|
|
seg->SetLayer( layerExpansionMask.first );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( seg.release(), ADD_MODE::APPEND );
|
2022-02-20 19:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-10-20 08:35:58 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
void ALTIUM_PCB::ConvertTracks6ToFootprintItem( FOOTPRINT* aFootprint, const ATRACK6& aElem,
|
2022-02-20 19:18:22 +00:00
|
|
|
const int aPrimitiveIndex,
|
2022-01-10 19:45:42 +00:00
|
|
|
const bool aIsBoardImport )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
2023-11-25 21:23:34 +00:00
|
|
|
if( aElem.polygon != ALTIUM_POLYGON_NONE )
|
|
|
|
{
|
2024-01-07 11:56:37 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( "Altium: Unexpected footprint Track with polygon id %u",
|
|
|
|
(unsigned)aElem.polygon ) );
|
2022-01-10 16:45:37 +00:00
|
|
|
return;
|
2023-11-25 21:23:34 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-04-02 16:04:45 +00:00
|
|
|
if( aElem.is_keepout || aElem.layer == ALTIUM_LAYER::KEEP_OUT_LAYER
|
|
|
|
|| IsAltiumLayerAPlane( aElem.layer ) )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
|
|
|
// This is not the actual board item. We can use it to create the polygon for the region
|
|
|
|
PCB_SHAPE shape( nullptr, SHAPE_T::SEGMENT );
|
|
|
|
shape.SetStart( aElem.start );
|
|
|
|
shape.SetEnd( aElem.end );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape.SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
2022-03-07 18:58:43 +00:00
|
|
|
HelperPcpShapeAsFootprintKeepoutRegion( aFootprint, shape, aElem.layer,
|
|
|
|
aElem.keepoutrestrictions );
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
|
|
|
{
|
2022-01-10 19:45:42 +00:00
|
|
|
if( aIsBoardImport && IsCopperLayer( klayer ) && aElem.net != ALTIUM_NET_UNCONNECTED )
|
2020-10-20 08:35:58 +00:00
|
|
|
{
|
2022-01-10 16:45:37 +00:00
|
|
|
// Special case: do to not lose net connections in footprints
|
2022-01-10 19:45:42 +00:00
|
|
|
ConvertTracks6ToBoardItemOnLayer( aElem, klayer );
|
2020-10-20 08:35:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-10 19:45:42 +00:00
|
|
|
ConvertTracks6ToFootprintItemOnLayer( aFootprint, aElem, klayer );
|
2020-10-20 08:35:58 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
2022-02-20 19:18:22 +00:00
|
|
|
|
2023-06-15 21:57:05 +00:00
|
|
|
for( const auto& layerExpansionMask : HelperGetSolderAndPasteMaskExpansions(
|
2022-02-20 19:18:22 +00:00
|
|
|
ALTIUM_RECORD::TRACK, aPrimitiveIndex, aElem.layer ) )
|
|
|
|
{
|
|
|
|
int width = aElem.width + ( layerExpansionMask.second * 2 );
|
|
|
|
if( width > 1 )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> seg = std::make_unique<PCB_SHAPE>( aFootprint, SHAPE_T::SEGMENT );
|
2022-02-20 19:18:22 +00:00
|
|
|
|
|
|
|
seg->SetStart( aElem.start );
|
|
|
|
seg->SetEnd( aElem.end );
|
2023-11-25 13:05:45 +00:00
|
|
|
seg->SetStroke( STROKE_PARAMS( width, LINE_STYLE::SOLID ) );
|
2022-02-20 19:18:22 +00:00
|
|
|
seg->SetLayer( layerExpansionMask.first );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( seg.release(), ADD_MODE::APPEND );
|
2022-02-20 19:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-10-20 08:35:58 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
void ALTIUM_PCB::ConvertTracks6ToBoardItemOnLayer( const ATRACK6& aElem, PCB_LAYER_ID aLayer )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
|
|
|
if( IsCopperLayer( aLayer ) && aElem.net != ALTIUM_NET_UNCONNECTED )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_TRACK> track = std::make_unique<PCB_TRACK>( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-10 16:45:37 +00:00
|
|
|
track->SetStart( aElem.start );
|
|
|
|
track->SetEnd( aElem.end );
|
|
|
|
track->SetWidth( aElem.width );
|
|
|
|
track->SetLayer( aLayer );
|
|
|
|
track->SetNetCode( GetNetCode( aElem.net ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( track.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-10 16:45:37 +00:00
|
|
|
else
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> seg = std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::SEGMENT );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
|
|
|
seg->SetStart( aElem.start );
|
|
|
|
seg->SetEnd( aElem.end );
|
2023-11-25 13:05:45 +00:00
|
|
|
seg->SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
2022-01-10 16:45:37 +00:00
|
|
|
seg->SetLayer( aLayer );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( seg.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-10 16:45:37 +00:00
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
void ALTIUM_PCB::ConvertTracks6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, const ATRACK6& aElem,
|
|
|
|
PCB_LAYER_ID aLayer )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> seg = std::make_unique<PCB_SHAPE>( aFootprint, SHAPE_T::SEGMENT );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
|
|
|
seg->SetStart( aElem.start );
|
|
|
|
seg->SetEnd( aElem.end );
|
2023-11-25 13:05:45 +00:00
|
|
|
seg->SetStroke( STROKE_PARAMS( aElem.width, LINE_STYLE::SOLID ) );
|
2022-01-10 16:45:37 +00:00
|
|
|
seg->SetLayer( aLayer );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( seg.release(), ADD_MODE::APPEND );
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseWideStrings6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2021-11-10 16:46:01 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
|
|
|
{
|
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->Report( _( "Loading unicode strings..." ) );
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2022-01-01 06:04:08 +00:00
|
|
|
|
2021-11-10 16:46:01 +00:00
|
|
|
m_unicodeStrings = reader.ReadWideStringTable();
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "WideStrings6 stream is not fully parsed" ) );
|
2021-11-10 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseTexts6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading text..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2021-11-10 16:46:01 +00:00
|
|
|
ATEXT6 elem( reader, m_unicodeStrings );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
if( elem.component == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2022-01-16 13:40:23 +00:00
|
|
|
ConvertTexts6ToBoardItem( elem );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-16 13:40:23 +00:00
|
|
|
FOOTPRINT* footprint = HelperGetFootprint( elem.component );
|
|
|
|
ConvertTexts6ToFootprintItem( footprint, elem );
|
|
|
|
}
|
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Texts6 stream is not fully parsed" ) );
|
2022-01-16 13:40:23 +00:00
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
void ALTIUM_PCB::ConvertTexts6ToBoardItem( const ATEXT6& aElem )
|
|
|
|
{
|
|
|
|
if( aElem.fonttype == ALTIUM_TEXT_TYPE::BARCODE )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Ignored barcode on Altium layer %d (not yet supported)." ),
|
|
|
|
aElem.layer );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-10 15:27:29 +00:00
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
|
|
|
ConvertTexts6ToBoardItemOnLayer( aElem, klayer );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
void ALTIUM_PCB::ConvertTexts6ToFootprintItem( FOOTPRINT* aFootprint, const ATEXT6& aElem )
|
|
|
|
{
|
|
|
|
if( aElem.fonttype == ALTIUM_TEXT_TYPE::BARCODE )
|
|
|
|
{
|
2024-02-19 12:24:13 +00:00
|
|
|
if( !m_footprintName.IsEmpty() )
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error loading library '%s':\n"
|
2024-02-19 12:24:13 +00:00
|
|
|
"Footprint %s contains barcode on Altium layer %d (not yet supported)." ),
|
|
|
|
m_library,
|
|
|
|
m_footprintName,
|
|
|
|
aElem.layer );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 01:21:48 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Footprint %s contains barcode on Altium layer %d (not yet supported)." ),
|
2024-02-19 12:24:13 +00:00
|
|
|
aFootprint->GetReference(),
|
|
|
|
aElem.layer );
|
2024-05-01 01:21:48 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_DEBUG );
|
|
|
|
}
|
2024-02-19 12:24:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-04 11:41:45 +00:00
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
|
|
|
ConvertTexts6ToFootprintItemOnLayer( aFootprint, aElem, klayer );
|
|
|
|
}
|
2020-04-04 11:41:45 +00:00
|
|
|
|
2020-11-15 21:41:38 +00:00
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
void ALTIUM_PCB::ConvertTexts6ToBoardItemOnLayer( const ATEXT6& aElem, PCB_LAYER_ID aLayer )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_TEXT> pcbText = std::make_unique<PCB_TEXT>( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2023-10-01 13:10:09 +00:00
|
|
|
static const std::map<wxString, wxString> variableMap = {
|
|
|
|
{ "LAYER_NAME", "LAYER" },
|
|
|
|
{ "PRINT_DATE", "CURRENT_DATE"},
|
|
|
|
};
|
2022-02-05 02:06:25 +00:00
|
|
|
|
2023-10-01 13:10:09 +00:00
|
|
|
wxString kicadText = AltiumPcbSpecialStringsToKiCadStrings( aElem.text, variableMap );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2023-10-01 13:10:09 +00:00
|
|
|
pcbText->SetText(kicadText);
|
2022-01-16 13:40:23 +00:00
|
|
|
pcbText->SetLayer( aLayer );
|
|
|
|
pcbText->SetPosition( aElem.position );
|
|
|
|
pcbText->SetTextAngle( EDA_ANGLE( aElem.rotation, DEGREES_T ) );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
ConvertTexts6ToEdaTextSettings( aElem, *pcbText );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( pcbText.release(), ADD_MODE::APPEND );
|
2022-01-16 13:40:23 +00:00
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
void ALTIUM_PCB::ConvertTexts6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, const ATEXT6& aElem,
|
|
|
|
PCB_LAYER_ID aLayer )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_TEXT* fpText;
|
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
if( aElem.isDesignator )
|
|
|
|
{
|
|
|
|
fpText = &aFootprint->Reference(); // TODO: handle multiple layers
|
|
|
|
}
|
|
|
|
else if( aElem.isComment )
|
|
|
|
{
|
|
|
|
fpText = &aFootprint->Value(); // TODO: handle multiple layers
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-06 17:30:03 +00:00
|
|
|
fpText = new PCB_TEXT( aFootprint );
|
2022-01-16 13:40:23 +00:00
|
|
|
aFootprint->Add( fpText, ADD_MODE::APPEND );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2023-10-01 13:10:09 +00:00
|
|
|
static const std::map<wxString, wxString> variableMap = {
|
|
|
|
{ "DESIGNATOR", "REFERENCE" },
|
|
|
|
{ "COMMENT", "VALUE" },
|
|
|
|
{ "VALUE", "ALTIUM_VALUE" },
|
|
|
|
{ "LAYER_NAME", "LAYER" },
|
|
|
|
{ "PRINT_DATE", "CURRENT_DATE"},
|
|
|
|
};
|
2022-02-04 22:44:59 +00:00
|
|
|
|
2023-10-01 13:10:09 +00:00
|
|
|
wxString kicadText = AltiumPcbSpecialStringsToKiCadStrings( aElem.text, variableMap );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2023-10-01 13:10:09 +00:00
|
|
|
fpText->SetText(kicadText);
|
2023-07-04 10:11:38 +00:00
|
|
|
fpText->SetKeepUpright( false );
|
2022-01-16 13:40:23 +00:00
|
|
|
fpText->SetLayer( aLayer );
|
2023-04-14 08:42:02 +00:00
|
|
|
fpText->SetPosition( aElem.position );
|
2023-03-30 11:49:23 +00:00
|
|
|
fpText->SetTextAngle( EDA_ANGLE( aElem.rotation, DEGREES_T ) );
|
2022-01-16 13:40:23 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
ConvertTexts6ToEdaTextSettings( aElem, *fpText );
|
2022-01-16 13:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
void ALTIUM_PCB::ConvertTexts6ToEdaTextSettings( const ATEXT6& aElem, EDA_TEXT& aEdaText )
|
2022-01-16 13:40:23 +00:00
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
aEdaText.SetTextSize( VECTOR2I( aElem.height, aElem.height ) ); // TODO: parse text width
|
2023-07-21 00:08:03 +00:00
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
if( aElem.fonttype == ALTIUM_TEXT_TYPE::TRUETYPE )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2023-07-21 00:08:03 +00:00
|
|
|
KIFONT::FONT* font = KIFONT::FONT::GetFont( aElem.fontname, aElem.isBold, aElem.isItalic );
|
2024-03-30 23:03:03 +00:00
|
|
|
aEdaText.SetFont( font );
|
2023-07-21 00:08:03 +00:00
|
|
|
|
|
|
|
if( font->IsOutline() )
|
|
|
|
{
|
|
|
|
// TODO: why is this required? Somehow, truetype size is calculated differently
|
|
|
|
if( font->GetName().Contains( wxS( "Arial" ) ) )
|
2024-03-30 23:03:03 +00:00
|
|
|
aEdaText.SetTextSize( VECTOR2I( aElem.height * 0.63, aElem.height * 0.63 ) );
|
2023-07-21 00:08:03 +00:00
|
|
|
else
|
2024-03-30 23:03:03 +00:00
|
|
|
aEdaText.SetTextSize( VECTOR2I( aElem.height * 0.5, aElem.height * 0.5 ) );
|
2023-07-21 00:08:03 +00:00
|
|
|
}
|
2022-01-16 13:40:23 +00:00
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aEdaText.SetTextThickness( aElem.strokewidth );
|
|
|
|
aEdaText.SetBoldFlag( aElem.isBold );
|
|
|
|
aEdaText.SetItalic( aElem.isItalic );
|
|
|
|
aEdaText.SetMirrored( aElem.isMirrored );
|
2022-01-16 13:40:23 +00:00
|
|
|
|
2023-07-04 10:16:25 +00:00
|
|
|
// Altium position always specifies the bottom left corner
|
2024-03-30 23:03:03 +00:00
|
|
|
aEdaText.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
aEdaText.SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2022-01-16 13:40:23 +00:00
|
|
|
|
2023-07-04 10:16:25 +00:00
|
|
|
// TODO: correct the position and set proper justification
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 13:40:23 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
void ALTIUM_PCB::ParseFills6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile,
|
2020-11-14 01:16:02 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-26 19:21:30 +00:00
|
|
|
m_progressReporter->Report( _( "Loading rectangles..." ) );
|
2021-06-26 10:49:58 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumPcbFile, aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
2021-06-26 10:49:58 +00:00
|
|
|
checkpoint();
|
2020-04-03 23:22:24 +00:00
|
|
|
AFILL6 elem( reader );
|
|
|
|
|
2022-01-17 18:49:06 +00:00
|
|
|
if( elem.component == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
|
|
|
ConvertFills6ToBoardItem( elem );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FOOTPRINT* footprint = HelperGetFootprint( elem.component );
|
|
|
|
ConvertFills6ToFootprintItem( footprint, elem, true );
|
|
|
|
}
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2022-01-17 18:49:06 +00:00
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
THROW_IO_ERROR( "Fills6 stream is not fully parsed" );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2022-01-17 18:49:06 +00:00
|
|
|
void ALTIUM_PCB::ConvertFills6ToBoardItem( const AFILL6& aElem )
|
|
|
|
{
|
2023-08-18 09:59:35 +00:00
|
|
|
if( aElem.is_keepout || aElem.layer == ALTIUM_LAYER::KEEP_OUT_LAYER )
|
2022-01-17 18:49:06 +00:00
|
|
|
{
|
2023-08-18 09:59:35 +00:00
|
|
|
// This is not the actual board item. We can use it to create the polygon for the region
|
|
|
|
PCB_SHAPE shape( nullptr, SHAPE_T::RECTANGLE );
|
2023-09-06 06:02:41 +00:00
|
|
|
|
2023-08-18 09:59:35 +00:00
|
|
|
shape.SetStart( aElem.pos1 );
|
|
|
|
shape.SetEnd( aElem.pos2 );
|
2023-09-06 06:02:41 +00:00
|
|
|
shape.SetFilled( true );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape.SetStroke( STROKE_PARAMS( 0, LINE_STYLE::SOLID ) );
|
2023-08-18 09:59:35 +00:00
|
|
|
|
|
|
|
if( aElem.rotation != 0. )
|
|
|
|
{
|
|
|
|
VECTOR2I center( ( aElem.pos1.x + aElem.pos2.x ) / 2,
|
|
|
|
( aElem.pos1.y + aElem.pos2.y ) / 2 );
|
|
|
|
shape.Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
HelperPcpShapeAsBoardKeepoutRegion( shape, aElem.layer, aElem.keepoutrestrictions );
|
2022-01-17 18:49:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
|
|
|
ConvertFills6ToBoardItemOnLayer( aElem, klayer );
|
|
|
|
}
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
|
2022-01-17 18:49:06 +00:00
|
|
|
void ALTIUM_PCB::ConvertFills6ToFootprintItem( FOOTPRINT* aFootprint, const AFILL6& aElem,
|
|
|
|
const bool aIsBoardImport )
|
|
|
|
{
|
2022-04-02 16:04:45 +00:00
|
|
|
if( aElem.is_keepout
|
|
|
|
|| aElem.layer == ALTIUM_LAYER::KEEP_OUT_LAYER ) // TODO: what about plane layers?
|
2022-01-17 18:49:06 +00:00
|
|
|
{
|
|
|
|
// This is not the actual board item. We can use it to create the polygon for the region
|
2023-07-24 16:07:56 +00:00
|
|
|
PCB_SHAPE shape( nullptr, SHAPE_T::RECTANGLE );
|
2023-09-06 06:02:41 +00:00
|
|
|
|
2022-01-17 18:49:06 +00:00
|
|
|
shape.SetStart( aElem.pos1 );
|
|
|
|
shape.SetEnd( aElem.pos2 );
|
2023-09-06 06:02:41 +00:00
|
|
|
shape.SetFilled( true );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape.SetStroke( STROKE_PARAMS( 0, LINE_STYLE::SOLID ) );
|
2020-04-05 22:26:29 +00:00
|
|
|
|
2022-01-17 18:49:06 +00:00
|
|
|
if( aElem.rotation != 0. )
|
|
|
|
{
|
|
|
|
VECTOR2I center( ( aElem.pos1.x + aElem.pos2.x ) / 2,
|
|
|
|
( aElem.pos1.y + aElem.pos2.y ) / 2 );
|
|
|
|
shape.Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-17 18:49:06 +00:00
|
|
|
|
2022-03-11 18:15:34 +00:00
|
|
|
HelperPcpShapeAsFootprintKeepoutRegion( aFootprint, shape, aElem.layer,
|
|
|
|
aElem.keepoutrestrictions );
|
2022-01-17 18:49:06 +00:00
|
|
|
}
|
|
|
|
else if( aIsBoardImport && IsAltiumLayerCopper( aElem.layer )
|
|
|
|
&& aElem.net != ALTIUM_NET_UNCONNECTED )
|
|
|
|
{
|
|
|
|
// Special case: do to not lose net connections in footprints
|
2023-08-18 09:59:35 +00:00
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
|
|
|
ConvertFills6ToBoardItemOnLayer( aElem, klayer );
|
2022-01-17 18:49:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aElem.layer ) )
|
|
|
|
ConvertFills6ToFootprintItemOnLayer( aFootprint, aElem, klayer );
|
|
|
|
}
|
|
|
|
}
|
2020-04-05 22:26:29 +00:00
|
|
|
|
|
|
|
|
2022-01-17 18:49:06 +00:00
|
|
|
void ALTIUM_PCB::ConvertFills6ToBoardItemOnLayer( const AFILL6& aElem, PCB_LAYER_ID aLayer )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> fill = std::make_unique<PCB_SHAPE>( m_board, SHAPE_T::RECTANGLE );
|
2022-01-17 18:49:06 +00:00
|
|
|
|
|
|
|
fill->SetFilled( true );
|
|
|
|
fill->SetLayer( aLayer );
|
|
|
|
fill->SetStroke( STROKE_PARAMS( 0 ) );
|
|
|
|
|
|
|
|
fill->SetStart( aElem.pos1 );
|
|
|
|
fill->SetEnd( aElem.pos2 );
|
|
|
|
|
2023-08-18 12:51:33 +00:00
|
|
|
if( IsCopperLayer( aLayer ) && aElem.net != ALTIUM_NET_UNCONNECTED )
|
|
|
|
{
|
2023-08-18 09:59:35 +00:00
|
|
|
fill->SetNetCode( GetNetCode( aElem.net ) );
|
|
|
|
}
|
|
|
|
|
2022-01-17 18:49:06 +00:00
|
|
|
if( aElem.rotation != 0. )
|
|
|
|
{
|
|
|
|
// TODO: Do we need SHAPE_T::POLY for non 90° rotations?
|
|
|
|
VECTOR2I center( ( aElem.pos1.x + aElem.pos2.x ) / 2, ( aElem.pos1.y + aElem.pos2.y ) / 2 );
|
|
|
|
fill->Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) );
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( fill.release(), ADD_MODE::APPEND );
|
2022-01-17 18:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ALTIUM_PCB::ConvertFills6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, const AFILL6& aElem,
|
|
|
|
PCB_LAYER_ID aLayer )
|
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> fill = std::make_unique<PCB_SHAPE>( aFootprint, SHAPE_T::RECTANGLE );
|
2022-01-17 18:49:06 +00:00
|
|
|
|
|
|
|
fill->SetFilled( true );
|
|
|
|
fill->SetLayer( aLayer );
|
|
|
|
fill->SetStroke( STROKE_PARAMS( 0 ) );
|
|
|
|
|
|
|
|
fill->SetStart( aElem.pos1 );
|
|
|
|
fill->SetEnd( aElem.pos2 );
|
|
|
|
|
|
|
|
if( aElem.rotation != 0. )
|
|
|
|
{
|
|
|
|
// TODO: Do we need SHAPE_T::POLY for non 90° rotations?
|
|
|
|
VECTOR2I center( ( aElem.pos1.x + aElem.pos2.x ) / 2, ( aElem.pos1.y + aElem.pos2.y ) / 2 );
|
|
|
|
fill->Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) );
|
|
|
|
}
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( fill.release(), ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2022-01-10 16:45:37 +00:00
|
|
|
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
void ALTIUM_PCB::HelperSetZoneLayers( ZONE& aZone, const ALTIUM_LAYER aAltiumLayer )
|
2022-02-19 13:37:05 +00:00
|
|
|
{
|
2023-09-14 16:15:15 +00:00
|
|
|
LSET layerSet;
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2023-09-14 16:15:15 +00:00
|
|
|
for( PCB_LAYER_ID klayer : GetKicadLayersToIterate( aAltiumLayer ) )
|
|
|
|
layerSet.set( klayer );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aZone.SetLayerSet( layerSet );
|
2022-02-19 13:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
void ALTIUM_PCB::HelperSetZoneKeepoutRestrictions( ZONE& aZone, const uint8_t aKeepoutRestrictions )
|
2022-03-07 18:58:43 +00:00
|
|
|
{
|
|
|
|
bool keepoutRestrictionVia = ( aKeepoutRestrictions & 0x01 ) != 0;
|
|
|
|
bool keepoutRestrictionTrack = ( aKeepoutRestrictions & 0x02 ) != 0;
|
|
|
|
bool keepoutRestrictionCopper = ( aKeepoutRestrictions & 0x04 ) != 0;
|
|
|
|
bool keepoutRestrictionSMDPad = ( aKeepoutRestrictions & 0x08 ) != 0;
|
|
|
|
bool keepoutRestrictionTHPad = ( aKeepoutRestrictions & 0x10 ) != 0;
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
aZone.SetDoNotAllowVias( keepoutRestrictionVia );
|
|
|
|
aZone.SetDoNotAllowTracks( keepoutRestrictionTrack );
|
|
|
|
aZone.SetDoNotAllowCopperPour( keepoutRestrictionCopper );
|
|
|
|
aZone.SetDoNotAllowPads( keepoutRestrictionSMDPad && keepoutRestrictionTHPad );
|
|
|
|
aZone.SetDoNotAllowFootprints( false );
|
2022-03-07 18:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ALTIUM_PCB::HelperPcpShapeAsBoardKeepoutRegion( const PCB_SHAPE& aShape,
|
|
|
|
const ALTIUM_LAYER aAltiumLayer,
|
|
|
|
const uint8_t aKeepoutRestrictions )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( m_board );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
|
|
|
zone->SetIsRuleArea( true );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
HelperSetZoneLayers( *zone, aAltiumLayer );
|
|
|
|
HelperSetZoneKeepoutRestrictions( *zone, aKeepoutRestrictions );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
aShape.EDA_SHAPE::TransformShapeToPolygon( *zone->Outline(), 0, ARC_HIGH_DEF, ERROR_INSIDE );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
|
|
|
zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
|
|
|
ZONE::GetDefaultHatchPitch(), true );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
m_board->Add( zone.release(), ADD_MODE::APPEND );
|
2022-01-10 16:45:37 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
|
2022-03-07 18:58:43 +00:00
|
|
|
void ALTIUM_PCB::HelperPcpShapeAsFootprintKeepoutRegion( FOOTPRINT* aFootprint,
|
|
|
|
const PCB_SHAPE& aShape,
|
|
|
|
const ALTIUM_LAYER aAltiumLayer,
|
|
|
|
const uint8_t aKeepoutRestrictions )
|
2022-01-10 16:45:37 +00:00
|
|
|
{
|
2024-03-30 23:03:03 +00:00
|
|
|
std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aFootprint );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
|
|
|
zone->SetIsRuleArea( true );
|
|
|
|
|
2024-03-30 23:03:03 +00:00
|
|
|
HelperSetZoneLayers( *zone, aAltiumLayer );
|
|
|
|
HelperSetZoneKeepoutRestrictions( *zone, aKeepoutRestrictions );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
aShape.EDA_SHAPE::TransformShapeToPolygon( *zone->Outline(), 0, ARC_HIGH_DEF, ERROR_INSIDE );
|
2022-01-10 16:45:37 +00:00
|
|
|
|
|
|
|
zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
|
|
|
ZONE::GetDefaultHatchPitch(), true );
|
|
|
|
|
2022-01-10 19:45:42 +00:00
|
|
|
// TODO: zone->SetLocalCoord(); missing?
|
2024-03-30 23:03:03 +00:00
|
|
|
aFootprint->Add( zone.release(), ADD_MODE::APPEND );
|
2022-02-06 15:23:46 +00:00
|
|
|
}
|
2022-02-20 19:18:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::pair<PCB_LAYER_ID, int>> ALTIUM_PCB::HelperGetSolderAndPasteMaskExpansions(
|
|
|
|
const ALTIUM_RECORD aType, const int aPrimitiveIndex, const ALTIUM_LAYER aAltiumLayer )
|
|
|
|
{
|
|
|
|
if( m_extendedPrimitiveInformationMaps.count( aType ) == 0 )
|
|
|
|
return {}; // there is nothing to parse
|
|
|
|
|
|
|
|
auto elems =
|
|
|
|
m_extendedPrimitiveInformationMaps[ALTIUM_RECORD::TRACK].equal_range( aPrimitiveIndex );
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
if( elems.first == elems.second )
|
|
|
|
return {}; // there is nothing to parse
|
|
|
|
|
|
|
|
std::vector<std::pair<PCB_LAYER_ID, int>> layerExpansionPairs;
|
|
|
|
|
|
|
|
for( auto it = elems.first; it != elems.second; ++it )
|
|
|
|
{
|
|
|
|
const AEXTENDED_PRIMITIVE_INFORMATION& pInf = it->second;
|
|
|
|
|
|
|
|
if( pInf.type == AEXTENDED_PRIMITIVE_INFORMATION_TYPE::MASK )
|
|
|
|
{
|
|
|
|
if( pInf.soldermaskexpansionmode == ALTIUM_MODE::MANUAL
|
|
|
|
|| pInf.soldermaskexpansionmode == ALTIUM_MODE::RULE )
|
|
|
|
{
|
|
|
|
// TODO: what layers can lead to solder or paste mask usage? E.g. KEEP_OUT_LAYER and other top/bottom layers
|
|
|
|
if( aAltiumLayer == ALTIUM_LAYER::TOP_LAYER
|
|
|
|
|| aAltiumLayer == ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
layerExpansionPairs.emplace_back( F_Mask, pInf.soldermaskexpansionmanual );
|
|
|
|
}
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
if( aAltiumLayer == ALTIUM_LAYER::BOTTOM_LAYER
|
|
|
|
|| aAltiumLayer == ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
layerExpansionPairs.emplace_back( B_Mask, pInf.soldermaskexpansionmanual );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( pInf.pastemaskexpansionmode == ALTIUM_MODE::MANUAL
|
|
|
|
|| pInf.pastemaskexpansionmode == ALTIUM_MODE::RULE )
|
|
|
|
{
|
|
|
|
if( aAltiumLayer == ALTIUM_LAYER::TOP_LAYER
|
|
|
|
|| aAltiumLayer == ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
layerExpansionPairs.emplace_back( F_Paste, pInf.pastemaskexpansionmanual );
|
|
|
|
}
|
2022-03-22 10:23:29 +00:00
|
|
|
|
2022-02-20 19:18:22 +00:00
|
|
|
if( aAltiumLayer == ALTIUM_LAYER::BOTTOM_LAYER
|
|
|
|
|| aAltiumLayer == ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
layerExpansionPairs.emplace_back( B_Paste, pInf.pastemaskexpansionmanual );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return layerExpansionPairs;
|
2022-04-02 16:04:45 +00:00
|
|
|
}
|