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>
|
|
|
|
*
|
|
|
|
* 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"
|
2020-08-23 19:01:08 +00:00
|
|
|
#include "plugins/altium/altium_parser.h"
|
2020-10-23 12:29:07 +00:00
|
|
|
#include <plugins/altium/altium_parser_utils.h>
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <dimension.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
|
|
|
#include <pcb_text.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <track.h>
|
2020-10-15 22:39:33 +00:00
|
|
|
#include <kicad_string.h>
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_shape.h>
|
|
|
|
#include <fp_text.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>
|
2020-04-21 13:34:06 +00:00
|
|
|
#include <project.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>
|
|
|
|
#include <wx/mstream.h>
|
|
|
|
#include <wx/wfstream.h>
|
|
|
|
#include <wx/zstream.h>
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ParseAltiumPcb( BOARD* aBoard, const wxString& aFileName,
|
2020-10-04 23:34:59 +00:00
|
|
|
const std::map<ALTIUM_PCB_DIR, std::string>& aFileMapping )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
// Open file
|
|
|
|
FILE* fp = wxFopen( aFileName, "rb" );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( fp == nullptr )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( _( "Cannot open file '%s'" ), aFileName ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fseek( fp, 0, SEEK_END );
|
2020-04-05 22:26:29 +00:00
|
|
|
long len = ftell( fp );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-05 22:26:29 +00:00
|
|
|
if( len < 0 )
|
|
|
|
{
|
|
|
|
fclose( fp );
|
|
|
|
THROW_IO_ERROR( "Reading error, cannot determine length of file" );
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
std::unique_ptr<unsigned char[]> buffer( new unsigned char[len] );
|
|
|
|
fseek( fp, 0, SEEK_SET );
|
|
|
|
|
|
|
|
size_t bytesRead = fread( buffer.get(), sizeof( unsigned char ), len, fp );
|
|
|
|
fclose( fp );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-05 22:26:29 +00:00
|
|
|
if( static_cast<size_t>( len ) != bytesRead )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "Reading error" );
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
CFB::CompoundFileReader reader( buffer.get(), bytesRead );
|
|
|
|
|
|
|
|
// Parse File
|
|
|
|
ALTIUM_PCB pcb( aBoard );
|
|
|
|
pcb.Parse( reader, aFileMapping );
|
|
|
|
}
|
|
|
|
catch( CFB::CFBException& exception )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( exception.what() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
bool IsAltiumLayerCopper( ALTIUM_LAYER aLayer )
|
|
|
|
{
|
|
|
|
return aLayer >= ALTIUM_LAYER::TOP_LAYER && aLayer <= ALTIUM_LAYER::BOTTOM_LAYER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* ALTIUM_PCB::HelperCreateAndAddDrawsegment( uint16_t aComponent )
|
2020-04-18 21:47:53 +00:00
|
|
|
{
|
|
|
|
if( aComponent == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( m_board );
|
|
|
|
m_board->Add( shape, ADD_MODE::APPEND );
|
|
|
|
return shape;
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( m_components.size() <= aComponent )
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( "Component creator tries to access component id %d "
|
|
|
|
"of %d existing components",
|
|
|
|
aComponent,
|
|
|
|
m_components.size() ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = m_components.at( aComponent );
|
2020-11-13 11:17:15 +00:00
|
|
|
PCB_SHAPE* fpShape = new FP_SHAPE( footprint );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Add( fpShape, ADD_MODE::APPEND );
|
2020-10-04 23:34:59 +00:00
|
|
|
return fpShape;
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void ALTIUM_PCB::HelperDrawsegmentSetLocalCoord( PCB_SHAPE* aShape, uint16_t aComponent )
|
2020-04-18 21:47:53 +00:00
|
|
|
{
|
|
|
|
if( aComponent != ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* fpShape = dynamic_cast<FP_SHAPE*>( aShape );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
if( fpShape )
|
2021-01-14 21:18:46 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
fpShape->SetLocalCoord();
|
2021-01-14 21:18:46 +00:00
|
|
|
|
|
|
|
// TODO: SetLocalCoord() does not update the polygon shape!
|
|
|
|
// This workaround converts the poly shape into the local coordinates
|
|
|
|
SHAPE_POLY_SET& polyShape = fpShape->GetPolyShape();
|
|
|
|
if( !polyShape.IsEmpty() )
|
|
|
|
{
|
|
|
|
FOOTPRINT* fp = m_components.at( aComponent );
|
|
|
|
|
|
|
|
polyShape.Move( -fp->GetPosition() );
|
|
|
|
polyShape.Rotate( -fp->GetOrientationRadians() );
|
|
|
|
}
|
|
|
|
}
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 11:21:47 +00:00
|
|
|
void HelperShapeLineChainFromAltiumVertices(
|
2020-10-22 11:44:25 +00:00
|
|
|
SHAPE_LINE_CHAIN& aLine, const std::vector<ALTIUM_VERTICE>& aVertices )
|
2020-10-22 11:21:47 +00:00
|
|
|
{
|
2020-10-22 11:44:25 +00:00
|
|
|
for( auto& vertice : aVertices )
|
2020-10-22 11:21:47 +00:00
|
|
|
{
|
|
|
|
if( vertice.isRound )
|
|
|
|
{
|
|
|
|
double angle = NormalizeAngleDegreesPos( vertice.endangle - vertice.startangle );
|
|
|
|
|
|
|
|
double startradiant = DEG2RAD( vertice.startangle );
|
|
|
|
double endradiant = DEG2RAD( vertice.endangle );
|
|
|
|
wxPoint arcStartOffset = wxPoint( KiROUND( std::cos( startradiant ) * vertice.radius ),
|
|
|
|
-KiROUND( std::sin( startradiant ) * vertice.radius ) );
|
|
|
|
|
|
|
|
wxPoint arcEndOffset = wxPoint( KiROUND( std::cos( endradiant ) * vertice.radius ),
|
|
|
|
-KiROUND( std::sin( endradiant ) * vertice.radius ) );
|
|
|
|
|
|
|
|
wxPoint arcStart = vertice.center + arcStartOffset;
|
|
|
|
wxPoint arcEnd = vertice.center + arcEndOffset;
|
|
|
|
|
|
|
|
if( GetLineLength( arcStart, vertice.position )
|
|
|
|
< GetLineLength( arcEnd, vertice.position ) )
|
|
|
|
{
|
2020-10-22 11:44:25 +00:00
|
|
|
aLine.Append( SHAPE_ARC( vertice.center, arcStart, -angle ) );
|
2020-10-22 11:21:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-22 11:44:25 +00:00
|
|
|
aLine.Append( SHAPE_ARC( vertice.center, arcEnd, angle ) );
|
2020-10-22 11:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-22 11:44:25 +00:00
|
|
|
aLine.Append( vertice.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 );
|
|
|
|
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;
|
|
|
|
case ALTIUM_LAYER::MID_LAYER_1: return In1_Cu; // TODO: stackup same as in KiCad?
|
|
|
|
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;
|
|
|
|
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_1: return Dwgs_User; //Edge_Cuts;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_2: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_3: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_4: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_5: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_6: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_7: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_8: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_9: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_10: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_11: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_12: return Dwgs_User;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_13: return F_Fab;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_14: return B_Fab;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_15: return F_CrtYd;
|
|
|
|
case ALTIUM_LAYER::MECHANICAL_16: return B_CrtYd;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ALTIUM_PCB::ALTIUM_PCB( BOARD* aBoard )
|
|
|
|
{
|
2020-05-10 17:30:03 +00:00
|
|
|
m_board = aBoard;
|
|
|
|
m_num_nets = 0;
|
|
|
|
m_highest_pour_index = 0;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ALTIUM_PCB::~ALTIUM_PCB()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ALTIUM_PCB::Parse( const CFB::CompoundFileReader& aReader,
|
2020-11-13 15:15:52 +00:00
|
|
|
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,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseFileHeader( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::BOARD6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseBoard6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::COMPONENTS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseComponents6Data( aReader, fileHeader );
|
|
|
|
} },
|
2020-04-21 13:34:06 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::MODELS,
|
|
|
|
[this, aFileMapping]( auto aReader, auto fileHeader ) {
|
|
|
|
wxString dir( aFileMapping.at( ALTIUM_PCB_DIR::MODELS ) );
|
|
|
|
dir.RemoveLast( 4 ); // Remove "Data" from the path
|
|
|
|
this->ParseModelsData( aReader, fileHeader, dir );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::COMPONENTBODIES6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseComponentsBodies6Data( aReader, fileHeader );
|
|
|
|
} },
|
2020-04-03 23:22:24 +00:00
|
|
|
{ true, ALTIUM_PCB_DIR::NETS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseNets6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::CLASSES6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseClasses6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::RULES6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseRules6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::DIMENSIONS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseDimensions6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::POLYGONS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParsePolygons6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::ARCS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseArcs6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::PADS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParsePads6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::VIAS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseVias6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::TRACKS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseTracks6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::TEXTS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseTexts6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::FILLS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseFills6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ false, ALTIUM_PCB_DIR::BOARDREGIONS,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseBoardRegionsData( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::SHAPEBASEDREGIONS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseShapeBasedRegions6Data( aReader, fileHeader );
|
|
|
|
} },
|
|
|
|
{ true, ALTIUM_PCB_DIR::REGIONS6,
|
|
|
|
[this]( auto aReader, auto fileHeader ) {
|
|
|
|
this->ParseRegions6Data( aReader, fileHeader );
|
|
|
|
} }
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
if( mappedDirectory == aFileMapping.end() )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxASSERT_MSG( !isRequired, wxString::Format( "Altium Directory of kind %d was expected, "
|
|
|
|
"but no mapping is present in the code",
|
|
|
|
directory ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file =
|
|
|
|
FindStream( aReader, mappedDirectory->second.c_str() );
|
|
|
|
if( file != nullptr )
|
|
|
|
{
|
|
|
|
fp( aReader, file );
|
|
|
|
}
|
|
|
|
else if( isRequired )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( _( "File not found: '%s'" ), mappedDirectory->second ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:30:03 +00:00
|
|
|
// fixup zone priorities since Altium stores them in the opposite order
|
|
|
|
for( auto& zone : m_polygons )
|
|
|
|
{
|
|
|
|
if( !zone )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Altium "fills" - not poured in Altium
|
|
|
|
if( zone->GetPriority() == 1000 )
|
|
|
|
{
|
|
|
|
// Unlikely, but you never know
|
|
|
|
if( m_highest_pour_index >= 1000 )
|
|
|
|
zone->SetPriority( m_highest_pour_index + 1 );
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int priority = m_highest_pour_index - zone->GetPriority();
|
|
|
|
|
|
|
|
zone->SetPriority( priority >= 0 ? priority : 0 );
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
// change priority of outer zone to zero
|
|
|
|
for( auto& zone : m_outer_plane )
|
|
|
|
{
|
|
|
|
zone.second->SetPriority( 0 );
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Finish Board by recalculating footprint boundingboxes
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-11-12 23:50:33 +00:00
|
|
|
footprint->CalculateBoundingBox();
|
2020-04-21 13:34:06 +00:00
|
|
|
|
|
|
|
// Otherwise we cannot save the imported board
|
|
|
|
m_board->SetModified();
|
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;
|
|
|
|
}
|
|
|
|
else if( m_num_nets < aId )
|
|
|
|
{
|
2020-08-23 19:01:08 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
"Netcode with id %d does not exist. Only %d nets are known", aId, m_num_nets ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return aId + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ARULE6* ALTIUM_PCB::GetRule( ALTIUM_RULE_KIND aKind, const wxString& aName ) const
|
|
|
|
{
|
|
|
|
const auto rules = m_rules.find( aKind );
|
|
|
|
if( rules == m_rules.end() )
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for( const ARULE6& rule : rules->second )
|
|
|
|
{
|
|
|
|
if( rule.name == aName )
|
|
|
|
{
|
|
|
|
return &rule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ARULE6* ALTIUM_PCB::GetRuleDefault( ALTIUM_RULE_KIND aKind ) const
|
|
|
|
{
|
|
|
|
const auto rules = m_rules.find( aKind );
|
|
|
|
if( rules == m_rules.end() )
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for( const ARULE6& rule : rules->second )
|
|
|
|
{
|
|
|
|
if( rule.scope1expr == "All" && rule.scope2expr == "All" )
|
|
|
|
{
|
|
|
|
return &rule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseFileHeader( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
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
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseBoard6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
ABOARD6 elem( reader );
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Board6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 12:28:10 +00:00
|
|
|
m_board->GetDesignSettings().m_AuxOrigin = elem.sheetpos;
|
|
|
|
m_board->GetDesignSettings().m_GridOrigin = elem.sheetpos;
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
// read layercount from stackup, because LAYERSETSCOUNT is not always correct?!
|
|
|
|
size_t layercount = 0;
|
|
|
|
for( size_t i = static_cast<size_t>( ALTIUM_LAYER::TOP_LAYER );
|
|
|
|
i < elem.stackup.size() && i != 0; i = elem.stackup[i - 1].nextId, 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();
|
|
|
|
// find first copper layer
|
|
|
|
for( ; it != stackup.GetList().end() && ( *it )->GetType() != BS_ITEM_TYPE_COPPER; ++it )
|
|
|
|
;
|
|
|
|
|
|
|
|
auto curLayer = static_cast<int>( F_Cu );
|
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
|
|
|
{
|
2020-04-15 14:01:02 +00:00
|
|
|
m_board->SetLayerName( ( *it )->GetBrdLayerId(), "[unused]" );
|
|
|
|
|
2020-04-15 13:18:51 +00:00
|
|
|
if( ( *it )->GetType() != BS_ITEM_TYPE_COPPER )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "Board6 stream, unexpected item while parsing stackup" );
|
|
|
|
}
|
|
|
|
( *it )->SetThickness( 0 );
|
|
|
|
|
|
|
|
++it;
|
|
|
|
if( ( *it )->GetType() != BS_ITEM_TYPE_DIELECTRIC )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "Board6 stream, unexpected item while parsing stackup" );
|
|
|
|
}
|
|
|
|
( *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 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Board6 stream, unexpected item while parsing stackup" );
|
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 )
|
|
|
|
{
|
2020-08-23 19:01:08 +00:00
|
|
|
THROW_IO_ERROR( "Board6 stream, unexpected id while parsing last stackup layer" );
|
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;
|
|
|
|
if( ( *it )->GetType() != BS_ITEM_TYPE_DIELECTRIC )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Board6 stream, unexpected item while parsing stackup" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
( *it )->SetThickness( layer.dielectricthick, 0 );
|
|
|
|
( *it )->SetMaterial( layer.dielectricmaterial.empty() ?
|
|
|
|
NotSpecifiedPrm() :
|
|
|
|
wxString( layer.dielectricmaterial ) );
|
|
|
|
( *it )->SetEpsilonR( layer.dielectricconst, 0 );
|
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
HelperCreateBoardOutline( elem.board_vertices );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ALTIUM_PCB::HelperCreateBoardOutline( const std::vector<ALTIUM_VERTICE>& aVertices )
|
|
|
|
{
|
|
|
|
if( !aVertices.empty() )
|
|
|
|
{
|
|
|
|
const ALTIUM_VERTICE* last = &aVertices.at( 0 );
|
|
|
|
for( size_t i = 0; i < aVertices.size(); i++ )
|
|
|
|
{
|
|
|
|
const ALTIUM_VERTICE* cur = &aVertices.at( ( i + 1 ) % aVertices.size() );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( m_board );
|
|
|
|
m_board->Add( shape, ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetWidth( m_board->GetDesignSettings().GetLineThickness( Edge_Cuts ) );
|
|
|
|
shape->SetLayer( Edge_Cuts );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
if( !last->isRound && !cur->isRound )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetShape( S_SEGMENT );
|
|
|
|
shape->SetStart( last->position );
|
|
|
|
shape->SetEnd( cur->position );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else if( cur->isRound )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetShape( S_ARC );
|
|
|
|
shape->SetAngle( -NormalizeAngleDegreesPos( cur->endangle - cur->startangle ) * 10. );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
double startradiant = DEG2RAD( cur->startangle );
|
|
|
|
wxPoint arcStartOffset = wxPoint( KiROUND( std::cos( startradiant ) * cur->radius ),
|
|
|
|
-KiROUND( std::sin( startradiant ) * cur->radius ) );
|
|
|
|
wxPoint arcStart = cur->center + arcStartOffset;
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetCenter( cur->center );
|
|
|
|
shape->SetArcStart( arcStart );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
if( !last->isRound )
|
|
|
|
{
|
|
|
|
double endradiant = DEG2RAD( cur->endangle );
|
|
|
|
wxPoint arcEndOffset = wxPoint( KiROUND( std::cos( endradiant ) * cur->radius ),
|
|
|
|
-KiROUND( std::sin( endradiant ) * cur->radius ) );
|
|
|
|
wxPoint arcEnd = cur->center + arcEndOffset;
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape2 = new PCB_SHAPE( m_board );
|
|
|
|
shape2->SetShape( S_SEGMENT );
|
|
|
|
m_board->Add( shape2, ADD_MODE::APPEND );
|
|
|
|
shape2->SetWidth( m_board->GetDesignSettings().GetLineThickness( Edge_Cuts ) );
|
|
|
|
shape2->SetLayer( Edge_Cuts );
|
|
|
|
shape2->SetStart( last->position );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
// TODO: this is more of a hack than the real solution
|
|
|
|
double lineLengthStart = GetLineLength( last->position, arcStart );
|
|
|
|
double lineLengthEnd = GetLineLength( last->position, arcEnd );
|
|
|
|
if( lineLengthStart > lineLengthEnd )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
shape2->SetEnd( cur->center + arcEndOffset );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
shape2->SetEnd( cur->center + arcStartOffset );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last = cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseClasses6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
ACLASS6 elem( reader );
|
|
|
|
|
|
|
|
if( elem.kind == ALTIUM_CLASS_KIND::NET_CLASS )
|
|
|
|
{
|
2020-10-20 09:48:27 +00:00
|
|
|
NETCLASSPTR nc = std::make_shared<NETCLASS>( elem.name );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
for( const auto& name : elem.names )
|
|
|
|
{
|
2020-10-20 09:48:27 +00:00
|
|
|
// TODO: it seems it can happen that we have names not attached to any net.
|
|
|
|
nc->Add( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_board->GetDesignSettings().GetNetClasses().Add( nc ) )
|
|
|
|
{
|
|
|
|
// Name conflict, this is likely a bad board file.
|
|
|
|
// unique_ptr will delete nc on this code path
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Duplicated Netclass name \"%s\"" ), elem.name ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Classes6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2020-10-20 09:48:27 +00:00
|
|
|
|
|
|
|
m_board->m_LegacyNetclassesLoaded = true;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseComponents6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
uint16_t componentId = 0;
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
ACOMPONENT6 elem( reader );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = new FOOTPRINT( m_board );
|
2020-11-13 11:17:15 +00:00
|
|
|
m_board->Add( footprint, ADD_MODE::APPEND );
|
|
|
|
m_components.emplace_back( footprint );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-12-17 23:32:23 +00:00
|
|
|
LIB_ID fpID = AltiumToKiCadLibID( elem.sourcefootprintlibrary, elem.sourcelibreference );
|
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;
|
|
|
|
if( reference.find_first_not_of( "0123456789" ) == wxString::npos )
|
|
|
|
reference.Prepend( "UNK" );
|
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
|
|
|
|
|
|
|
componentId++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Components6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseComponentsBodies6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-21 13:34:06 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
"ComponentsBodies6 stream tries to access component id %d of %d existing components",
|
|
|
|
elem.component, m_components.size() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !elem.modelIsEmbedded )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto modelTuple = m_models.find( elem.modelId );
|
|
|
|
if( modelTuple == m_models.end() )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
"ComponentsBodies6 stream tries to access model id %s which does not exist",
|
|
|
|
elem.modelId ) );
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = m_components.at( elem.component );
|
2020-11-13 11:17:15 +00:00
|
|
|
const wxPoint& 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;
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
modelSettings.m_Offset.x = Iu2Millimeter((int) elem.modelPosition.x - fpPosition.x );
|
|
|
|
modelSettings.m_Offset.y = -Iu2Millimeter((int) elem.modelPosition.y - fpPosition.y );
|
2020-04-21 13:34:06 +00:00
|
|
|
modelSettings.m_Offset.z = Iu2Millimeter( (int) elem.modelPosition.z );
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
double 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 );
|
|
|
|
|
2020-04-24 19:05:39 +00:00
|
|
|
modelSettings.m_Rotation.x = NormalizeAngleDegrees( -elem.modelRotation.x, -180, 180 );
|
2020-05-05 11:25:02 +00:00
|
|
|
modelSettings.m_Rotation.y = NormalizeAngleDegrees( -elem.modelRotation.y, -180, 180 );
|
|
|
|
modelSettings.m_Rotation.z = NormalizeAngleDegrees(
|
|
|
|
-elem.modelRotation.z + elem.rotation + orientation / 10, -180, 180 );
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "ComponentsBodies6 stream is not fully parsed" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
void ALTIUM_PCB::HelperParseDimensions6Linear( const ADIMENSION6& aElem )
|
|
|
|
{
|
|
|
|
if( aElem.referencePoint.size() != 2 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "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 )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Dimension on Altium layer %d has no KiCad equivalent. "
|
|
|
|
"Put it on Eco1_User instead" ),
|
|
|
|
aElem.layer ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPoint referencePoint0 = aElem.referencePoint.at( 0 );
|
|
|
|
wxPoint referencePoint1 = aElem.referencePoint.at( 1 );
|
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
ALIGNED_DIMENSION* dimension = new ALIGNED_DIMENSION( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
m_board->Add( dimension, ADD_MODE::APPEND );
|
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetPrecision( aElem.textprecission );
|
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.
|
|
|
|
* XY1 is the position of the arrow above REFERENCE0POINT. those three points are not necesarily
|
|
|
|
* in 90degree angle, but KiCad requires this to show the correct measurements.
|
|
|
|
*
|
|
|
|
* 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-08-23 19:01:08 +00:00
|
|
|
wxPoint direction = aElem.xy1 - referencePoint0;
|
2020-04-03 23:22:24 +00:00
|
|
|
wxPoint directionNormalVector = wxPoint( -direction.y, direction.x );
|
|
|
|
SEG segm1( referencePoint0, referencePoint0 + directionNormalVector );
|
|
|
|
SEG segm2( referencePoint1, referencePoint1 + direction );
|
|
|
|
wxPoint intersection( segm1.Intersect( segm2, true, true ).get() );
|
2020-09-09 03:17:08 +00:00
|
|
|
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
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( direction.x <= 0 && direction.y <= 0 ) // TODO: I suspect this is not always correct
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
dimension->Text().SetTextThickness( aElem.textlinewidth );
|
2020-04-03 23:22:24 +00:00
|
|
|
dimension->Text().SetTextSize( wxSize( aElem.textheight, aElem.textheight ) );
|
|
|
|
dimension->Text().SetBold( aElem.textbold );
|
|
|
|
dimension->Text().SetItalic( aElem.textitalic );
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ALTIUM_PCB::HelperParseDimensions6Leader( const ADIMENSION6& aElem )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Dimension on Altium layer %d has no KiCad equivalent. "
|
|
|
|
"Put it on Eco1_User instead" ),
|
|
|
|
aElem.layer ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aElem.referencePoint.empty() )
|
|
|
|
{
|
|
|
|
wxPoint referencePoint0 = aElem.referencePoint.at( 0 );
|
|
|
|
|
|
|
|
// line
|
|
|
|
wxPoint last = referencePoint0;
|
|
|
|
for( size_t i = 1; i < aElem.referencePoint.size(); i++ )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( m_board );
|
|
|
|
m_board->Add( shape, ADD_MODE::APPEND );
|
|
|
|
shape->SetShape( S_SEGMENT );
|
|
|
|
shape->SetLayer( klayer );
|
|
|
|
shape->SetWidth( aElem.linewidth );
|
|
|
|
shape->SetStart( last );
|
|
|
|
shape->SetEnd( aElem.referencePoint.at( i ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
last = aElem.referencePoint.at( i );
|
|
|
|
}
|
|
|
|
|
|
|
|
// arrow
|
|
|
|
if( aElem.referencePoint.size() >= 2 )
|
|
|
|
{
|
|
|
|
wxPoint dirVec = aElem.referencePoint.at( 1 ) - referencePoint0;
|
|
|
|
if( dirVec.x != 0 || dirVec.y != 0 )
|
|
|
|
{
|
|
|
|
double scaling = EuclideanNorm( dirVec ) / aElem.arrowsize;
|
|
|
|
wxPoint arrVec =
|
|
|
|
wxPoint( KiROUND( dirVec.x / scaling ), KiROUND( dirVec.y / scaling ) );
|
|
|
|
RotatePoint( &arrVec, 200. );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape1 = new PCB_SHAPE( m_board );
|
|
|
|
m_board->Add( shape1, ADD_MODE::APPEND );
|
|
|
|
shape1->SetShape( S_SEGMENT );
|
|
|
|
shape1->SetLayer( klayer );
|
|
|
|
shape1->SetWidth( aElem.linewidth );
|
|
|
|
shape1->SetStart( referencePoint0 );
|
|
|
|
shape1->SetEnd( referencePoint0 + arrVec );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
RotatePoint( &arrVec, -400. );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape2 = new PCB_SHAPE( m_board );
|
|
|
|
m_board->Add( shape2, ADD_MODE::APPEND );
|
|
|
|
shape2->SetShape( S_SEGMENT );
|
|
|
|
shape2->SetLayer( klayer );
|
|
|
|
shape2->SetWidth( aElem.linewidth );
|
|
|
|
shape2->SetStart( referencePoint0 );
|
|
|
|
shape2->SetEnd( referencePoint0 + arrVec );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.textPoint.empty() )
|
|
|
|
{
|
2020-04-05 11:45:55 +00:00
|
|
|
wxLogError( "No text position present for leader dimension object" );
|
2020-04-03 23:22:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_TEXT* text = new PCB_TEXT( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
m_board->Add( text, ADD_MODE::APPEND );
|
|
|
|
text->SetText( aElem.textformat );
|
|
|
|
text->SetPosition( aElem.textPoint.at( 0 ) );
|
|
|
|
text->SetLayer( klayer );
|
|
|
|
text->SetTextSize( wxSize( aElem.textheight, aElem.textheight ) ); // TODO: parse text width
|
2020-04-14 12:25:00 +00:00
|
|
|
text->SetTextThickness( aElem.textlinewidth );
|
2020-04-03 23:22:24 +00:00
|
|
|
text->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
text->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ALTIUM_PCB::HelperParseDimensions6Datum( const ADIMENSION6& aElem )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Dimension on Altium layer %d has no KiCad equivalent. "
|
|
|
|
"Put it on Eco1_User instead" ),
|
|
|
|
aElem.layer ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( size_t i = 0; i < aElem.referencePoint.size(); i++ )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( m_board );
|
|
|
|
m_board->Add( shape, ADD_MODE::APPEND );
|
|
|
|
shape->SetShape( S_SEGMENT );
|
|
|
|
shape->SetLayer( klayer );
|
|
|
|
shape->SetWidth( aElem.linewidth );
|
|
|
|
shape->SetStart( aElem.referencePoint.at( i ) );
|
|
|
|
// shape->SetEnd( /* TODO: seems to be based on TEXTY */ );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ALTIUM_PCB::HelperParseDimensions6Center( const ADIMENSION6& aElem )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( aElem.layer );
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Dimension on Altium layer %d has no KiCad equivalent. "
|
|
|
|
"Put it on Eco1_User instead" ),
|
|
|
|
aElem.layer ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
2020-10-26 13:11:24 +00:00
|
|
|
wxPoint vec = wxPoint( 0, aElem.height / 2 );
|
|
|
|
RotatePoint( &vec, aElem.angle * 10. );
|
|
|
|
|
|
|
|
CENTER_DIMENSION* dimension = new CENTER_DIMENSION( m_board );
|
|
|
|
m_board->Add( dimension, ADD_MODE::APPEND );
|
|
|
|
dimension->SetLayer( klayer );
|
|
|
|
dimension->SetLineThickness( aElem.linewidth );
|
|
|
|
dimension->SetStart( aElem.xy1 );
|
|
|
|
dimension->SetEnd( aElem.xy1 + vec );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseDimensions6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
ADIMENSION6 elem( reader );
|
|
|
|
|
|
|
|
switch( elem.kind )
|
|
|
|
{
|
|
|
|
case ALTIUM_DIMENSION_KIND::LINEAR:
|
|
|
|
HelperParseDimensions6Linear( elem );
|
|
|
|
break;
|
|
|
|
case ALTIUM_DIMENSION_KIND::LEADER:
|
|
|
|
HelperParseDimensions6Leader( elem );
|
|
|
|
break;
|
|
|
|
case ALTIUM_DIMENSION_KIND::DATUM:
|
2020-05-10 18:12:47 +00:00
|
|
|
wxLogWarning( wxString::Format( "Ignore dimension object of kind %d", elem.kind ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
// HelperParseDimensions6Datum( elem );
|
|
|
|
break;
|
|
|
|
case ALTIUM_DIMENSION_KIND::CENTER:
|
|
|
|
HelperParseDimensions6Center( elem );
|
|
|
|
break;
|
|
|
|
default:
|
2020-05-10 18:12:47 +00:00
|
|
|
wxLogWarning( wxString::Format( "Ignore dimension object of kind %d", elem.kind ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Dimensions6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 13:34:06 +00:00
|
|
|
|
|
|
|
void ALTIUM_PCB::ParseModelsData( const CFB::CompoundFileReader& aReader,
|
2020-11-13 15:15:52 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry, const wxString aRootDir )
|
2020-04-21 13:34:06 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
2020-05-05 12:30:50 +00:00
|
|
|
if( reader.GetRemainingBytes() == 0 )
|
|
|
|
{
|
|
|
|
return; // fast path: no 3d-models present which need to be imported -> no directory needs to be created
|
|
|
|
}
|
|
|
|
|
|
|
|
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?
|
|
|
|
const wxString altiumModelDir = "ALTIUM_EMBEDDED_MODELS";
|
|
|
|
|
|
|
|
wxFileName altiumModelsPath = wxFileName::DirName( projectPath );
|
|
|
|
wxString kicadModelPrefix = "${KIPRJMOD}/" + altiumModelDir + "/";
|
|
|
|
if( !altiumModelsPath.AppendDir( altiumModelDir ) )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "Cannot construct directory path for step models" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create dir if it does not exist
|
|
|
|
if( !altiumModelsPath.DirExists() )
|
|
|
|
{
|
|
|
|
if( !altiumModelsPath.Mkdir() )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "Cannot create directory \"%s\" -> no 3D-models will be imported." ),
|
2020-10-16 00:39:55 +00:00
|
|
|
altiumModelsPath.GetFullPath() ) );
|
2020-05-05 12:30:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 13:34:06 +00:00
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
AMODEL elem( reader );
|
|
|
|
|
|
|
|
wxString stepPath = aRootDir + std::to_string( idx++ );
|
|
|
|
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* stepEntry = FindStream( aReader, stepPath.c_str() );
|
|
|
|
|
|
|
|
size_t stepSize = static_cast<size_t>( stepEntry->size );
|
|
|
|
std::unique_ptr<char[]> stepContent( new char[stepSize] );
|
|
|
|
|
|
|
|
// read file into buffer
|
|
|
|
aReader.ReadFile( stepEntry, 0, stepContent.get(), stepSize );
|
|
|
|
|
2020-05-05 12:30:50 +00:00
|
|
|
wxFileName storagePath( altiumModelsPath.GetPath(), elem.name );
|
|
|
|
if( !storagePath.IsDirWritable() )
|
|
|
|
{
|
|
|
|
wxLogError(
|
|
|
|
wxString::Format( _( "You do not have write permissions to save file \"%s\"." ),
|
2020-10-16 00:39:55 +00:00
|
|
|
storagePath.GetFullPath() ) );
|
2020-05-05 12:30:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-21 13:34:06 +00:00
|
|
|
|
|
|
|
wxMemoryInputStream stepStream( stepContent.get(), stepSize );
|
|
|
|
wxZlibInputStream zlibInputStream( stepStream );
|
|
|
|
|
2020-12-12 23:51:35 +00:00
|
|
|
wxFFileOutputStream outputStream( storagePath.GetFullPath() );
|
2020-04-21 13:34:06 +00:00
|
|
|
outputStream.Write( zlibInputStream );
|
|
|
|
outputStream.Close();
|
|
|
|
|
2020-05-05 12:30:50 +00:00
|
|
|
m_models.insert( { elem.id, kicadModelPrefix + elem.name } );
|
2020-04-21 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "Models stream is not fully parsed" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseNets6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
wxASSERT( m_num_nets == 0 );
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
ANET6 elem( reader );
|
|
|
|
|
|
|
|
m_board->Add( new NETINFO_ITEM( m_board, elem.name, ++m_num_nets ), ADD_MODE::APPEND );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Nets6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParsePolygons6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
APOLYGON6 elem( reader );
|
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Polygon on Altium layer %d has no KiCad equivalent. "
|
|
|
|
"Ignore it instead" ),
|
|
|
|
elem.layer ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
m_polygons.emplace_back( nullptr );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-22 15:23:12 +00:00
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, elem.vertices );
|
|
|
|
|
|
|
|
if( linechain.PointCount() < 2 )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogError( wxString::Format( _( "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;
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = new ZONE( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
|
|
|
m_polygons.emplace_back( zone );
|
|
|
|
|
|
|
|
zone->SetNetCode( GetNetCode( elem.net ) );
|
|
|
|
zone->SetLayer( klayer );
|
|
|
|
zone->SetPosition( elem.vertices.at( 0 ).position );
|
|
|
|
zone->SetLocked( elem.locked );
|
2020-05-10 17:30:03 +00:00
|
|
|
zone->SetPriority( 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
|
|
|
|
|
|
|
if( elem.pourindex > m_highest_pour_index )
|
|
|
|
m_highest_pour_index = elem.pourindex;
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
// TODO: more flexible rule parsing
|
|
|
|
const ARULE6* clearanceRule = GetRuleDefault( ALTIUM_RULE_KIND::PLANE_CLEARANCE );
|
2020-05-10 17:30:03 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( clearanceRule != nullptr )
|
|
|
|
{
|
2020-09-05 16:00:29 +00:00
|
|
|
zone->SetLocalClearance( clearanceRule->planeclearanceClearance );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
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.
|
|
|
|
zone->SetPriority( 1 );
|
|
|
|
|
|
|
|
// check if this is the outer zone by simply comparing the BBOX
|
|
|
|
const auto& cur_outer_plane = m_outer_plane.find( elem.layer );
|
|
|
|
if( cur_outer_plane == m_outer_plane.end()
|
|
|
|
|| zone->GetBoundingBox().Contains(
|
|
|
|
cur_outer_plane->second->GetBoundingBox() ) )
|
|
|
|
{
|
|
|
|
m_outer_plane[elem.layer] = zone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
const EDA_RECT& 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
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetHatchOrientation( elem.hatchstyle == ALTIUM_POLYGON_HATCHSTYLE::DEGREE_45 ? 45 : 0 );
|
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 );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Polygons6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseRules6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
ARULE6 elem( reader );
|
|
|
|
|
|
|
|
m_rules[elem.kind].emplace_back( elem );
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort rules by priority
|
|
|
|
for( auto&& val : m_rules )
|
|
|
|
{
|
|
|
|
std::sort( val.second.begin(), val.second.end(),
|
2020-11-13 15:15:52 +00:00
|
|
|
[]( const auto& lhs, const auto& rhs )
|
|
|
|
{
|
|
|
|
return lhs.priority < rhs.priority;
|
|
|
|
} );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Rules6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseBoardRegionsData( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
AREGION6 elem( reader, false );
|
|
|
|
|
|
|
|
// TODO: implement?
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "BoardRegions stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseShapeBasedRegions6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
AREGION6 elem( reader, true );
|
|
|
|
|
|
|
|
if( elem.kind == ALTIUM_REGION_KIND::BOARD_CUTOUT )
|
|
|
|
{
|
|
|
|
HelperCreateBoardOutline( elem.vertices );
|
|
|
|
}
|
2020-05-10 12:28:56 +00:00
|
|
|
else if( elem.kind == ALTIUM_REGION_KIND::POLYGON_CUTOUT || elem.is_keepout )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2020-10-22 15:23:12 +00:00
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, elem.vertices );
|
|
|
|
|
|
|
|
if( linechain.PointCount() < 2 )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "ShapeBasedRegion has only %d point extracted from %ld vertices. At least 2 points are required." ),
|
|
|
|
linechain.PointCount(), elem.vertices.size() ) );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = new ZONE( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
|
|
|
|
2020-09-21 23:32:07 +00:00
|
|
|
zone->SetIsRuleArea( true );
|
2020-05-10 12:28:56 +00:00
|
|
|
zone->SetDoNotAllowTracks( false );
|
|
|
|
zone->SetDoNotAllowVias( false );
|
|
|
|
zone->SetDoNotAllowPads( false );
|
|
|
|
zone->SetDoNotAllowFootprints( false );
|
|
|
|
zone->SetDoNotAllowCopperPour( true );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-10-22 15:23:12 +00:00
|
|
|
zone->SetPosition( elem.vertices.at( 0 ).position );
|
|
|
|
zone->Outline()->AddOutline( linechain );
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.layer == ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
zone->SetLayer( F_Cu );
|
|
|
|
zone->SetLayerSet( LSET::AllCuMask() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Zone on Altium layer %d has no KiCad "
|
|
|
|
"equivalent. Put it on Eco1_User instead" ),
|
|
|
|
elem.layer ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
zone->SetLayer( klayer );
|
|
|
|
}
|
|
|
|
|
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 );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else if( elem.kind == ALTIUM_REGION_KIND::COPPER )
|
|
|
|
{
|
|
|
|
if( elem.subpolyindex == ALTIUM_POLYGON_NONE )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Polygon on Altium layer %d has no KiCad "
|
|
|
|
"equivalent. Put it on Eco1_User instead" ),
|
|
|
|
elem.layer ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
2020-10-22 15:23:12 +00:00
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
HelperShapeLineChainFromAltiumVertices( linechain, elem.vertices );
|
|
|
|
|
|
|
|
if( linechain.PointCount() < 2 )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogError( wxString::Format( _( "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
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( m_board );
|
|
|
|
m_board->Add( shape, ADD_MODE::APPEND );
|
|
|
|
shape->SetShape( S_POLYGON );
|
2020-11-14 01:16:02 +00:00
|
|
|
shape->SetFilled( true );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( klayer );
|
|
|
|
shape->SetWidth( 0 );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-10-22 11:21:47 +00:00
|
|
|
shape->SetPolyShape( linechain );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogError( wxString::Format( "Ignore polygon shape of kind %d on layer %s, because "
|
|
|
|
"not implemented yet",
|
|
|
|
elem.kind,
|
|
|
|
LSET::Name( GetKicadLayer( elem.layer ) ) ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "ShapeBasedRegions6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseRegions6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_polygons )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
if( zone )
|
2020-04-03 23:22:24 +00:00
|
|
|
zone->UnFill(); // just to be sure
|
|
|
|
}
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
AREGION6 elem( reader, false );
|
|
|
|
|
|
|
|
#if 0 // TODO: it seems this code has multiple issues right now, and we can manually fill anyways
|
|
|
|
if( elem.subpolyindex != ALTIUM_POLYGON_NONE )
|
|
|
|
{
|
|
|
|
if( m_polygons.size() <= elem.subpolyindex )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
2020-04-05 09:22:40 +00:00
|
|
|
"Region stream tries to access polygon id %d of %d existing polygons",
|
2020-04-03 23:22:24 +00:00
|
|
|
elem.subpolyindex, m_polygons.size() ) );
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE *zone = m_polygons.at( elem.subpolyindex );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
if( zone == nullptr )
|
|
|
|
{
|
|
|
|
continue; // we know the zone id, but because we do not know the layer we did not add it!
|
|
|
|
}
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN linechain;
|
|
|
|
for( auto& vertice : elem.vertices )
|
|
|
|
{
|
|
|
|
linechain.Append( vertice.position );
|
|
|
|
}
|
|
|
|
linechain.Append( elem.vertices.at( 0 ).position );
|
|
|
|
linechain.SetClosed( true );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET polyset;
|
|
|
|
polyset.AddOutline( linechain );
|
|
|
|
polyset.BooleanAdd( zone->GetFilledPolysList(), SHAPE_POLY_SET::POLYGON_MODE::PM_STRICTLY_SIMPLE );
|
|
|
|
|
|
|
|
zone->SetFilledPolysList( polyset );
|
|
|
|
zone->SetIsFilled( true );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Regions6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
|
|
|
|
void ALTIUM_PCB::ParseArcs6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
AARC6 elem( reader );
|
|
|
|
|
|
|
|
if( elem.is_polygonoutline || elem.subpolyindex != ALTIUM_POLYGON_NONE )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// element in plane is in fact substracted from the plane. Should be already done by Altium?
|
2020-10-04 23:34:59 +00:00
|
|
|
//if( IsAltiumLayerAPlane( elem.layer ) )
|
|
|
|
// continue;
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.is_keepout || IsAltiumLayerAPlane( elem.layer ) )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE shape( nullptr ); // just a helper to get the graphic
|
|
|
|
shape.SetWidth( elem.width );
|
|
|
|
shape.SetCenter( elem.center );
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.startangle == 0. && elem.endangle == 360. )
|
|
|
|
{ // TODO: other variants to define circle?
|
2020-10-04 23:34:59 +00:00
|
|
|
shape.SetShape( S_CIRCLE );
|
|
|
|
shape.SetArcStart( elem.center - wxPoint( 0, elem.radius ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
shape.SetShape( S_ARC );
|
|
|
|
shape.SetAngle( -NormalizeAngleDegreesPos( elem.endangle - elem.startangle ) * 10. );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
double startradiant = DEG2RAD( elem.startangle );
|
|
|
|
wxPoint arcStartOffset = wxPoint( KiROUND( std::cos( startradiant ) * elem.radius ),
|
|
|
|
-KiROUND( std::sin( startradiant ) * elem.radius ) );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape.SetArcStart( elem.center + arcStartOffset );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = new ZONE( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
|
|
|
|
2020-09-21 23:32:07 +00:00
|
|
|
zone->SetIsRuleArea( true );
|
2020-04-03 23:22:24 +00:00
|
|
|
zone->SetDoNotAllowTracks( false );
|
|
|
|
zone->SetDoNotAllowVias( false );
|
2020-05-07 00:30:46 +00:00
|
|
|
zone->SetDoNotAllowPads( false );
|
|
|
|
zone->SetDoNotAllowFootprints( false );
|
2020-04-03 23:22:24 +00:00
|
|
|
zone->SetDoNotAllowCopperPour( true );
|
|
|
|
|
2020-10-20 08:35:58 +00:00
|
|
|
if( elem.layer == ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
zone->SetLayer( F_Cu );
|
|
|
|
zone->SetLayerSet( LSET::AllCuMask() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Arc Keepout on Altium layer %d has no "
|
|
|
|
"KiCad equivalent. Put it on Eco1_User instead" ),
|
|
|
|
elem.layer ) );
|
2020-10-20 08:35:58 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
zone->SetLayer( klayer );
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape.TransformShapeWithClearanceToPolygon( *zone->Outline(), klayer, 0, ARC_HIGH_DEF,
|
2020-10-13 10:55:24 +00:00
|
|
|
ERROR_INSIDE );
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->Outline()->Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); // the outline is not a single polygon!
|
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 );
|
2020-04-03 23:22:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-20 08:35:58 +00:00
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Arc on Altium layer %d has no KiCad equivalent. "
|
|
|
|
"Put it on Eco1_User instead" ),
|
|
|
|
elem.layer ) );
|
2020-10-20 08:35:58 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( klayer >= F_Cu && klayer <= B_Cu )
|
|
|
|
{
|
|
|
|
double angle = -NormalizeAngleDegreesPos( elem.endangle - elem.startangle );
|
|
|
|
double startradiant = DEG2RAD( elem.startangle );
|
|
|
|
wxPoint arcStartOffset = wxPoint( KiROUND( std::cos( startradiant ) * elem.radius ),
|
|
|
|
-KiROUND( std::sin( startradiant ) * elem.radius ) );
|
|
|
|
|
|
|
|
SHAPE_ARC shapeArc( elem.center, elem.center + arcStartOffset, angle, elem.width );
|
|
|
|
ARC* arc = new ARC( m_board, &shapeArc );
|
|
|
|
m_board->Add( arc, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
arc->SetWidth( elem.width );
|
|
|
|
arc->SetLayer( klayer );
|
|
|
|
arc->SetNetCode( GetNetCode( elem.net ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = HelperCreateAndAddDrawsegment( elem.component );
|
|
|
|
shape->SetCenter( elem.center );
|
|
|
|
shape->SetWidth( elem.width );
|
|
|
|
shape->SetLayer( klayer );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
if( elem.startangle == 0. && elem.endangle == 360. )
|
|
|
|
{ // TODO: other variants to define circle?
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetShape( S_CIRCLE );
|
|
|
|
shape->SetArcStart( elem.center - wxPoint( 0, elem.radius ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetShape( S_ARC );
|
|
|
|
shape->SetAngle( -NormalizeAngleDegreesPos( elem.endangle - elem.startangle ) * 10. );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
double startradiant = DEG2RAD( elem.startangle );
|
|
|
|
wxPoint arcStartOffset = wxPoint( KiROUND( std::cos( startradiant ) * elem.radius ),
|
|
|
|
-KiROUND( std::sin( startradiant ) * elem.radius ) );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetArcStart( elem.center + arcStartOffset );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
HelperDrawsegmentSetLocalCoord( shape, elem.component );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Arcs6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
|
|
|
|
void ALTIUM_PCB::ParsePads6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
APAD6 elem( reader );
|
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
// It is possible to place altium pads on non-copper layers -> we need to interpolate them using drawings!
|
|
|
|
if( !IsAltiumLayerCopper( elem.layer ) && !IsAltiumLayerAPlane( elem.layer )
|
|
|
|
&& elem.layer != ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
HelperParsePad6NonCopper( elem );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
// Create Pad
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = nullptr;
|
2020-11-13 11:17:15 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.component == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint = new FOOTPRINT( m_board ); // We cannot add a pad directly into the PCB
|
2020-11-13 11:17:15 +00:00
|
|
|
m_board->Add( footprint, ADD_MODE::APPEND );
|
|
|
|
footprint->SetPosition( elem.position );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( m_components.size() <= elem.component )
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( "Pads6 stream tries to access component id %d "
|
|
|
|
"of %d existing components",
|
|
|
|
elem.component,
|
|
|
|
m_components.size() ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint = m_components.at( elem.component );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
PAD* pad = new PAD( footprint );
|
|
|
|
footprint->Add( pad, ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
pad->SetName( elem.name );
|
|
|
|
pad->SetNetCode( GetNetCode( elem.net ) );
|
|
|
|
pad->SetLocked( elem.is_locked );
|
|
|
|
|
|
|
|
pad->SetPosition( elem.position );
|
|
|
|
pad->SetOrientationDegrees( elem.direction );
|
|
|
|
pad->SetLocalCoord();
|
|
|
|
|
|
|
|
pad->SetSize( elem.topsize );
|
|
|
|
|
|
|
|
if( elem.holesize == 0 )
|
|
|
|
{
|
|
|
|
pad->SetAttribute( PAD_ATTR_T::PAD_ATTRIB_SMD );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( elem.layer != ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
// TODO: I assume other values are possible as well?
|
|
|
|
wxLogError( wxString::Format(
|
2020-11-13 11:17:15 +00:00
|
|
|
"Pad '%s' of Footprint %s is not marked as multilayer, but it is an THT pad",
|
|
|
|
elem.name, footprint->GetReference() ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2020-09-30 15:38:35 +00:00
|
|
|
pad->SetAttribute( elem.plated ? PAD_ATTR_T::PAD_ATTRIB_PTH :
|
|
|
|
PAD_ATTR_T::PAD_ATTRIB_NPTH );
|
2020-04-03 23:22:24 +00:00
|
|
|
if( !elem.sizeAndShape || elem.sizeAndShape->holeshape == ALTIUM_PAD_HOLE_SHAPE::ROUND )
|
|
|
|
{
|
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_CIRCLE );
|
|
|
|
pad->SetDrillSize( wxSize( elem.holesize, elem.holesize ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( elem.sizeAndShape->holeshape )
|
|
|
|
{
|
|
|
|
case ALTIUM_PAD_HOLE_SHAPE::ROUND:
|
2020-04-05 09:22:40 +00:00
|
|
|
wxFAIL_MSG( "Round holes are handled before the switch" );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_PAD_HOLE_SHAPE::SQUARE:
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Pad '%s' of Footprint %s has a square hole. "
|
|
|
|
"KiCad does not support this yet" ),
|
|
|
|
elem.name,
|
|
|
|
footprint->GetReference() ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_CIRCLE );
|
|
|
|
pad->SetDrillSize( wxSize( elem.holesize, elem.holesize ) ); // Workaround
|
|
|
|
// TODO: elem.sizeAndShape->slotsize was 0 in testfile. Either use holesize in this case or rect holes have a different id
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_PAD_HOLE_SHAPE::SLOT:
|
|
|
|
{
|
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_OBLONG );
|
|
|
|
double normalizedSlotrotation =
|
|
|
|
NormalizeAngleDegreesPos( elem.sizeAndShape->slotrotation );
|
|
|
|
if( normalizedSlotrotation == 0. || normalizedSlotrotation == 180. )
|
|
|
|
{
|
|
|
|
pad->SetDrillSize( wxSize( elem.sizeAndShape->slotsize, elem.holesize ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( normalizedSlotrotation != 90. && normalizedSlotrotation != 270. )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Pad '%s' of Footprint %s has a "
|
|
|
|
"hole-rotation of %f degree. KiCad "
|
|
|
|
"only supports 90 degree angles" ),
|
|
|
|
elem.name,
|
|
|
|
footprint->GetReference(),
|
|
|
|
normalizedSlotrotation ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetDrillSize( wxSize( elem.holesize, elem.sizeAndShape->slotsize ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case ALTIUM_PAD_HOLE_SHAPE::UNKNOWN:
|
|
|
|
wxLogError( wxString::Format(
|
2020-11-13 11:17:15 +00:00
|
|
|
"Pad '%s' of Footprint %s uses a hole of unknown kind %d", elem.name,
|
|
|
|
footprint->GetReference(), elem.sizeAndShape->holeshape ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_CIRCLE );
|
|
|
|
pad->SetDrillSize( wxSize( elem.holesize, elem.holesize ) ); // Workaround
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-05-06 07:17:43 +00:00
|
|
|
|
|
|
|
if( elem.sizeAndShape )
|
|
|
|
{
|
|
|
|
pad->SetOffset( elem.sizeAndShape->holeoffset[0] );
|
|
|
|
}
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( elem.padmode != ALTIUM_PAD_MODE::SIMPLE )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
2020-11-13 11:17:15 +00:00
|
|
|
_( "Pad '%s' of Footprint %s uses a complex pad stack (kind %d), which is not supported yet" ),
|
|
|
|
elem.name, footprint->GetReference(), elem.padmode ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( elem.topshape )
|
|
|
|
{
|
|
|
|
case ALTIUM_PAD_SHAPE::RECT:
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_RECT );
|
|
|
|
break;
|
|
|
|
case ALTIUM_PAD_SHAPE::CIRCLE:
|
|
|
|
if( elem.sizeAndShape
|
|
|
|
&& elem.sizeAndShape->alt_shape[0] == ALTIUM_PAD_SHAPE_ALT::ROUNDRECT )
|
|
|
|
{
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_ROUNDRECT ); // 100 = round, 0 = rectangular
|
|
|
|
double ratio = elem.sizeAndShape->cornerradius[0] / 200.;
|
|
|
|
pad->SetRoundRectRadiusRatio( ratio );
|
|
|
|
}
|
|
|
|
else if( elem.topsize.x == elem.topsize.y )
|
|
|
|
{
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_CIRCLE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_OVAL );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ALTIUM_PAD_SHAPE::OCTAGONAL:
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_CHAMFERED_RECT );
|
|
|
|
pad->SetChamferPositions( RECT_CHAMFER_ALL );
|
|
|
|
pad->SetChamferRectRatio( 0.25 );
|
|
|
|
break;
|
|
|
|
case ALTIUM_PAD_SHAPE::UNKNOWN:
|
|
|
|
default:
|
2020-04-05 11:45:55 +00:00
|
|
|
wxLogError( wxString::Format( "Pad '%s' of Footprint %s uses a unknown pad-shape",
|
2020-11-13 11:17:15 +00:00
|
|
|
elem.name, footprint->GetReference() ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( elem.layer )
|
|
|
|
{
|
|
|
|
case ALTIUM_LAYER::TOP_LAYER:
|
|
|
|
pad->SetLayer( F_Cu );
|
2020-11-12 22:30:02 +00:00
|
|
|
pad->SetLayerSet( PAD::SMDMask() );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_LAYER::BOTTOM_LAYER:
|
|
|
|
pad->SetLayer( B_Cu );
|
2020-11-12 22:30:02 +00:00
|
|
|
pad->SetLayerSet( FlipLayerMask( PAD::SMDMask() ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_LAYER::MULTI_LAYER:
|
2020-11-12 22:30:02 +00:00
|
|
|
pad->SetLayerSet( elem.plated ? PAD::PTHMask() : PAD::UnplatedHoleMask() );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
2020-04-18 21:47:53 +00:00
|
|
|
default:
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
|
|
|
pad->SetLayer( klayer );
|
2020-05-06 07:22:26 +00:00
|
|
|
pad->SetLayerSet( LSET( 1, klayer ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
break;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( elem.pastemaskexpansionmode == ALTIUM_PAD_RULE::MANUAL )
|
|
|
|
{
|
|
|
|
pad->SetLocalSolderPasteMargin( elem.pastemaskexpansionmanual );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( elem.soldermaskexpansionmode == ALTIUM_PAD_RULE::MANUAL )
|
|
|
|
{
|
|
|
|
pad->SetLocalSolderMaskMargin( elem.soldermaskexpansionmanual );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( elem.is_tent_top )
|
|
|
|
{
|
|
|
|
pad->SetLayerSet( pad->GetLayerSet().reset( F_Mask ) );
|
|
|
|
}
|
|
|
|
if( elem.is_tent_bottom )
|
|
|
|
{
|
|
|
|
pad->SetLayerSet( pad->GetLayerSet().reset( B_Mask ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Pads6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
void ALTIUM_PCB::HelperParsePad6NonCopper( const APAD6& aElem )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2020-11-14 01:16:02 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Non-Copper Pad on Altium layer %d has no KiCad "
|
|
|
|
"equivalent. Put it on Eco1_User instead" ),
|
|
|
|
aElem.layer ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.net != ALTIUM_NET_UNCONNECTED )
|
|
|
|
{
|
2020-11-14 01:16:02 +00:00
|
|
|
wxLogError( wxString::Format( "Non-Copper Pad '%s' is connected to a net. This is not "
|
|
|
|
"supported",
|
|
|
|
aElem.name ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.holesize != 0 )
|
|
|
|
{
|
2020-11-14 01:16:02 +00:00
|
|
|
wxLogError( wxString::Format( _( "Non-Copper Pad '%s' has a hole. This should not happen" ),
|
|
|
|
aElem.name ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.padmode != ALTIUM_PAD_MODE::SIMPLE )
|
|
|
|
{
|
2020-11-14 01:16:02 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Non-Copper Pad '%s' uses a complex pad stack (kind %d). "
|
|
|
|
"This should not happen" ),
|
|
|
|
aElem.name,
|
|
|
|
aElem.padmode ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( aElem.topshape )
|
|
|
|
{
|
|
|
|
case ALTIUM_PAD_SHAPE::RECT:
|
|
|
|
{
|
|
|
|
// filled rect
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = HelperCreateAndAddDrawsegment( aElem.component );
|
|
|
|
shape->SetShape( S_POLYGON );
|
2020-11-14 01:16:02 +00:00
|
|
|
shape->SetFilled( true );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( klayer );
|
|
|
|
shape->SetWidth( 0 );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetPolyPoints( { aElem.position + wxPoint( aElem.topsize.x / 2, aElem.topsize.y / 2 ),
|
2020-04-18 21:47:53 +00:00
|
|
|
aElem.position + wxPoint( aElem.topsize.x / 2, -aElem.topsize.y / 2 ),
|
|
|
|
aElem.position + wxPoint( -aElem.topsize.x / 2, -aElem.topsize.y / 2 ),
|
|
|
|
aElem.position + wxPoint( -aElem.topsize.x / 2, aElem.topsize.y / 2 ) } );
|
|
|
|
|
|
|
|
if( aElem.direction != 0 )
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->Rotate( aElem.position, aElem.direction * 10 );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
HelperDrawsegmentSetLocalCoord( shape, aElem.component );
|
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;
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = HelperCreateAndAddDrawsegment( aElem.component );
|
|
|
|
shape->SetLayer( klayer );
|
|
|
|
shape->SetWidth( offset * 2 );
|
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;
|
|
|
|
|
|
|
|
wxPoint p11 = aElem.position + wxPoint( offsetX, offsetY );
|
|
|
|
wxPoint p12 = aElem.position + wxPoint( offsetX, -offsetY );
|
|
|
|
wxPoint p22 = aElem.position + wxPoint( -offsetX, -offsetY );
|
|
|
|
wxPoint p21 = aElem.position + wxPoint( -offsetX, offsetY );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetShape( S_POLYGON );
|
2021-01-14 21:18:46 +00:00
|
|
|
shape->SetFilled( true );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetPolyPoints( { p11, p12, p22, p21 } );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else if( aElem.topsize.x == aElem.topsize.y )
|
|
|
|
{
|
|
|
|
// circle
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetShape( S_CIRCLE );
|
2020-11-14 01:16:02 +00:00
|
|
|
shape->SetFilled( true );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetCenter( aElem.position );
|
|
|
|
shape->SetWidth( aElem.topsize.x / 2 );
|
|
|
|
shape->SetArcStart( aElem.position - wxPoint( 0, aElem.topsize.x / 4 ) );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else if( aElem.topsize.x < aElem.topsize.y )
|
|
|
|
{
|
|
|
|
// short vertical line
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetShape( S_SEGMENT );
|
2020-04-18 21:47:53 +00:00
|
|
|
wxPoint pointOffset( 0, ( aElem.topsize.y - aElem.topsize.x ) / 2 );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetStart( aElem.position + pointOffset );
|
|
|
|
shape->SetEnd( aElem.position - pointOffset );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// short horizontal line
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetShape( S_SEGMENT );
|
2020-04-18 21:47:53 +00:00
|
|
|
wxPoint pointOffset( ( aElem.topsize.x - aElem.topsize.y ) / 2, 0 );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetStart( aElem.position + pointOffset );
|
|
|
|
shape->SetEnd( aElem.position - pointOffset );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aElem.direction != 0 )
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->Rotate( aElem.position, aElem.direction * 10 );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
HelperDrawsegmentSetLocalCoord( shape, aElem.component );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else if( aElem.topsize.x == aElem.topsize.y )
|
|
|
|
{
|
|
|
|
// filled circle
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = HelperCreateAndAddDrawsegment( aElem.component );
|
|
|
|
shape->SetShape( S_CIRCLE );
|
2020-11-14 01:16:02 +00:00
|
|
|
shape->SetFilled( true );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( klayer );
|
|
|
|
shape->SetCenter( aElem.position );
|
|
|
|
shape->SetWidth( aElem.topsize.x / 2 );
|
|
|
|
shape->SetArcStart( aElem.position - wxPoint( 0, aElem.topsize.x / 4 ) );
|
|
|
|
HelperDrawsegmentSetLocalCoord( shape, aElem.component );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// short line
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = HelperCreateAndAddDrawsegment( aElem.component );
|
|
|
|
shape->SetShape( S_SEGMENT );
|
|
|
|
shape->SetLayer( klayer );
|
|
|
|
shape->SetWidth( std::min( aElem.topsize.x, aElem.topsize.y ) );
|
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
if( aElem.topsize.x < aElem.topsize.y )
|
|
|
|
{
|
|
|
|
wxPoint offset( 0, ( aElem.topsize.y - aElem.topsize.x ) / 2 );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetStart( aElem.position + offset );
|
|
|
|
shape->SetEnd( aElem.position - offset );
|
2020-04-18 21:47:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint offset( ( aElem.topsize.x - aElem.topsize.y ) / 2, 0 );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetStart( aElem.position + offset );
|
|
|
|
shape->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 )
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->Rotate( aElem.position, aElem.direction * 10. );
|
|
|
|
|
|
|
|
HelperDrawsegmentSetLocalCoord( shape, aElem.component );
|
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
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = HelperCreateAndAddDrawsegment( aElem.component );
|
|
|
|
shape->SetShape( S_POLYGON );
|
2020-11-14 01:16:02 +00:00
|
|
|
shape->SetFilled( true );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( klayer );
|
|
|
|
shape->SetWidth( 0 );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
|
|
|
wxPoint p11 = aElem.position + wxPoint( aElem.topsize.x / 2, aElem.topsize.y / 2 );
|
|
|
|
wxPoint p12 = aElem.position + wxPoint( aElem.topsize.x / 2, -aElem.topsize.y / 2 );
|
|
|
|
wxPoint p22 = aElem.position + wxPoint( -aElem.topsize.x / 2, -aElem.topsize.y / 2 );
|
|
|
|
wxPoint p21 = aElem.position + wxPoint( -aElem.topsize.x / 2, aElem.topsize.y / 2 );
|
|
|
|
|
|
|
|
int chamfer = std::min( aElem.topsize.x, aElem.topsize.y ) / 4;
|
|
|
|
wxPoint chamferX( chamfer, 0 );
|
|
|
|
wxPoint chamferY( 0, chamfer );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->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. )
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->Rotate( aElem.position, aElem.direction * 10 );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
HelperDrawsegmentSetLocalCoord( shape, aElem.component );
|
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:
|
|
|
|
wxLogError(
|
|
|
|
wxString::Format( "Non-Copper Pad '%s' uses a unknown pad-shape", aElem.name ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void ALTIUM_PCB::ParseVias6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
AVIA6 elem( reader );
|
|
|
|
|
|
|
|
VIA* via = new VIA( m_board );
|
|
|
|
m_board->Add( via, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
if( !IsCopperLayer( start_klayer ) || !IsCopperLayer( end_klayer ) )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format(
|
2020-04-05 11:45:55 +00:00
|
|
|
"Via from layer %d <-> %d uses non-copper layer. This should not happen.",
|
2020-04-03 23:22:24 +00:00
|
|
|
elem.layer_start, elem.layer_end ) );
|
|
|
|
continue; // just assume through-hole instead.
|
|
|
|
}
|
|
|
|
|
|
|
|
// we need VIATYPE set!
|
|
|
|
via->SetLayerPair( start_klayer, end_klayer );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Vias6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void ALTIUM_PCB::ParseTracks6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
ATRACK6 elem( reader );
|
|
|
|
|
|
|
|
if( elem.is_polygonoutline || elem.subpolyindex != ALTIUM_POLYGON_NONE )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// element in plane is in fact substracted from the plane. Already done by Altium?
|
2020-10-04 23:34:59 +00:00
|
|
|
//if( IsAltiumLayerAPlane( elem.layer ) )
|
|
|
|
// continue;
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
|
|
|
|
|
|
|
if( elem.is_keepout || IsAltiumLayerAPlane( elem.layer ) )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE shape( nullptr ); // just a helper to get the graphic
|
|
|
|
shape.SetShape( S_SEGMENT );
|
|
|
|
shape.SetStart( elem.start );
|
|
|
|
shape.SetEnd( elem.end );
|
|
|
|
shape.SetWidth( elem.width );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = new ZONE( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
2020-10-20 08:35:58 +00:00
|
|
|
|
2020-09-21 23:32:07 +00:00
|
|
|
zone->SetIsRuleArea( true );
|
2020-04-03 23:22:24 +00:00
|
|
|
zone->SetDoNotAllowTracks( false );
|
|
|
|
zone->SetDoNotAllowVias( false );
|
2020-05-07 00:30:46 +00:00
|
|
|
zone->SetDoNotAllowPads( false );
|
|
|
|
zone->SetDoNotAllowFootprints( false );
|
2020-04-03 23:22:24 +00:00
|
|
|
zone->SetDoNotAllowCopperPour( true );
|
|
|
|
|
2020-10-20 08:35:58 +00:00
|
|
|
if( elem.layer == ALTIUM_LAYER::MULTI_LAYER )
|
|
|
|
{
|
|
|
|
zone->SetLayer( F_Cu );
|
|
|
|
zone->SetLayerSet( LSET::AllCuMask() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "Track Keepout on Altium layer %d has no KiCad equivalent. Put it on Eco1_User instead" ),
|
|
|
|
elem.layer ) );
|
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
zone->SetLayer( klayer );
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape.TransformShapeWithClearanceToPolygon( *zone->Outline(), klayer, 0, ARC_HIGH_DEF,
|
2020-10-13 10:55:24 +00:00
|
|
|
ERROR_INSIDE );
|
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 );
|
2020-04-03 23:22:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-20 08:35:58 +00:00
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "Track on Altium layer %d has no KiCad equivalent. Put it on Eco1_User instead" ),
|
|
|
|
elem.layer ) );
|
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( klayer >= F_Cu && klayer <= B_Cu )
|
|
|
|
{
|
|
|
|
TRACK* track = new TRACK( m_board );
|
|
|
|
m_board->Add( track, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
track->SetStart( elem.start );
|
|
|
|
track->SetEnd( elem.end );
|
|
|
|
track->SetWidth( elem.width );
|
|
|
|
track->SetLayer( klayer );
|
|
|
|
track->SetNetCode( GetNetCode( elem.net ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = HelperCreateAndAddDrawsegment( elem.component );
|
|
|
|
shape->SetShape( S_SEGMENT );
|
|
|
|
shape->SetStart( elem.start );
|
|
|
|
shape->SetEnd( elem.end );
|
|
|
|
shape->SetWidth( elem.width );
|
|
|
|
shape->SetLayer( klayer );
|
|
|
|
HelperDrawsegmentSetLocalCoord( shape, elem.component );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reader.SkipSubrecord();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Tracks6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void ALTIUM_PCB::ParseTexts6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
ATEXT6 elem( reader );
|
|
|
|
|
2020-05-10 18:11:24 +00:00
|
|
|
if( elem.fonttype == ALTIUM_TEXT_TYPE::BARCODE )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "Ignore Barcode on Altium layer %d because it is not supported right now." ),
|
|
|
|
elem.layer ) );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-13 21:07:01 +00:00
|
|
|
// TODO: better approach to select if item belongs to a FOOTPRINT
|
2020-04-03 23:22:24 +00:00
|
|
|
EDA_TEXT* tx = nullptr;
|
|
|
|
BOARD_ITEM* itm = nullptr;
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.component == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_TEXT* pcbText = new PCB_TEXT( m_board );
|
|
|
|
tx = pcbText;
|
|
|
|
itm = pcbText;
|
|
|
|
m_board->Add( pcbText, ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( m_components.size() <= elem.component )
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( "Texts6 stream tries to access component id %d "
|
|
|
|
"of %d existing components",
|
|
|
|
elem.component,
|
|
|
|
m_components.size() ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = m_components.at( elem.component );
|
|
|
|
FP_TEXT* fpText;
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.isDesignator )
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
fpText = &footprint->Reference();
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else if( elem.isComment )
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
fpText = &footprint->Value();
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
fpText = new FP_TEXT( footprint );
|
|
|
|
footprint->Add( fpText, ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
fpText->SetKeepUpright( false );
|
2020-05-10 15:27:29 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
tx = fpText;
|
|
|
|
itm = fpText;
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
2020-04-19 09:36:57 +00:00
|
|
|
wxString trimmedText = elem.text.Trim();
|
|
|
|
if( !elem.isDesignator && trimmedText.CmpNoCase( ".Designator" ) == 0 )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2020-04-06 16:14:04 +00:00
|
|
|
tx->SetText( "${REFERENCE}" );
|
|
|
|
}
|
2020-04-19 09:36:57 +00:00
|
|
|
else if( !elem.isComment && trimmedText.CmpNoCase( ".Comment" ) == 0 )
|
2020-04-06 16:14:04 +00:00
|
|
|
{
|
|
|
|
tx->SetText( "${VALUE}" );
|
|
|
|
}
|
2020-04-19 09:36:57 +00:00
|
|
|
else if( trimmedText.CmpNoCase( ".Layer_Name" ) == 0 )
|
2020-04-06 16:14:04 +00:00
|
|
|
{
|
|
|
|
tx->SetText( "${LAYER}" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tx->SetText( elem.text );
|
|
|
|
}
|
|
|
|
|
|
|
|
itm->SetPosition( elem.position );
|
|
|
|
tx->SetTextAngle( elem.rotation * 10. );
|
2020-04-04 11:41:45 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.component != ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2020-11-15 21:41:38 +00:00
|
|
|
FP_TEXT* fpText = dynamic_cast<FP_TEXT*>( tx );
|
2020-04-04 11:41:45 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
if( fpText )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
2020-11-15 21:41:38 +00:00
|
|
|
FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( fpText->GetParent() );
|
|
|
|
double orientation = parentFootprint->GetOrientation();
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
fpText->SetTextAngle( fpText->GetTextAngle() - orientation );
|
|
|
|
fpText->SetLocalCoord();
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-05-10 18:12:47 +00:00
|
|
|
wxLogWarning( wxString::Format(
|
2020-04-03 23:22:24 +00:00
|
|
|
_( "Text on Altium layer %d has no KiCad equivalent. Put it on Eco1_User instead" ),
|
|
|
|
elem.layer ) );
|
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
itm->SetLayer( klayer );
|
|
|
|
|
2020-05-10 18:11:24 +00:00
|
|
|
if( elem.fonttype == ALTIUM_TEXT_TYPE::TRUETYPE )
|
2020-05-10 15:27:29 +00:00
|
|
|
{
|
|
|
|
// TODO: why is this required? Somehow, truetype size is calculated differently
|
|
|
|
tx->SetTextSize( wxSize( elem.height / 2, elem.height / 2 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tx->SetTextSize( wxSize( elem.height, elem.height ) ); // TODO: parse text width
|
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
tx->SetTextThickness( elem.strokewidth );
|
2020-05-10 16:51:38 +00:00
|
|
|
tx->SetBold( elem.isBold );
|
|
|
|
tx->SetItalic( elem.isItalic );
|
|
|
|
tx->SetMirrored( elem.isMirrored );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
if( elem.isDesignator || elem.isComment ) // That's just a bold assumption
|
|
|
|
{
|
|
|
|
tx->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
tx->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( elem.textposition )
|
|
|
|
{
|
|
|
|
case ALTIUM_TEXT_POSITION::LEFT_TOP:
|
|
|
|
case ALTIUM_TEXT_POSITION::LEFT_CENTER:
|
|
|
|
case ALTIUM_TEXT_POSITION::LEFT_BOTTOM:
|
|
|
|
tx->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
case ALTIUM_TEXT_POSITION::CENTER_TOP:
|
|
|
|
case ALTIUM_TEXT_POSITION::CENTER_CENTER:
|
|
|
|
case ALTIUM_TEXT_POSITION::CENTER_BOTTOM:
|
|
|
|
tx->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
case ALTIUM_TEXT_POSITION::RIGHT_TOP:
|
|
|
|
case ALTIUM_TEXT_POSITION::RIGHT_CENTER:
|
|
|
|
case ALTIUM_TEXT_POSITION::RIGHT_BOTTOM:
|
|
|
|
tx->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
default:
|
2020-04-05 09:22:40 +00:00
|
|
|
wxLogError( "Unexpected horizontal Text Position. This should never happen." );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( elem.textposition )
|
|
|
|
{
|
|
|
|
case ALTIUM_TEXT_POSITION::LEFT_TOP:
|
|
|
|
case ALTIUM_TEXT_POSITION::CENTER_TOP:
|
|
|
|
case ALTIUM_TEXT_POSITION::RIGHT_TOP:
|
|
|
|
tx->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
case ALTIUM_TEXT_POSITION::LEFT_CENTER:
|
|
|
|
case ALTIUM_TEXT_POSITION::CENTER_CENTER:
|
|
|
|
case ALTIUM_TEXT_POSITION::RIGHT_CENTER:
|
|
|
|
tx->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
case ALTIUM_TEXT_POSITION::LEFT_BOTTOM:
|
|
|
|
case ALTIUM_TEXT_POSITION::CENTER_BOTTOM:
|
|
|
|
case ALTIUM_TEXT_POSITION::RIGHT_BOTTOM:
|
|
|
|
tx->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
default:
|
2020-04-05 09:22:40 +00:00
|
|
|
wxLogError( "Unexpected vertical text position. This should never happen." );
|
2020-04-03 23:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Texts6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
void ALTIUM_PCB::ParseFills6Data( const CFB::CompoundFileReader& aReader,
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry )
|
2020-04-03 23:22:24 +00:00
|
|
|
{
|
|
|
|
ALTIUM_PARSER reader( aReader, aEntry );
|
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
|
|
|
|
{
|
|
|
|
AFILL6 elem( reader );
|
|
|
|
|
|
|
|
wxPoint p11( elem.pos1.x, elem.pos1.y );
|
|
|
|
wxPoint p12( elem.pos1.x, elem.pos2.y );
|
|
|
|
wxPoint p22( elem.pos2.x, elem.pos2.y );
|
|
|
|
wxPoint p21( elem.pos2.x, elem.pos1.y );
|
|
|
|
|
|
|
|
wxPoint center( ( elem.pos1.x + elem.pos2.x ) / 2, ( elem.pos1.y + elem.pos2.y ) / 2 );
|
|
|
|
|
|
|
|
PCB_LAYER_ID klayer = GetKicadLayer( elem.layer );
|
|
|
|
if( klayer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-14 01:16:02 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "Fill on Altium layer %d has no KiCad equivalent. "
|
|
|
|
"Put it on Eco1_User instead" ),
|
|
|
|
elem.layer ) );
|
2020-04-03 23:22:24 +00:00
|
|
|
klayer = Eco1_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( elem.is_keepout || elem.net != ALTIUM_NET_UNCONNECTED )
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = new ZONE( m_board );
|
2020-04-03 23:22:24 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
zone->SetNetCode( GetNetCode( elem.net ) );
|
|
|
|
zone->SetLayer( klayer );
|
|
|
|
zone->SetPosition( elem.pos1 );
|
|
|
|
zone->SetPriority( 1000 );
|
|
|
|
|
2020-04-05 22:26:29 +00:00
|
|
|
const int outlineIdx = -1; // this is the id of the copper zone main outline
|
|
|
|
zone->AppendCorner( p11, outlineIdx );
|
|
|
|
zone->AppendCorner( p12, outlineIdx );
|
|
|
|
zone->AppendCorner( p22, outlineIdx );
|
|
|
|
zone->AppendCorner( p21, outlineIdx );
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
// should be correct?
|
2020-09-05 16:00:29 +00:00
|
|
|
zone->SetLocalClearance( 0 );
|
2020-04-03 23:22:24 +00:00
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::FULL );
|
|
|
|
|
|
|
|
if( elem.is_keepout )
|
|
|
|
{
|
2020-09-21 23:32:07 +00:00
|
|
|
zone->SetIsRuleArea( true );
|
2020-04-03 23:22:24 +00:00
|
|
|
zone->SetDoNotAllowTracks( false );
|
|
|
|
zone->SetDoNotAllowVias( false );
|
2020-05-07 00:30:46 +00:00
|
|
|
zone->SetDoNotAllowPads( false );
|
|
|
|
zone->SetDoNotAllowFootprints( false );
|
2020-04-03 23:22:24 +00:00
|
|
|
zone->SetDoNotAllowCopperPour( true );
|
|
|
|
}
|
|
|
|
|
2020-04-05 22:26:29 +00:00
|
|
|
if( elem.rotation != 0. )
|
|
|
|
zone->Rotate( center, elem.rotation * 10 );
|
|
|
|
|
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 );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( m_board );
|
|
|
|
m_board->Add( shape, ADD_MODE::APPEND );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetShape( S_POLYGON );
|
2020-11-14 01:16:02 +00:00
|
|
|
shape->SetFilled( true );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( klayer );
|
|
|
|
shape->SetWidth( 0 );
|
2020-04-05 22:26:29 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetPolyPoints( { p11, p12, p22, p21 } );
|
2020-04-05 22:26:29 +00:00
|
|
|
|
|
|
|
if( elem.rotation != 0. )
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->Rotate( center, elem.rotation * 10 );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
{
|
2020-04-05 09:22:40 +00:00
|
|
|
THROW_IO_ERROR( "Fills6 stream is not fully parsed" );
|
2020-04-03 23:22:24 +00:00
|
|
|
}
|
|
|
|
}
|