2020-07-12 16:58:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-01-31 20:47:36 +00:00
|
|
|
* Copyright (C) 2020-2021 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
|
2023-03-04 23:15:43 +00:00
|
|
|
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-07-12 16:58:35 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-08-29 18:09:48 +00:00
|
|
|
* @file cadstar_pcb_archive_loader.cpp
|
|
|
|
* @brief Loads a cpa file into a KiCad BOARD object
|
2020-07-12 16:58:35 +00:00
|
|
|
*/
|
|
|
|
|
2020-08-29 18:09:48 +00:00
|
|
|
#include <cadstar_pcb_archive_loader.h>
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_stackup_manager/board_stackup.h>
|
2020-08-23 10:34:27 +00:00
|
|
|
#include <board_stackup_manager/stackup_predefined_prms.h> // KEY_COPPER, KEY_CORE, KEY_PREPREG
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-06-11 16:59:28 +00:00
|
|
|
#include <pcb_dimension.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
|
|
|
#include <fp_shape.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2021-06-03 17:03:25 +00:00
|
|
|
#include <pcb_group.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2020-12-13 15:40:03 +00:00
|
|
|
#include <project.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2021-09-09 21:15:38 +00:00
|
|
|
#include <progress_reporter.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2020-08-28 20:32:53 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2020-08-31 22:09:29 +00:00
|
|
|
#include <trigo.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2022-08-14 01:51:14 +00:00
|
|
|
#include <wx/debug.h>
|
2021-06-06 13:28:02 +00:00
|
|
|
#include <wx/log.h>
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
#include <limits> // std::numeric_limits
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::Load( BOARD* aBoard, PROJECT* aProject )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board = aBoard;
|
|
|
|
m_project = aProject;
|
2020-12-13 17:28:47 +00:00
|
|
|
|
2021-09-09 21:15:38 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->SetNumPhases( 3 ); // (0) Read file, (1) Parse file, (2) Load file
|
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
Parse();
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
LONGPOINT designLimit = Assignments.Technology.DesignLimit;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
//Note: can't use getKiCadPoint() due wxPoint being int - need long long to make the check
|
2020-09-10 20:58:20 +00:00
|
|
|
long long designSizeXkicad = (long long) designLimit.x * KiCadUnitMultiplier;
|
|
|
|
long long designSizeYkicad = (long long) designLimit.y * KiCadUnitMultiplier;
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2020-09-14 17:13:09 +00:00
|
|
|
// Max size limited by the positive dimension of wxPoint (which is an int)
|
|
|
|
long long maxDesignSizekicad = std::numeric_limits<int>::max();
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
if( designSizeXkicad > maxDesignSizekicad || designSizeYkicad > maxDesignSizekicad )
|
2020-09-27 13:10:59 +00:00
|
|
|
{
|
2020-08-16 17:12:08 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "The design is too large and cannot be imported into KiCad. \n"
|
|
|
|
"Please reduce the maximum design size in CADSTAR by navigating to: \n"
|
|
|
|
"Design Tab -> Properties -> Design Options -> Maximum Design Size. \n"
|
2020-09-14 08:02:07 +00:00
|
|
|
"Current Design size: %.2f, %.2f millimeters. \n"
|
|
|
|
"Maximum permitted design size: %.2f, %.2f millimeters.\n" ),
|
|
|
|
(double) designSizeXkicad / PCB_IU_PER_MM,
|
|
|
|
(double) designSizeYkicad / PCB_IU_PER_MM,
|
2020-09-14 17:13:09 +00:00
|
|
|
(double) maxDesignSizekicad / PCB_IU_PER_MM,
|
|
|
|
(double) maxDesignSizekicad / PCB_IU_PER_MM ) );
|
2020-09-27 13:10:59 +00:00
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_designCenter =
|
2020-08-16 17:12:08 +00:00
|
|
|
( Assignments.Technology.DesignArea.first + Assignments.Technology.DesignArea.second )
|
|
|
|
/ 2;
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
if( Layout.NetSynch == NETSYNCH::WARNING )
|
2020-09-27 13:10:59 +00:00
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
wxLogWarning(
|
|
|
|
_( "The selected file indicates that nets might be out of synchronisation "
|
|
|
|
"with the schematic. It is recommended that you carry out an 'Align Nets' "
|
|
|
|
"procedure in CADSTAR and re-import, to avoid inconsistencies between the "
|
|
|
|
"PCB and the schematic. " ) );
|
2020-09-27 13:10:59 +00:00
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2021-09-09 21:15:38 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter->BeginPhase( 2 );
|
|
|
|
|
|
|
|
// Significantly most amount of time spent loading coppers compared to all the other steps
|
|
|
|
// (39 seconds vs max of 100ms in other steps). This is due to requirement of boolean
|
|
|
|
// operations to join them together into a single polygon.
|
|
|
|
long numSteps = Layout.Coppers.size();
|
|
|
|
|
2021-10-12 17:39:04 +00:00
|
|
|
// A large amount is also spent calculating zone priorities
|
|
|
|
numSteps += ( Layout.Templates.size() * Layout.Templates.size() ) / 2;
|
|
|
|
|
2021-09-09 21:15:38 +00:00
|
|
|
m_progressReporter->SetMaxProgress( numSteps );
|
|
|
|
}
|
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
loadBoardStackup();
|
2020-10-01 22:47:38 +00:00
|
|
|
remapUnsureLayers();
|
2020-09-02 18:35:12 +00:00
|
|
|
loadDesignRules();
|
2020-08-28 20:32:53 +00:00
|
|
|
loadComponentLibrary();
|
2020-09-06 21:20:32 +00:00
|
|
|
loadGroups();
|
2020-08-16 17:12:08 +00:00
|
|
|
loadBoards();
|
2020-08-23 10:34:27 +00:00
|
|
|
loadFigures();
|
2020-09-02 21:48:18 +00:00
|
|
|
loadTexts();
|
2020-09-06 22:16:02 +00:00
|
|
|
loadDimensions();
|
2020-08-23 10:34:27 +00:00
|
|
|
loadAreas();
|
2020-08-28 20:32:53 +00:00
|
|
|
loadComponents();
|
2020-09-05 15:31:57 +00:00
|
|
|
loadDocumentationSymbols();
|
2020-08-31 22:09:29 +00:00
|
|
|
loadTemplates();
|
2021-09-09 21:15:38 +00:00
|
|
|
loadCoppers(); // Progress reporting is here as significantly most amount of time spent
|
2021-10-12 17:39:04 +00:00
|
|
|
|
|
|
|
for( PCB_LAYER_ID id : LSET::AllCuMask( m_numCopperLayers ).Seq() )
|
|
|
|
{
|
|
|
|
if( !calculateZonePriorities( id ) )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( _( "Unable to determine zone fill priorities for layer "
|
|
|
|
"'%s'. A best attempt has been made but it is "
|
|
|
|
"possible that DRC errors exist and that manual "
|
|
|
|
"editing of the zone priorities is required." ),
|
|
|
|
m_board->GetLayerName( id ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
loadNets();
|
2021-01-31 20:47:36 +00:00
|
|
|
loadTextVariables();
|
2020-11-02 19:23:01 +00:00
|
|
|
|
2020-10-13 21:40:44 +00:00
|
|
|
if( Layout.Trunks.size() > 0 )
|
|
|
|
{
|
|
|
|
wxLogWarning(
|
|
|
|
_( "The CADSTAR design contains Trunk routing elements, which have no KiCad "
|
|
|
|
"equivalent. These elements were not loaded." ) );
|
|
|
|
}
|
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
if( Layout.VariantHierarchy.Variants.size() > 0 )
|
2020-09-27 13:10:59 +00:00
|
|
|
{
|
2020-11-21 12:55:58 +00:00
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The CADSTAR design contains variants which has no KiCad equivalent. Only "
|
2020-12-13 15:40:03 +00:00
|
|
|
"the variant '%s' was loaded." ),
|
|
|
|
Layout.VariantHierarchy.Variants.begin()->second.Name ) );
|
2020-09-27 13:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( Layout.ReuseBlocks.size() > 0 )
|
|
|
|
{
|
|
|
|
wxLogWarning(
|
|
|
|
_( "The CADSTAR design contains re-use blocks which has no KiCad equivalent. The "
|
|
|
|
"re-use block information has been discarded during the import." ) );
|
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2022-08-14 20:13:27 +00:00
|
|
|
wxLogWarning( _( "CADSTAR fonts are different to the ones in KiCad. This will likely result "
|
|
|
|
"in alignment issues that may cause DRC errors. Please review the imported "
|
|
|
|
"text elements carefully and correct manually if required." ) );
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
wxLogMessage(
|
|
|
|
_( "The CADSTAR design has been imported successfully.\n"
|
|
|
|
"Please review the import errors and warnings (if any)." ) );
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
|
|
|
|
2021-01-31 21:55:51 +00:00
|
|
|
std::vector<FOOTPRINT*> CADSTAR_PCB_ARCHIVE_LOADER::GetLoadedLibraryFootpints() const
|
|
|
|
{
|
|
|
|
std::vector<FOOTPRINT*> retval;
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<SYMDEF_ID, FOOTPRINT*> fpPair : m_libraryMap )
|
2021-01-31 21:55:51 +00:00
|
|
|
{
|
|
|
|
retval.push_back( static_cast<FOOTPRINT*>( fpPair.second->Clone() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2020-12-21 20:04:52 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::logBoardStackupWarning(
|
|
|
|
const wxString& aCadstarLayerName,
|
2020-10-01 22:47:38 +00:00
|
|
|
const PCB_LAYER_ID& aKiCadLayer )
|
2020-08-30 12:23:25 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_logLayerWarnings )
|
2020-10-01 22:47:38 +00:00
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The CADSTAR layer '%s' has no KiCad equivalent. All elements on this "
|
|
|
|
"layer have been mapped to KiCad layer '%s' instead." ),
|
|
|
|
aCadstarLayerName, LSET::Name( aKiCadLayer ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::logBoardStackupMessage( const wxString& aCadstarLayerName,
|
|
|
|
const PCB_LAYER_ID& aKiCadLayer )
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_logLayerWarnings )
|
2020-10-01 22:47:38 +00:00
|
|
|
{
|
|
|
|
wxLogMessage( wxString::Format(
|
|
|
|
_( "The CADSTAR layer '%s' has been assumed to be a technical layer. All "
|
|
|
|
"elements on this layer have been mapped to KiCad layer '%s'." ),
|
|
|
|
aCadstarLayerName, LSET::Name( aKiCadLayer ) ) );
|
|
|
|
}
|
2020-08-30 12:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-28 02:21:37 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::initStackupItem( const LAYER& aCadstarLayer,
|
2021-02-13 20:00:17 +00:00
|
|
|
BOARD_STACKUP_ITEM* aKiCadItem,
|
2020-12-28 02:21:37 +00:00
|
|
|
int aDielectricSublayer )
|
|
|
|
{
|
|
|
|
if( !aCadstarLayer.MaterialId.IsEmpty() )
|
|
|
|
{
|
|
|
|
MATERIAL material = Assignments.Layerdefs.Materials.at( aCadstarLayer.MaterialId );
|
|
|
|
|
|
|
|
aKiCadItem->SetMaterial( material.Name, aDielectricSublayer );
|
|
|
|
aKiCadItem->SetEpsilonR( material.Permittivity.GetDouble(), aDielectricSublayer );
|
|
|
|
aKiCadItem->SetLossTangent( material.LossTangent.GetDouble(), aDielectricSublayer );
|
|
|
|
//TODO add Resistivity when KiCad supports it
|
|
|
|
}
|
|
|
|
|
2021-10-09 20:11:16 +00:00
|
|
|
if( !aCadstarLayer.Name.IsEmpty() )
|
|
|
|
aKiCadItem->SetLayerName( aCadstarLayer.Name );
|
|
|
|
|
|
|
|
if( aCadstarLayer.Thickness != 0 )
|
|
|
|
aKiCadItem->SetThickness( getKiCadLength( aCadstarLayer.Thickness ), aDielectricSublayer );
|
2020-12-28 02:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadBoardStackup()
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-12-28 02:21:37 +00:00
|
|
|
// Structure describing an electrical layer with optional dielectric layers below it
|
|
|
|
// (construction layers in CADSTAR)
|
|
|
|
struct LAYER_BLOCK
|
|
|
|
{
|
|
|
|
LAYER_ID ElecLayerID = wxEmptyString; // Normally not empty, but could be empty if the
|
|
|
|
// first layer in the stackup is a construction
|
|
|
|
// layer
|
|
|
|
std::vector<LAYER_ID> ConstructionLayers; // Normally empty for the last electrical layer
|
|
|
|
// but it is possible to build a board in CADSTAR
|
|
|
|
// with no construction layers or with the bottom
|
|
|
|
// layer being a construction layer
|
|
|
|
|
|
|
|
bool IsInitialised() { return !ElecLayerID.IsEmpty() || ConstructionLayers.size() > 0; };
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<LAYER_BLOCK> cadstarBoardStackup;
|
|
|
|
LAYER_BLOCK currentBlock;
|
|
|
|
|
|
|
|
// Find the electrical and construction (dielectric) layers in the stackup
|
|
|
|
for( LAYER_ID cadstarLayerID : Assignments.Layerdefs.LayerStack )
|
|
|
|
{
|
|
|
|
LAYER cadstarLayer = Assignments.Layerdefs.Layers.at( cadstarLayerID );
|
|
|
|
|
2021-01-31 20:47:36 +00:00
|
|
|
if( cadstarLayer.Type == LAYER_TYPE::JUMPERLAYER ||
|
2020-12-28 02:21:37 +00:00
|
|
|
cadstarLayer.Type == LAYER_TYPE::POWER ||
|
|
|
|
cadstarLayer.Type == LAYER_TYPE::ELEC )
|
|
|
|
{
|
|
|
|
if( currentBlock.IsInitialised() )
|
|
|
|
{
|
|
|
|
cadstarBoardStackup.push_back( currentBlock );
|
|
|
|
currentBlock = LAYER_BLOCK(); // reset the block
|
|
|
|
}
|
|
|
|
|
|
|
|
currentBlock.ElecLayerID = cadstarLayerID;
|
|
|
|
}
|
|
|
|
else if( cadstarLayer.Type == LAYER_TYPE::CONSTRUCTION )
|
|
|
|
{
|
|
|
|
currentBlock.ConstructionLayers.push_back( cadstarLayerID );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( currentBlock.IsInitialised() )
|
|
|
|
cadstarBoardStackup.push_back( currentBlock );
|
|
|
|
|
2021-10-09 19:06:56 +00:00
|
|
|
m_numCopperLayers = cadstarBoardStackup.size();
|
2020-12-28 02:21:37 +00:00
|
|
|
|
|
|
|
// Special case: last layer in the stackup is a construction layer, we need to use B.Cu as a
|
|
|
|
// dummy layer
|
|
|
|
if( cadstarBoardStackup.back().ConstructionLayers.size() > 0 )
|
|
|
|
{
|
|
|
|
cadstarBoardStackup.push_back( LAYER_BLOCK() ); //Add dummy layer at the end
|
2021-10-09 19:06:56 +00:00
|
|
|
++m_numCopperLayers;
|
2020-12-28 02:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure it is an even number of layers (KiCad doesn't yet support unbalanced stack-ups)
|
2021-10-09 19:06:56 +00:00
|
|
|
if( ( m_numCopperLayers % 2 ) != 0 )
|
2020-12-28 02:21:37 +00:00
|
|
|
{
|
|
|
|
LAYER_BLOCK bottomLayer = cadstarBoardStackup.back();
|
|
|
|
cadstarBoardStackup.pop_back();
|
|
|
|
|
|
|
|
LAYER_BLOCK secondToLastLayer = cadstarBoardStackup.back();
|
|
|
|
cadstarBoardStackup.pop_back();
|
|
|
|
|
|
|
|
LAYER_BLOCK dummyLayer;
|
2021-11-10 21:41:48 +00:00
|
|
|
LAYER_ID lastConstruction = secondToLastLayer.ConstructionLayers.back();
|
2020-12-28 02:21:37 +00:00
|
|
|
|
|
|
|
if( secondToLastLayer.ConstructionLayers.size() > 1 )
|
|
|
|
{
|
|
|
|
// At least two construction layers, lets remove it here and use it in the dummy layer
|
|
|
|
secondToLastLayer.ConstructionLayers.pop_back();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// There is only one construction layer, lets halve its thickness so it is split evenly
|
|
|
|
// between this layer and the dummy layer
|
|
|
|
Assignments.Layerdefs.Layers.at( lastConstruction ).Thickness /= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
dummyLayer.ConstructionLayers.push_back( lastConstruction );
|
|
|
|
cadstarBoardStackup.push_back( secondToLastLayer );
|
|
|
|
cadstarBoardStackup.push_back( dummyLayer );
|
|
|
|
cadstarBoardStackup.push_back( bottomLayer );
|
2021-10-09 19:06:56 +00:00
|
|
|
++m_numCopperLayers;
|
2020-12-28 02:21:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-09 19:06:56 +00:00
|
|
|
wxASSERT( m_numCopperLayers == cadstarBoardStackup.size() );
|
2020-12-28 02:21:37 +00:00
|
|
|
wxASSERT( cadstarBoardStackup.back().ConstructionLayers.size() == 0 );
|
|
|
|
|
|
|
|
// Create a new stackup from default stackup list
|
2021-10-09 19:33:14 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& boardDesignSettings = m_board->GetDesignSettings();
|
|
|
|
BOARD_STACKUP& stackup = boardDesignSettings.GetStackupDescriptor();
|
2020-07-12 16:58:35 +00:00
|
|
|
stackup.RemoveAll();
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->SetEnabledLayers( LSET::AllLayersMask() );
|
|
|
|
m_board->SetVisibleLayers( LSET::AllLayersMask() );
|
2021-10-09 19:06:56 +00:00
|
|
|
m_board->SetCopperLayerCount( m_numCopperLayers );
|
|
|
|
stackup.BuildDefaultStackupList( &m_board->GetDesignSettings(), m_numCopperLayers );
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2020-12-28 02:21:37 +00:00
|
|
|
size_t stackIndex = 0;
|
2021-01-31 20:47:36 +00:00
|
|
|
|
2020-12-28 02:21:37 +00:00
|
|
|
for( BOARD_STACKUP_ITEM* item : stackup.GetList() )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-12-28 02:21:37 +00:00
|
|
|
if( item->GetType() == BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_COPPER )
|
|
|
|
{
|
|
|
|
LAYER_ID layerID = cadstarBoardStackup.at( stackIndex ).ElecLayerID;
|
|
|
|
|
|
|
|
if( layerID.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Loading a dummy layer. Make zero thickness so it doesn't affect overall stackup
|
|
|
|
item->SetThickness( 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LAYER copperLayer = Assignments.Layerdefs.Layers.at( layerID );
|
|
|
|
initStackupItem( copperLayer, item, 0 );
|
|
|
|
LAYER_T copperType = LAYER_T::LT_SIGNAL;
|
|
|
|
|
|
|
|
switch( copperLayer.Type )
|
|
|
|
{
|
|
|
|
case LAYER_TYPE::JUMPERLAYER:
|
|
|
|
copperType = LAYER_T::LT_JUMPER;
|
|
|
|
break;
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2020-12-28 02:21:37 +00:00
|
|
|
case LAYER_TYPE::ELEC:
|
|
|
|
copperType = LAYER_T::LT_SIGNAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_TYPE::POWER:
|
|
|
|
copperType = LAYER_T::LT_POWER;
|
2021-02-13 20:00:17 +00:00
|
|
|
m_powerPlaneLayers.push_back( copperLayer.ID ); //need to add a Copper zone
|
2020-12-28 02:21:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unexpected Layer type. Was expecting an electrical type" ) );
|
2020-12-28 02:21:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->SetLayerType( item->GetBrdLayerId(), copperType );
|
|
|
|
m_board->SetLayerName( item->GetBrdLayerId(), item->GetLayerName() );
|
|
|
|
m_layermap.insert( { copperLayer.ID, item->GetBrdLayerId() } );
|
2020-12-28 02:21:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( item->GetType() == BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_DIELECTRIC )
|
2020-10-19 17:11:52 +00:00
|
|
|
{
|
2020-12-28 02:21:37 +00:00
|
|
|
LAYER_BLOCK layerBlock = cadstarBoardStackup.at( stackIndex );
|
|
|
|
LAYER_BLOCK layerBlockBelow = cadstarBoardStackup.at( stackIndex + 1 );
|
|
|
|
|
2021-10-09 20:11:16 +00:00
|
|
|
if( layerBlock.ConstructionLayers.size() == 0 )
|
|
|
|
{
|
|
|
|
++stackIndex;
|
|
|
|
continue; // Older cadstar designs have no construction layers - use KiCad defaults
|
|
|
|
}
|
2020-12-28 02:21:37 +00:00
|
|
|
|
|
|
|
int dielectricId = stackIndex + 1;
|
|
|
|
item->SetDielectricLayerId( dielectricId );
|
|
|
|
|
|
|
|
//Prepreg or core?
|
|
|
|
//Look at CADSTAR layer embedding (see LAYER->Embedding) to check whether the electrical
|
|
|
|
//layer embeds above and below to decide if current layer is prepreg or core
|
|
|
|
if( layerBlock.ElecLayerID.IsEmpty() )
|
|
|
|
{
|
|
|
|
//Dummy electrical layer, assume prepreg
|
|
|
|
item->SetTypeName( KEY_PREPREG );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LAYER copperLayer = Assignments.Layerdefs.Layers.at( layerBlock.ElecLayerID );
|
|
|
|
|
|
|
|
if( layerBlockBelow.ElecLayerID.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Dummy layer below, just use current layer to decide
|
|
|
|
|
|
|
|
if( copperLayer.Embedding == EMBEDDING::ABOVE )
|
|
|
|
item->SetTypeName( KEY_CORE );
|
2021-01-31 20:47:36 +00:00
|
|
|
else
|
2020-12-28 02:21:37 +00:00
|
|
|
item->SetTypeName( KEY_PREPREG );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LAYER copperLayerBelow =
|
|
|
|
Assignments.Layerdefs.Layers.at( layerBlockBelow.ElecLayerID );
|
|
|
|
|
|
|
|
if( copperLayer.Embedding == EMBEDDING::ABOVE )
|
|
|
|
{
|
|
|
|
// Need to check layer below is embedding downwards
|
|
|
|
if( copperLayerBelow.Embedding == EMBEDDING::BELOW )
|
|
|
|
item->SetTypeName( KEY_CORE );
|
|
|
|
else
|
|
|
|
item->SetTypeName( KEY_PREPREG );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->SetTypeName( KEY_PREPREG );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int dielectricSublayer = 0;
|
|
|
|
|
|
|
|
for( LAYER_ID constructionLaID : layerBlock.ConstructionLayers )
|
|
|
|
{
|
|
|
|
LAYER dielectricLayer = Assignments.Layerdefs.Layers.at( constructionLaID );
|
2021-01-31 20:47:36 +00:00
|
|
|
|
2020-12-28 02:21:37 +00:00
|
|
|
if( dielectricSublayer )
|
|
|
|
item->AddDielectricPrms( dielectricSublayer );
|
2021-01-31 20:47:36 +00:00
|
|
|
|
2020-12-28 02:21:37 +00:00
|
|
|
initStackupItem( dielectricLayer, item, dielectricSublayer );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->SetLayerName( item->GetBrdLayerId(), item->GetLayerName() );
|
|
|
|
m_layermap.insert( { dielectricLayer.ID, item->GetBrdLayerId() } );
|
2020-12-28 02:21:37 +00:00
|
|
|
++dielectricSublayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
++stackIndex;
|
2020-10-19 17:11:52 +00:00
|
|
|
}
|
2021-11-05 16:31:54 +00:00
|
|
|
else if( item->GetType() == BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_SILKSCREEN )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
item->SetColor( wxT( "White" ) );
|
2021-11-05 16:31:54 +00:00
|
|
|
}
|
|
|
|
else if( item->GetType() == BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_SOLDERMASK )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
item->SetColor( wxT( "Green" ) );
|
2021-11-05 16:31:54 +00:00
|
|
|
}
|
2020-12-28 02:21:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-09 19:33:14 +00:00
|
|
|
int thickness = stackup.BuildBoardThicknessFromStackup();
|
|
|
|
boardDesignSettings.SetBoardThickness( thickness );
|
|
|
|
boardDesignSettings.m_HasStackup = true;
|
|
|
|
|
2022-09-03 21:57:33 +00:00
|
|
|
int numElecLayersProcessed = 0;
|
2020-11-02 19:23:01 +00:00
|
|
|
|
2021-11-10 21:41:48 +00:00
|
|
|
// Map CADSTAR documentation layers to KiCad "User layers"
|
|
|
|
int currentDocLayer = 0;
|
|
|
|
std::vector<PCB_LAYER_ID> docLayers = { Dwgs_User, Cmts_User, User_1, User_2, User_3, User_4,
|
|
|
|
User_5, User_6, User_7, User_8, User_9 };
|
|
|
|
|
2020-12-28 02:21:37 +00:00
|
|
|
for( LAYER_ID cadstarLayerID : Assignments.Layerdefs.LayerStack )
|
|
|
|
{
|
|
|
|
LAYER curLayer = Assignments.Layerdefs.Layers.at( cadstarLayerID );
|
|
|
|
PCB_LAYER_ID kicadLayerID = PCB_LAYER_ID::UNDEFINED_LAYER;
|
|
|
|
wxString layerName = curLayer.Name.Lower();
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2020-12-21 20:04:52 +00:00
|
|
|
enum class LOG_LEVEL
|
|
|
|
{
|
|
|
|
NONE,
|
|
|
|
MSG,
|
|
|
|
WARN
|
|
|
|
};
|
|
|
|
|
2021-01-31 20:47:36 +00:00
|
|
|
auto selectLayerID =
|
|
|
|
[&]( PCB_LAYER_ID aFront, PCB_LAYER_ID aBack, LOG_LEVEL aLogType )
|
2020-12-21 20:04:52 +00:00
|
|
|
{
|
2022-09-03 21:57:33 +00:00
|
|
|
if( numElecLayersProcessed >= m_numCopperLayers )
|
2020-12-21 20:04:52 +00:00
|
|
|
kicadLayerID = aBack;
|
|
|
|
else
|
|
|
|
kicadLayerID = aFront;
|
|
|
|
|
|
|
|
switch( aLogType )
|
|
|
|
{
|
|
|
|
case LOG_LEVEL::NONE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOG_LEVEL::MSG:
|
|
|
|
logBoardStackupMessage( curLayer.Name, kicadLayerID );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOG_LEVEL::WARN:
|
2021-11-10 21:41:48 +00:00
|
|
|
logBoardStackupWarning( curLayer.Name, kicadLayerID );
|
2020-12-21 20:04:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
switch( curLayer.Type )
|
|
|
|
{
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_TYPE::ALLDOC:
|
|
|
|
case LAYER_TYPE::ALLELEC:
|
|
|
|
case LAYER_TYPE::ALLLAYER:
|
|
|
|
case LAYER_TYPE::ASSCOMPCOPP:
|
|
|
|
case LAYER_TYPE::NOLAYER:
|
2020-07-12 16:58:35 +00:00
|
|
|
//Shouldn't be here if CPA file is correctly parsed and not corrupt
|
2021-06-27 23:26:54 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unexpected layer '%s' in layer stack." ),
|
|
|
|
curLayer.Name ) );
|
2020-07-12 16:58:35 +00:00
|
|
|
break;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-12-28 02:21:37 +00:00
|
|
|
case LAYER_TYPE::JUMPERLAYER:
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_TYPE::ELEC:
|
2021-01-31 20:47:36 +00:00
|
|
|
case LAYER_TYPE::POWER:
|
2022-09-03 21:57:33 +00:00
|
|
|
++numElecLayersProcessed;
|
2020-12-28 02:21:37 +00:00
|
|
|
KI_FALLTHROUGH;
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_TYPE::CONSTRUCTION:
|
2020-12-28 02:21:37 +00:00
|
|
|
//Already dealt with these when loading board stackup
|
2020-07-12 16:58:35 +00:00
|
|
|
break;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_TYPE::DOC:
|
2021-11-10 21:41:48 +00:00
|
|
|
|
|
|
|
if( currentDocLayer >= docLayers.size() )
|
|
|
|
currentDocLayer = 0;
|
|
|
|
|
|
|
|
kicadLayerID = docLayers.at( currentDocLayer++ );
|
|
|
|
logBoardStackupMessage( curLayer.Name, kicadLayerID );
|
2020-08-23 10:34:27 +00:00
|
|
|
break;
|
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_TYPE::NONELEC:
|
2020-07-12 16:58:35 +00:00
|
|
|
switch( curLayer.SubType )
|
|
|
|
{
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_ASSEMBLY:
|
2020-12-21 20:04:52 +00:00
|
|
|
selectLayerID( PCB_LAYER_ID::F_Fab, PCB_LAYER_ID::B_Fab, LOG_LEVEL::NONE );
|
2020-08-23 10:34:27 +00:00
|
|
|
break;
|
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_PLACEMENT:
|
2020-12-21 20:04:52 +00:00
|
|
|
selectLayerID( PCB_LAYER_ID::F_CrtYd, PCB_LAYER_ID::B_CrtYd, LOG_LEVEL::NONE );
|
2020-08-23 10:34:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_NONE:
|
2020-12-21 20:04:52 +00:00
|
|
|
// Generic Non-electrical layer (older CADSTAR versions).
|
2021-01-31 20:47:36 +00:00
|
|
|
// Attempt to detect technical layers by string matching.
|
2022-02-05 02:06:25 +00:00
|
|
|
if( layerName.Contains( wxT( "glue" ) ) || layerName.Contains( wxT( "adhesive" ) ) )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-12-28 02:21:37 +00:00
|
|
|
selectLayerID( PCB_LAYER_ID::F_Adhes, PCB_LAYER_ID::B_Adhes, LOG_LEVEL::MSG );
|
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( layerName.Contains( wxT( "silk" ) ) || layerName.Contains( wxT( "legend" ) ) )
|
2020-12-28 02:21:37 +00:00
|
|
|
{
|
|
|
|
selectLayerID( PCB_LAYER_ID::F_SilkS, PCB_LAYER_ID::B_SilkS, LOG_LEVEL::MSG );
|
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( layerName.Contains( wxT( "assembly" ) ) || layerName.Contains( wxT( "fabrication" ) ) )
|
2020-12-28 02:21:37 +00:00
|
|
|
{
|
|
|
|
selectLayerID( PCB_LAYER_ID::F_Fab, PCB_LAYER_ID::B_Fab, LOG_LEVEL::MSG );
|
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( layerName.Contains( wxT( "resist" ) ) || layerName.Contains( wxT( "mask" ) ) )
|
2020-12-28 02:21:37 +00:00
|
|
|
{
|
|
|
|
selectLayerID( PCB_LAYER_ID::F_Mask, PCB_LAYER_ID::B_Mask, LOG_LEVEL::MSG );
|
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( layerName.Contains( wxT( "paste" ) ) )
|
2020-12-28 02:21:37 +00:00
|
|
|
{
|
|
|
|
selectLayerID( PCB_LAYER_ID::F_Paste, PCB_LAYER_ID::B_Paste, LOG_LEVEL::MSG );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Does not appear to be a technical layer - Map to Eco layers for now.
|
|
|
|
selectLayerID( PCB_LAYER_ID::Eco1_User, PCB_LAYER_ID::Eco2_User,
|
|
|
|
LOG_LEVEL::WARN );
|
2020-10-01 22:47:38 +00:00
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_PASTE:
|
2020-12-21 20:04:52 +00:00
|
|
|
selectLayerID( PCB_LAYER_ID::F_Paste, PCB_LAYER_ID::B_Paste, LOG_LEVEL::MSG );
|
2020-07-12 16:58:35 +00:00
|
|
|
break;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_SILKSCREEN:
|
2020-12-21 20:04:52 +00:00
|
|
|
selectLayerID( PCB_LAYER_ID::F_SilkS, PCB_LAYER_ID::B_SilkS, LOG_LEVEL::MSG );
|
2020-07-12 16:58:35 +00:00
|
|
|
break;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_SOLDERRESIST:
|
2020-12-21 20:04:52 +00:00
|
|
|
selectLayerID( PCB_LAYER_ID::F_Mask, PCB_LAYER_ID::B_Mask, LOG_LEVEL::MSG );
|
2020-07-12 16:58:35 +00:00
|
|
|
break;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-10-26 21:15:24 +00:00
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_ROUT:
|
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_CLEARANCE:
|
2020-12-21 20:04:52 +00:00
|
|
|
//Unsure what these layer types are used for. Map to Eco layers for now.
|
|
|
|
selectLayerID( PCB_LAYER_ID::Eco1_User, PCB_LAYER_ID::Eco2_User, LOG_LEVEL::WARN );
|
2020-10-26 21:15:24 +00:00
|
|
|
break;
|
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unknown CADSTAR Layer Sub-type" ) );
|
2020-07-12 16:58:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unknown CADSTAR Layer Type" ) );
|
2020-07-12 16:58:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_layermap.insert( { curLayer.ID, kicadLayerID } );
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-01 22:47:38 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::remapUnsureLayers()
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
LSET enabledLayers = m_board->GetEnabledLayers();
|
2020-10-01 22:47:38 +00:00
|
|
|
LSET validRemappingLayers = enabledLayers | LSET::AllBoardTechMask() |
|
|
|
|
LSET::UserMask() | LSET::UserDefinedLayers();
|
|
|
|
|
|
|
|
std::vector<INPUT_LAYER_DESC> inputLayers;
|
|
|
|
std::map<wxString, LAYER_ID> cadstarLayerNameMap;
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<LAYER_ID, PCB_LAYER_ID> layerPair : m_layermap )
|
2020-10-01 22:47:38 +00:00
|
|
|
{
|
|
|
|
LAYER* curLayer = &Assignments.Layerdefs.Layers.at( layerPair.first );
|
|
|
|
|
2022-08-14 21:23:59 +00:00
|
|
|
//Only remap documentation and non-electrical layers
|
|
|
|
if( curLayer->Type == LAYER_TYPE::NONELEC || curLayer->Type == LAYER_TYPE::DOC )
|
2020-10-01 22:47:38 +00:00
|
|
|
{
|
|
|
|
INPUT_LAYER_DESC iLdesc;
|
|
|
|
iLdesc.Name = curLayer->Name;
|
|
|
|
iLdesc.PermittedLayers = validRemappingLayers;
|
|
|
|
iLdesc.AutoMapLayer = layerPair.second;
|
|
|
|
|
|
|
|
inputLayers.push_back( iLdesc );
|
|
|
|
cadstarLayerNameMap.insert( { curLayer->Name, curLayer->ID } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( inputLayers.size() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Callback:
|
2021-02-13 20:00:17 +00:00
|
|
|
std::map<wxString, PCB_LAYER_ID> reMappedLayers = m_layerMappingHandler( inputLayers );
|
2020-10-01 22:47:38 +00:00
|
|
|
|
|
|
|
for( std::pair<wxString, PCB_LAYER_ID> layerPair : reMappedLayers )
|
|
|
|
{
|
|
|
|
if( layerPair.second == PCB_LAYER_ID::UNDEFINED_LAYER )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unexpected Layer ID" ) );
|
2020-10-01 22:47:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
LAYER_ID cadstarLayerID = cadstarLayerNameMap.at( layerPair.first );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_layermap.at( cadstarLayerID ) = layerPair.second;
|
2020-10-01 22:47:38 +00:00
|
|
|
enabledLayers |= LSET( layerPair.second );
|
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->SetEnabledLayers( enabledLayers );
|
|
|
|
m_board->SetVisibleLayers( enabledLayers );
|
2020-10-01 22:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-02 18:35:12 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadDesignRules()
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
2020-09-10 20:58:20 +00:00
|
|
|
std::map<SPACINGCODE_ID, SPACINGCODE>& spacingCodes = Assignments.Codedefs.SpacingCodes;
|
2020-09-02 18:35:12 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
auto applyRule =
|
|
|
|
[&]( wxString aID, int* aVal )
|
|
|
|
{
|
|
|
|
if( spacingCodes.find( aID ) == spacingCodes.end() )
|
|
|
|
wxLogWarning( _( "Design rule %s was not found. This was ignored." ) );
|
|
|
|
else
|
|
|
|
*aVal = getKiCadLength( spacingCodes.at( aID ).Spacing );
|
|
|
|
};
|
2020-09-02 18:35:12 +00:00
|
|
|
|
|
|
|
//Note: for details on the different spacing codes see SPACINGCODE::ID
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
applyRule( "T_T", &bds.m_MinClearance );
|
|
|
|
applyRule( "C_B", &bds.m_CopperEdgeClearance );
|
|
|
|
applyRule( "H_H", &bds.m_HoleToHoleMin );
|
2020-09-02 18:35:12 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
bds.m_TrackMinWidth = getKiCadLength( Assignments.Technology.MinRouteWidth );
|
|
|
|
bds.m_ViasMinSize = bds.m_TrackMinWidth; // Not specified, assumed same as track width
|
|
|
|
bds.m_ViasMinAnnularWidth = bds.m_TrackMinWidth / 2; // Not specified, assumed half track width
|
|
|
|
bds.m_MinThroughDrill = PCB_IU_PER_MM * 0.0508; // CADSTAR does not specify a minimum hole size
|
2021-04-10 21:15:13 +00:00
|
|
|
// so set to minimum permitted in KiCad (2 mils)
|
2022-08-14 11:03:18 +00:00
|
|
|
bds.m_HoleClearance = 0; // Testing suggests cadstar might not have a copper-to-hole clearance
|
2020-09-02 18:35:12 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
auto applyNetClassRule =
|
|
|
|
[&]( wxString aID, std::shared_ptr<NETCLASS>& aNetClassPtr )
|
|
|
|
{
|
|
|
|
int value = -1;
|
|
|
|
applyRule( aID, &value );
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( value != -1 )
|
|
|
|
aNetClassPtr->SetClearance( value );
|
|
|
|
};
|
2020-09-02 18:35:12 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
applyNetClassRule( "T_T", bds.m_NetSettings->m_DefaultNetClass );
|
2020-09-02 18:35:12 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
wxLogWarning( _( "KiCad design rules are different from CADSTAR ones. Only the compatible "
|
|
|
|
"design rules were imported. It is recommended that you review the design "
|
|
|
|
"rules that have been applied." ) );
|
2020-09-02 18:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadComponentLibrary()
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
for( std::pair<SYMDEF_ID, SYMDEF_PCB> symPair : Library.ComponentDefinitions )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
SYMDEF_ID key = symPair.first;
|
|
|
|
SYMDEF_PCB component = symPair.second;
|
|
|
|
wxString fpName = component.ReferenceName + ( ( component.Alternate.size() > 0 ) ?
|
2020-08-28 20:32:53 +00:00
|
|
|
( wxT( " (" ) + component.Alternate + wxT( ")" ) ) :
|
|
|
|
wxT( "" ) );
|
2021-10-09 19:06:56 +00:00
|
|
|
|
|
|
|
// Check that we are not loading a documentation symbol.
|
|
|
|
// Documentation symbols in CADSTAR are graphical "footprints" that can be assigned
|
|
|
|
// to any layer. The definition in the library assigns all elements to an undefined layer.
|
|
|
|
LAYER_ID componentLayer;
|
|
|
|
|
|
|
|
if( component.Figures.size() > 0 )
|
|
|
|
{
|
|
|
|
FIGURE firstFigure = component.Figures.begin()->second;
|
|
|
|
componentLayer = firstFigure.LayerID;
|
|
|
|
}
|
|
|
|
else if( component.Texts.size() > 0 )
|
|
|
|
{
|
|
|
|
TEXT firstText = component.Texts.begin()->second;
|
|
|
|
componentLayer = firstText.LayerID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !componentLayer.IsEmpty() && getLayerType( componentLayer ) == LAYER_TYPE::NOLAYER )
|
|
|
|
continue; // don't process documentation symbols
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
FOOTPRINT* footprint = new FOOTPRINT( m_board );
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetPosition( getKiCadPoint( component.Origin ) );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
LIB_ID libID;
|
2020-12-17 23:32:23 +00:00
|
|
|
libID.Parse( fpName, true );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetFPID( libID );
|
|
|
|
loadLibraryFigures( component, footprint );
|
|
|
|
loadLibraryAreas( component, footprint );
|
|
|
|
loadLibraryPads( component, footprint );
|
2021-04-10 18:14:43 +00:00
|
|
|
loadLibraryCoppers( component, footprint ); // Load coppers after pads to ensure correct
|
|
|
|
// ordering of pads in footprint->Pads()
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_libraryMap.insert( std::make_pair( key, footprint ) );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadLibraryFigures( const SYMDEF_PCB& aComponent,
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* aFootprint )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
for( std::pair<FIGURE_ID, FIGURE> figPair : aComponent.Figures )
|
|
|
|
{
|
|
|
|
FIGURE& fig = figPair.second;
|
2020-11-13 01:12:36 +00:00
|
|
|
|
2020-09-08 17:35:06 +00:00
|
|
|
drawCadstarShape( fig.Shape, getKiCadLayer( fig.LayerID ),
|
2020-11-13 01:12:36 +00:00
|
|
|
getLineThickness( fig.LineCodeID ),
|
2022-02-05 02:06:25 +00:00
|
|
|
wxString::Format( wxT( "Component %s:%s -> Figure %s" ),
|
2020-11-13 01:12:36 +00:00
|
|
|
aComponent.ReferenceName,
|
|
|
|
aComponent.Alternate,
|
|
|
|
fig.ID ),
|
|
|
|
aFootprint );
|
2020-09-08 17:35:06 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-09-08 17:35:06 +00:00
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadLibraryCoppers( const SYMDEF_PCB& aComponent,
|
|
|
|
FOOTPRINT* aFootprint )
|
2020-09-08 17:35:06 +00:00
|
|
|
{
|
2021-04-10 18:14:43 +00:00
|
|
|
int totalCopperPads = 0;
|
|
|
|
|
2020-09-08 17:35:06 +00:00
|
|
|
for( COMPONENT_COPPER compCopper : aComponent.ComponentCoppers )
|
|
|
|
{
|
|
|
|
int lineThickness = getKiCadLength( getCopperCode( compCopper.CopperCodeID ).CopperWidth );
|
2021-04-10 18:14:43 +00:00
|
|
|
PCB_LAYER_ID copperLayer = getKiCadLayer( compCopper.LayerID );
|
2020-09-08 17:35:06 +00:00
|
|
|
|
2021-04-10 18:14:43 +00:00
|
|
|
if( compCopper.AssociatedPadIDs.size() > 0 && LSET::AllCuMask().Contains( copperLayer )
|
|
|
|
&& compCopper.Shape.Type == SHAPE_TYPE::SOLID )
|
|
|
|
{
|
|
|
|
// The copper is associated with pads and in an electrical layer which means it can
|
|
|
|
// have a net associated with it. Load as a pad instead.
|
|
|
|
// Note: we can only handle SOLID copper shapes. If the copper shape is an outline or
|
|
|
|
// hatched or outline, then we give up and load as a graphical shape instead.
|
|
|
|
|
|
|
|
// Find the first non-PCB-only pad. If there are none, use the first one
|
|
|
|
COMPONENT_PAD anchorPad;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for( PAD_ID padID : compCopper.AssociatedPadIDs )
|
|
|
|
{
|
|
|
|
anchorPad = aComponent.ComponentPads.at( padID );
|
|
|
|
|
|
|
|
if( !anchorPad.PCBonlyPad )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found )
|
|
|
|
anchorPad = aComponent.ComponentPads.at( compCopper.AssociatedPadIDs.front() );
|
|
|
|
|
2022-08-14 01:51:14 +00:00
|
|
|
std::unique_ptr<PAD> pad = std::make_unique<PAD>( aFootprint );
|
2021-05-01 14:46:50 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB::SMD );
|
2021-04-10 18:14:43 +00:00
|
|
|
pad->SetLayerSet( LSET( 1, copperLayer ) );
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->SetNumber( anchorPad.Identifier.IsEmpty()
|
2021-04-10 18:14:43 +00:00
|
|
|
? wxString::Format( wxT( "%ld" ), anchorPad.ID )
|
|
|
|
: anchorPad.Identifier );
|
|
|
|
|
|
|
|
// Custom pad shape with an anchor at the position of one of the associated
|
|
|
|
// pads and same size as the pad. Shape circle as it fits inside a rectangle
|
|
|
|
// but not the other way round
|
|
|
|
PADCODE anchorpadcode = getPadCode( anchorPad.PadCodeID );
|
|
|
|
int anchorSize = getKiCadLength( anchorpadcode.Shape.Size );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I anchorPos = getKiCadPoint( anchorPad.Position );
|
2021-04-10 18:14:43 +00:00
|
|
|
|
2022-08-14 01:51:14 +00:00
|
|
|
if( anchorSize <= 0 )
|
|
|
|
anchorSize = 1;
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CUSTOM );
|
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE::CIRCLE );
|
2021-04-10 18:14:43 +00:00
|
|
|
pad->SetSize( { anchorSize, anchorSize } );
|
|
|
|
pad->SetPosition( anchorPos );
|
|
|
|
pad->SetLocalCoord();
|
|
|
|
|
|
|
|
SHAPE_POLY_SET shapePolys = getPolySetFromCadstarShape( compCopper.Shape,
|
|
|
|
lineThickness,
|
|
|
|
aFootprint );
|
|
|
|
shapePolys.Move( aFootprint->GetPosition() - anchorPos );
|
|
|
|
pad->AddPrimitivePoly( shapePolys, 0, true );
|
|
|
|
|
2021-10-11 15:41:36 +00:00
|
|
|
// Now renumber all the associated pads
|
2021-04-10 18:14:43 +00:00
|
|
|
COMPONENT_PAD associatedPad;
|
|
|
|
|
|
|
|
for( PAD_ID padID : compCopper.AssociatedPadIDs )
|
|
|
|
{
|
2021-10-11 15:41:36 +00:00
|
|
|
PAD* assocPad = getPadReference( aFootprint, padID );
|
|
|
|
assocPad->SetNumber( pad->GetNumber() );
|
2021-04-10 19:24:40 +00:00
|
|
|
}
|
2022-09-03 22:21:56 +00:00
|
|
|
|
|
|
|
aFootprint->Add( pad.release(), ADD_MODE::APPEND ); // Append so that we get the correct behaviour
|
|
|
|
// when finding pads by PAD_ID. See loadNets()
|
|
|
|
|
|
|
|
m_librarycopperpads[aComponent.ID][anchorPad.ID].push_back( aFootprint->Pads().size() );
|
|
|
|
totalCopperPads++;
|
2021-04-10 18:14:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drawCadstarShape( compCopper.Shape, copperLayer, lineThickness,
|
2022-02-05 02:06:25 +00:00
|
|
|
wxString::Format( wxT( "Component %s:%s -> Copper element" ),
|
2021-04-10 18:14:43 +00:00
|
|
|
aComponent.ReferenceName, aComponent.Alternate ),
|
|
|
|
aFootprint );
|
|
|
|
}
|
2020-09-08 17:35:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadLibraryAreas( const SYMDEF_PCB& aComponent,
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* aFootprint )
|
2020-09-08 17:35:06 +00:00
|
|
|
{
|
|
|
|
for( std::pair<COMP_AREA_ID, COMPONENT_AREA> areaPair : aComponent.ComponentAreas )
|
|
|
|
{
|
|
|
|
COMPONENT_AREA& area = areaPair.second;
|
|
|
|
|
|
|
|
if( area.NoVias || area.NoTracks )
|
|
|
|
{
|
2021-10-08 20:27:32 +00:00
|
|
|
int lineThickness = 0; // CADSTAR areas only use the line width for display purpose
|
|
|
|
ZONE* zone = getZoneFromCadstarShape( area.Shape, lineThickness, aFootprint );
|
2020-09-08 17:35:06 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->Add( zone, ADD_MODE::APPEND );
|
2020-09-08 17:35:06 +00:00
|
|
|
|
|
|
|
if( isLayerSet( area.LayerID ) )
|
|
|
|
zone->SetLayerSet( getKiCadLayerSet( area.LayerID ) );
|
|
|
|
else
|
|
|
|
zone->SetLayer( getKiCadLayer( area.LayerID ) );
|
|
|
|
|
2020-09-27 13:10:59 +00:00
|
|
|
zone->SetIsRuleArea( true ); //import all CADSTAR areas as Keepout zones
|
2020-09-08 17:35:06 +00:00
|
|
|
zone->SetDoNotAllowPads( false ); //no CADSTAR equivalent
|
|
|
|
zone->SetZoneName( area.ID );
|
|
|
|
|
|
|
|
//There is no distinction between tracks and copper pours in CADSTAR Keepout zones
|
|
|
|
zone->SetDoNotAllowTracks( area.NoTracks );
|
|
|
|
zone->SetDoNotAllowCopperPour( area.NoTracks );
|
|
|
|
|
|
|
|
zone->SetDoNotAllowVias( area.NoVias );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString libName = aComponent.ReferenceName;
|
|
|
|
|
|
|
|
if( !aComponent.Alternate.IsEmpty() )
|
|
|
|
libName << wxT( " (" ) << aComponent.Alternate << wxT( ")" );
|
|
|
|
|
|
|
|
wxLogError(
|
|
|
|
wxString::Format( _( "The CADSTAR area '%s' in library component '%s' does not "
|
2021-03-02 08:56:09 +00:00
|
|
|
"have a KiCad equivalent. The area is neither a via nor "
|
2020-11-23 10:42:25 +00:00
|
|
|
"route keepout area. The area was not imported." ),
|
2020-09-08 17:35:06 +00:00
|
|
|
area.ID, libName ) );
|
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadLibraryPads( const SYMDEF_PCB& aComponent,
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* aFootprint )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2020-11-12 21:12:58 +00:00
|
|
|
for( std::pair<PAD_ID, COMPONENT_PAD> padPair : aComponent.ComponentPads )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2022-08-14 01:51:14 +00:00
|
|
|
if( PAD* pad = getKiCadPad( padPair.second, aFootprint ) )
|
|
|
|
aFootprint->Add( pad, ADD_MODE::APPEND ); // Append so that we get correct behaviour
|
|
|
|
// when finding pads by PAD_ID - see loadNets()
|
2020-10-24 17:02:44 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
PAD* CADSTAR_PCB_ARCHIVE_LOADER::getKiCadPad( const COMPONENT_PAD& aCadstarPad, FOOTPRINT* aParent )
|
2020-10-24 17:02:44 +00:00
|
|
|
{
|
|
|
|
PADCODE csPadcode = getPadCode( aCadstarPad.PadCodeID );
|
2021-03-25 17:47:40 +00:00
|
|
|
wxString errorMSG;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2022-08-14 01:51:14 +00:00
|
|
|
std::unique_ptr<PAD> pad = std::make_unique<PAD>( aParent );
|
2021-03-25 17:47:40 +00:00
|
|
|
LSET padLayerSet;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
switch( aCadstarPad.Side )
|
|
|
|
{
|
|
|
|
case PAD_SIDE::MAXIMUM: //Bottom side
|
2021-03-25 17:47:40 +00:00
|
|
|
padLayerSet |= LSET( 3, B_Cu, B_Paste, B_Mask );
|
2020-10-24 17:02:44 +00:00
|
|
|
break;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
case PAD_SIDE::MINIMUM: //TOP side
|
2021-03-25 17:47:40 +00:00
|
|
|
padLayerSet |= LSET( 3, F_Cu, F_Paste, F_Mask );
|
2020-10-24 17:02:44 +00:00
|
|
|
break;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
case PAD_SIDE::THROUGH_HOLE:
|
2021-03-25 17:47:40 +00:00
|
|
|
padLayerSet = LSET::AllCuMask() | LSET( 4, F_Mask, B_Mask, F_Paste, B_Paste );
|
2020-10-24 17:02:44 +00:00
|
|
|
break;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unknown Pad type" ) );
|
2020-10-24 17:02:44 +00:00
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2021-11-10 21:21:08 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB::SMD ); // assume SMD pad for now
|
2021-03-25 17:47:40 +00:00
|
|
|
pad->SetLocalSolderMaskMargin( 0 );
|
|
|
|
pad->SetLocalSolderPasteMargin( 0 );
|
|
|
|
pad->SetLocalSolderPasteMarginRatio( 0.0 );
|
|
|
|
bool complexPadErrorLogged = false;
|
|
|
|
|
|
|
|
for( auto& reassign : csPadcode.Reassigns )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID kiLayer = getKiCadLayer( reassign.first );
|
2021-05-01 12:22:35 +00:00
|
|
|
CADSTAR_PAD_SHAPE shape = reassign.second;
|
2021-03-25 17:47:40 +00:00
|
|
|
|
|
|
|
if( shape.Size == 0 )
|
|
|
|
{
|
|
|
|
padLayerSet.reset( kiLayer );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-28 14:17:20 +00:00
|
|
|
int newMargin = getKiCadLength( shape.Size - csPadcode.Shape.Size ) / 2;
|
2021-03-25 17:47:40 +00:00
|
|
|
|
|
|
|
if( kiLayer == F_Mask || kiLayer == B_Mask )
|
|
|
|
{
|
|
|
|
if( std::abs( pad->GetLocalSolderMaskMargin() ) < std::abs( newMargin ) )
|
|
|
|
pad->SetLocalSolderMaskMargin( newMargin );
|
|
|
|
}
|
|
|
|
else if( kiLayer == F_Paste || kiLayer == B_Paste )
|
|
|
|
{
|
|
|
|
if( std::abs( pad->GetLocalSolderPasteMargin() ) < std::abs( newMargin ) )
|
|
|
|
pad->SetLocalSolderPasteMargin( newMargin );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//TODO fix properly when KiCad supports full padstacks
|
|
|
|
|
|
|
|
if( !complexPadErrorLogged )
|
|
|
|
{
|
|
|
|
complexPadErrorLogged = true;
|
|
|
|
errorMSG +=
|
|
|
|
wxT( "\n - " )
|
|
|
|
+ wxString::Format(
|
|
|
|
_( "The CADSTAR pad definition '%s' is a complex pad stack, "
|
|
|
|
"which is not supported in KiCad. Please review the "
|
|
|
|
"imported pads as they may require manual correction." ),
|
|
|
|
csPadcode.Name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetLayerSet( padLayerSet );
|
|
|
|
|
2021-10-11 15:41:36 +00:00
|
|
|
if( aCadstarPad.PCBonlyPad )
|
|
|
|
{
|
|
|
|
// PCB Only pads in CADSTAR do not have a representation in the schematic - they are
|
|
|
|
// purely mechanical pads that have no net associated with them. Make the pad name
|
|
|
|
// empty to avoid warnings when importing from the schematic
|
|
|
|
pad->SetNumber( wxT( "" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pad->SetNumber( aCadstarPad.Identifier.IsEmpty()
|
|
|
|
? wxString::Format( wxT( "%ld" ), aCadstarPad.ID )
|
|
|
|
: aCadstarPad.Identifier );
|
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
if( csPadcode.Shape.Size == 0 )
|
2021-02-08 20:30:57 +00:00
|
|
|
{
|
|
|
|
if( csPadcode.DrillDiameter == UNDEFINED_VALUE
|
|
|
|
&& aCadstarPad.Side == PAD_SIDE::THROUGH_HOLE )
|
|
|
|
{
|
|
|
|
// Through-hole, zero sized pad?. Lets load this just on the F_Mask for now to
|
|
|
|
// prevent DRC errors.
|
|
|
|
// TODO: This could be a custom padstack, update when KiCad supports padstacks
|
2021-05-01 14:46:50 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB::SMD );
|
2021-02-08 20:30:57 +00:00
|
|
|
pad->SetLayerSet( LSET( 1, F_Mask ) );
|
|
|
|
}
|
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
// zero sized pads seems to break KiCad so lets make it very small instead
|
|
|
|
csPadcode.Shape.Size = 1;
|
2021-02-08 20:30:57 +00:00
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2022-01-05 02:23:11 +00:00
|
|
|
VECTOR2I padOffset = { 0, 0 }; // offset of the pad origin (before rotating)
|
|
|
|
VECTOR2I drillOffset = { 0, 0 }; // offset of the drill origin w.r.t. the pad (before rotating)
|
2020-10-24 23:40:26 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
switch( csPadcode.Shape.ShapeType )
|
|
|
|
{
|
|
|
|
case PAD_SHAPE_TYPE::ANNULUS:
|
|
|
|
//todo fix: use custom shape instead (Donught shape, i.e. a circle with a hole)
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CIRCLE );
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetSize( { getKiCadLength( csPadcode.Shape.Size ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TYPE::BULLET:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CHAMFERED_RECT );
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetSize( { getKiCadLength( (long long) csPadcode.Shape.Size
|
|
|
|
+ (long long) csPadcode.Shape.LeftLength
|
|
|
|
+ (long long) csPadcode.Shape.RightLength ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
|
|
|
pad->SetChamferPositions( RECT_CHAMFER_POSITIONS::RECT_CHAMFER_BOTTOM_LEFT
|
|
|
|
| RECT_CHAMFER_POSITIONS::RECT_CHAMFER_TOP_LEFT );
|
|
|
|
pad->SetRoundRectRadiusRatio( 0.5 );
|
|
|
|
pad->SetChamferRectRatio( 0.0 );
|
2020-10-24 23:40:26 +00:00
|
|
|
|
|
|
|
padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
|
|
|
|
( (long long) csPadcode.Shape.RightLength / 2 ) );
|
2020-10-24 17:02:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TYPE::CIRCLE:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CIRCLE );
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetSize( { getKiCadLength( csPadcode.Shape.Size ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TYPE::DIAMOND:
|
2020-10-24 23:40:26 +00:00
|
|
|
{
|
|
|
|
// Cadstar diamond shape is a square rotated 45 degrees
|
|
|
|
// We convert it in KiCad to a square with chamfered edges
|
|
|
|
int sizeOfSquare = (double) getKiCadLength( csPadcode.Shape.Size ) * sqrt(2.0);
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECT );
|
2020-10-24 23:40:26 +00:00
|
|
|
pad->SetChamferRectRatio( 0.5 );
|
|
|
|
pad->SetSize( { sizeOfSquare, sizeOfSquare } );
|
|
|
|
|
|
|
|
padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
|
|
|
|
( (long long) csPadcode.Shape.RightLength / 2 ) );
|
|
|
|
}
|
2020-10-24 17:02:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TYPE::FINGER:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::OVAL );
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetSize( { getKiCadLength( (long long) csPadcode.Shape.Size
|
|
|
|
+ (long long) csPadcode.Shape.LeftLength
|
|
|
|
+ (long long) csPadcode.Shape.RightLength ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
2020-11-02 19:23:01 +00:00
|
|
|
|
2020-10-24 23:40:26 +00:00
|
|
|
padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
|
|
|
|
( (long long) csPadcode.Shape.RightLength / 2 ) );
|
2020-10-24 17:02:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TYPE::OCTAGON:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CHAMFERED_RECT );
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetChamferPositions( RECT_CHAMFER_POSITIONS::RECT_CHAMFER_ALL );
|
|
|
|
pad->SetChamferRectRatio( 0.25 );
|
|
|
|
pad->SetSize( { getKiCadLength( csPadcode.Shape.Size ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TYPE::RECTANGLE:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECT );
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetSize( { getKiCadLength( (long long) csPadcode.Shape.Size
|
|
|
|
+ (long long) csPadcode.Shape.LeftLength
|
|
|
|
+ (long long) csPadcode.Shape.RightLength ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
2020-10-24 23:40:26 +00:00
|
|
|
|
|
|
|
padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
|
|
|
|
( (long long) csPadcode.Shape.RightLength / 2 ) );
|
2020-10-24 17:02:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TYPE::ROUNDED_RECT:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECT );
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetRoundRectCornerRadius( getKiCadLength( csPadcode.Shape.InternalFeature ) );
|
|
|
|
pad->SetSize( { getKiCadLength( (long long) csPadcode.Shape.Size
|
|
|
|
+ (long long) csPadcode.Shape.LeftLength
|
|
|
|
+ (long long) csPadcode.Shape.RightLength ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
2020-11-02 19:23:01 +00:00
|
|
|
|
2020-10-24 23:40:26 +00:00
|
|
|
padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
|
|
|
|
( (long long) csPadcode.Shape.RightLength / 2 ) );
|
2020-10-24 17:02:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case PAD_SHAPE_TYPE::SQUARE:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECT );
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetSize( { getKiCadLength( csPadcode.Shape.Size ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unknown Pad Shape" ) );
|
2020-10-24 17:02:44 +00:00
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
if( csPadcode.ReliefClearance != UNDEFINED_VALUE )
|
|
|
|
pad->SetThermalGap( getKiCadLength( csPadcode.ReliefClearance ) );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
if( csPadcode.ReliefWidth != UNDEFINED_VALUE )
|
|
|
|
pad->SetThermalSpokeWidth( getKiCadLength( csPadcode.ReliefWidth ) );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
if( csPadcode.DrillDiameter != UNDEFINED_VALUE )
|
|
|
|
{
|
|
|
|
if( csPadcode.SlotLength != UNDEFINED_VALUE )
|
|
|
|
{
|
2020-10-24 23:40:26 +00:00
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_OBLONG );
|
2020-11-02 19:23:01 +00:00
|
|
|
pad->SetDrillSize( { getKiCadLength( (long long) csPadcode.SlotLength +
|
2020-10-25 23:28:04 +00:00
|
|
|
(long long) csPadcode.DrillDiameter ),
|
|
|
|
getKiCadLength( csPadcode.DrillDiameter ) } );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
2020-10-24 17:02:44 +00:00
|
|
|
else
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2020-10-24 23:40:26 +00:00
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_CIRCLE );
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetDrillSize( { getKiCadLength( csPadcode.DrillDiameter ),
|
|
|
|
getKiCadLength( csPadcode.DrillDiameter ) } );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
2020-10-24 23:40:26 +00:00
|
|
|
|
|
|
|
drillOffset.x = -getKiCadLength( csPadcode.DrillXoffset );
|
|
|
|
drillOffset.y = getKiCadLength( csPadcode.DrillYoffset );
|
2021-11-10 21:21:08 +00:00
|
|
|
|
|
|
|
if( csPadcode.Plated )
|
|
|
|
pad->SetAttribute( PAD_ATTRIB::PTH );
|
|
|
|
else
|
|
|
|
pad->SetAttribute( PAD_ATTRIB::NPTH );
|
2020-10-25 23:28:04 +00:00
|
|
|
}
|
2021-02-08 20:30:57 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pad->SetDrillSize( { 0, 0 } );
|
|
|
|
}
|
2020-10-25 23:28:04 +00:00
|
|
|
|
|
|
|
if( csPadcode.SlotOrientation != 0 )
|
|
|
|
{
|
|
|
|
LSET lset = pad->GetLayerSet();
|
|
|
|
lset &= LSET::AllCuMask();
|
|
|
|
|
|
|
|
if( lset.size() > 0 )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET padOutline;
|
|
|
|
PCB_LAYER_ID layer = lset.Seq().at( 0 );
|
2021-02-13 20:00:17 +00:00
|
|
|
int maxError = m_board->GetDesignSettings().m_MaxError;
|
2020-10-25 23:28:04 +00:00
|
|
|
|
|
|
|
pad->SetPosition( { 0, 0 } );
|
|
|
|
pad->SetPos0( { 0, 0 } );
|
2022-10-21 12:48:45 +00:00
|
|
|
pad->TransformShapeToPolygon( padOutline, layer, 0, maxError, ERROR_INSIDE );
|
2020-10-25 23:28:04 +00:00
|
|
|
|
|
|
|
PCB_SHAPE* padShape = new PCB_SHAPE;
|
2021-07-21 18:31:25 +00:00
|
|
|
padShape->SetShape( SHAPE_T::POLY );
|
2020-11-14 01:16:02 +00:00
|
|
|
padShape->SetFilled( true );
|
2020-10-25 23:28:04 +00:00
|
|
|
padShape->SetPolyShape( padOutline );
|
2021-07-17 19:56:18 +00:00
|
|
|
padShape->SetStroke( STROKE_PARAMS( 0 ) );
|
2020-10-25 23:28:04 +00:00
|
|
|
padShape->Move( padOffset - drillOffset );
|
2022-01-13 19:32:00 +00:00
|
|
|
padShape->Rotate( VECTOR2I( 0, 0 ), ANGLE_180 - getAngle( csPadcode.SlotOrientation ) );
|
2020-10-25 23:28:04 +00:00
|
|
|
|
|
|
|
SHAPE_POLY_SET editedPadOutline = padShape->GetPolyShape();
|
|
|
|
|
|
|
|
if( editedPadOutline.Contains( { 0, 0 } ) )
|
2020-11-02 19:23:01 +00:00
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE::RECT );
|
2020-10-25 23:28:04 +00:00
|
|
|
pad->SetSize( wxSize( { 4, 4 } ) );
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CUSTOM );
|
2020-10-25 23:28:04 +00:00
|
|
|
pad->AddPrimitive( padShape );
|
|
|
|
padOffset = { 0, 0 };
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The CADSTAR pad has the hole shape outside the pad shape
|
|
|
|
// Lets just put the hole in the center of the pad instead
|
|
|
|
csPadcode.SlotOrientation = 0;
|
|
|
|
drillOffset = { 0, 0 };
|
|
|
|
|
2021-03-25 17:47:40 +00:00
|
|
|
errorMSG +=
|
|
|
|
wxT( "\n - " )
|
|
|
|
+ wxString::Format(
|
|
|
|
_( "The CADSTAR pad definition '%s' has the hole shape outside the "
|
|
|
|
"pad shape. The hole has been moved to the center of the pad." ),
|
|
|
|
csPadcode.Name );
|
2020-10-25 23:28:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "No copper layers defined in the pad?" ) );
|
2020-10-25 23:28:04 +00:00
|
|
|
csPadcode.SlotOrientation = 0;
|
|
|
|
pad->SetOffset( drillOffset );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-24 23:40:26 +00:00
|
|
|
pad->SetOffset( drillOffset );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
2020-10-24 23:40:26 +00:00
|
|
|
|
2022-01-13 13:45:48 +00:00
|
|
|
EDA_ANGLE padOrientation = getAngle( aCadstarPad.OrientAngle )
|
|
|
|
+ getAngle( csPadcode.Shape.OrientAngle );
|
2020-10-24 23:40:26 +00:00
|
|
|
|
2022-01-05 02:23:11 +00:00
|
|
|
RotatePoint( padOffset, padOrientation );
|
|
|
|
RotatePoint( drillOffset, padOrientation );
|
2020-10-24 23:40:26 +00:00
|
|
|
pad->SetPos0( getKiCadPoint( aCadstarPad.Position ) - aParent->GetPosition() - padOffset
|
|
|
|
- drillOffset );
|
2022-01-13 13:45:48 +00:00
|
|
|
pad->SetOrientation( padOrientation + getAngle( csPadcode.SlotOrientation ) );
|
2020-10-24 23:40:26 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
//TODO handle csPadcode.Reassigns when KiCad supports full padstacks
|
|
|
|
|
2021-03-25 17:47:40 +00:00
|
|
|
//log warnings:
|
|
|
|
if( m_padcodesTested.find( csPadcode.ID ) == m_padcodesTested.end() && !errorMSG.IsEmpty() )
|
|
|
|
{
|
2021-06-26 19:21:30 +00:00
|
|
|
wxLogError( _( "The CADSTAR pad definition '%s' has import errors: %s" ),
|
|
|
|
csPadcode.Name,
|
|
|
|
errorMSG );
|
2021-03-25 17:47:40 +00:00
|
|
|
|
|
|
|
m_padcodesTested.insert( csPadcode.ID );
|
|
|
|
}
|
|
|
|
|
2022-08-14 01:51:14 +00:00
|
|
|
return pad.release();
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-10 18:14:43 +00:00
|
|
|
PAD*& CADSTAR_PCB_ARCHIVE_LOADER::getPadReference( FOOTPRINT* aFootprint,
|
|
|
|
const PAD_ID aCadstarPadID )
|
|
|
|
{
|
2022-02-05 19:18:49 +00:00
|
|
|
size_t index = aCadstarPadID - (long) 1;
|
|
|
|
|
|
|
|
if( !( index < aFootprint->Pads().size() ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unable to find pad index '%d' in footprint '%s'." ),
|
|
|
|
(long) aCadstarPadID,
|
|
|
|
aFootprint->GetReference() ) );
|
2022-02-05 19:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return aFootprint->Pads().at( index );
|
2021-04-10 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadGroups()
|
|
|
|
{
|
|
|
|
for( std::pair<GROUP_ID, GROUP> groupPair : Layout.Groups )
|
|
|
|
{
|
|
|
|
GROUP& csGroup = groupPair.second;
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
PCB_GROUP* kiGroup = new PCB_GROUP( m_board );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( kiGroup );
|
2020-09-06 21:20:32 +00:00
|
|
|
kiGroup->SetName( csGroup.Name );
|
|
|
|
kiGroup->SetLocked( csGroup.Fixed );
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_groupMap.insert( { csGroup.ID, kiGroup } );
|
2020-09-06 21:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//now add any groups to their parent group
|
|
|
|
for( std::pair<GROUP_ID, GROUP> groupPair : Layout.Groups )
|
|
|
|
{
|
|
|
|
GROUP& csGroup = groupPair.second;
|
|
|
|
|
|
|
|
if( !csGroup.GroupID.IsEmpty() )
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_groupMap.find( csGroup.ID ) == m_groupMap.end() )
|
2020-09-16 10:27:15 +00:00
|
|
|
{
|
2021-06-27 23:26:54 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unable to find group ID %s in the group "
|
|
|
|
"definitions." ),
|
|
|
|
csGroup.ID ) );
|
2020-09-16 10:27:15 +00:00
|
|
|
}
|
2021-02-13 20:00:17 +00:00
|
|
|
else if( m_groupMap.find( csGroup.ID ) == m_groupMap.end() )
|
2020-09-16 10:27:15 +00:00
|
|
|
{
|
2021-06-27 23:26:54 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unable to find sub group %s in the group "
|
|
|
|
"map (parent group ID=%s, Name=%s)." ),
|
|
|
|
csGroup.GroupID,
|
|
|
|
csGroup.ID,
|
|
|
|
csGroup.Name ) );
|
2020-09-16 10:27:15 +00:00
|
|
|
}
|
2020-09-06 21:20:32 +00:00
|
|
|
else
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
PCB_GROUP* kiCadGroup = m_groupMap.at( csGroup.ID );
|
|
|
|
PCB_GROUP* parentGroup = m_groupMap.at( csGroup.GroupID );
|
2020-09-06 21:20:32 +00:00
|
|
|
parentGroup->AddItem( kiCadGroup );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadBoards()
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<BOARD_ID, CADSTAR_BOARD> boardPair : Layout.Boards )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
CADSTAR_BOARD& board = boardPair.second;
|
2020-09-06 21:20:32 +00:00
|
|
|
GROUP_ID boardGroup = createUniqueGroupID( wxT( "Board" ) );
|
2020-09-08 17:35:06 +00:00
|
|
|
drawCadstarShape( board.Shape, PCB_LAYER_ID::Edge_Cuts,
|
2022-02-05 02:06:25 +00:00
|
|
|
getLineThickness( board.LineCodeID ),
|
|
|
|
wxString::Format( wxT( "BOARD %s" ), board.ID ),
|
|
|
|
m_board, boardGroup );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
if( !board.GroupID.IsEmpty() )
|
|
|
|
{
|
|
|
|
addToGroup( board.GroupID, getKiCadGroup( boardGroup ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO process board attributes when KiCad supports them
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadFigures()
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
|
|
|
for( std::pair<FIGURE_ID, FIGURE> figPair : Layout.Figures )
|
|
|
|
{
|
|
|
|
FIGURE& fig = figPair.second;
|
2020-09-08 17:35:06 +00:00
|
|
|
drawCadstarShape( fig.Shape, getKiCadLayer( fig.LayerID ),
|
2022-02-05 02:06:25 +00:00
|
|
|
getLineThickness( fig.LineCodeID ),
|
|
|
|
wxString::Format( wxT( "FIGURE %s" ), fig.ID ),
|
2021-07-26 19:35:12 +00:00
|
|
|
m_board, fig.GroupID );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
//TODO process "swaprule" (doesn't seem to apply to Layout Figures?)
|
2020-08-28 20:32:53 +00:00
|
|
|
//TODO process re-use block when KiCad Supports it
|
|
|
|
//TODO process attributes when KiCad Supports attributes in figures
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
|
2020-09-02 21:48:18 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadTexts()
|
|
|
|
{
|
|
|
|
for( std::pair<TEXT_ID, TEXT> txtPair : Layout.Texts )
|
|
|
|
{
|
|
|
|
TEXT& csTxt = txtPair.second;
|
2021-02-13 20:00:17 +00:00
|
|
|
drawCadstarText( csTxt, m_board );
|
2020-09-02 21:48:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-09-06 22:16:02 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadDimensions()
|
|
|
|
{
|
|
|
|
for( std::pair<DIMENSION_ID, DIMENSION> dimPair : Layout.Dimensions )
|
|
|
|
{
|
|
|
|
DIMENSION& csDim = dimPair.second;
|
|
|
|
|
|
|
|
switch( csDim.Type )
|
|
|
|
{
|
|
|
|
case DIMENSION::TYPE::LINEARDIM:
|
|
|
|
switch( csDim.Subtype )
|
|
|
|
{
|
2020-12-23 01:49:23 +00:00
|
|
|
case DIMENSION::SUBTYPE::ANGLED:
|
|
|
|
wxLogWarning( wxString::Format( _( "Dimension ID %s is an angled dimension, which "
|
|
|
|
"has no KiCad equivalent. An aligned dimension "
|
|
|
|
"was loaded instead." ),
|
|
|
|
csDim.ID ) );
|
|
|
|
KI_FALLTHROUGH;
|
2020-09-06 22:16:02 +00:00
|
|
|
case DIMENSION::SUBTYPE::DIRECT:
|
|
|
|
case DIMENSION::SUBTYPE::ORTHOGONAL:
|
|
|
|
{
|
2020-12-23 01:49:23 +00:00
|
|
|
if( csDim.Line.Style == DIMENSION::LINE::STYLE::EXTERNAL )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "Dimension ID %s has 'External' style in CADSTAR. External "
|
|
|
|
"dimension styles are not yet supported in KiCad. The dimension "
|
|
|
|
"object was imported with an internal dimension style instead." ),
|
|
|
|
csDim.ID ) );
|
|
|
|
}
|
|
|
|
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIM_ALIGNED* dimension = nullptr;
|
2020-12-23 01:49:23 +00:00
|
|
|
|
|
|
|
if( csDim.Subtype == DIMENSION::SUBTYPE::ORTHOGONAL )
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
dimension = new PCB_DIM_ORTHOGONAL( m_board );
|
|
|
|
PCB_DIM_ORTHOGONAL* orDim = static_cast<PCB_DIM_ORTHOGONAL*>( dimension );
|
2020-12-23 01:49:23 +00:00
|
|
|
|
|
|
|
if( csDim.ExtensionLineParams.Start.x == csDim.Line.Start.x )
|
2021-06-11 16:59:28 +00:00
|
|
|
orDim->SetOrientation( PCB_DIM_ORTHOGONAL::DIR::HORIZONTAL );
|
2020-12-23 01:49:23 +00:00
|
|
|
else
|
2021-06-11 16:59:28 +00:00
|
|
|
orDim->SetOrientation( PCB_DIM_ORTHOGONAL::DIR::VERTICAL );
|
2020-12-23 01:49:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-04 23:52:00 +00:00
|
|
|
dimension = new PCB_DIM_ALIGNED( m_board, PCB_DIM_ALIGNED_T );
|
2020-12-23 01:49:23 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( dimension, ADD_MODE::APPEND );
|
2020-12-23 01:49:23 +00:00
|
|
|
applyDimensionSettings( csDim, dimension );
|
2021-01-31 20:47:36 +00:00
|
|
|
|
2020-12-23 01:49:23 +00:00
|
|
|
dimension->SetExtensionHeight(
|
|
|
|
getKiCadLength( csDim.ExtensionLineParams.Overshoot ) );
|
|
|
|
|
|
|
|
// Calculate height:
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I crossbarStart = getKiCadPoint( csDim.Line.Start );
|
|
|
|
VECTOR2I crossbarEnd = getKiCadPoint( csDim.Line.End );
|
2020-12-23 01:49:23 +00:00
|
|
|
VECTOR2I crossbarVector = crossbarEnd - crossbarStart;
|
|
|
|
VECTOR2I heightVector = crossbarStart - dimension->GetStart();
|
|
|
|
double height = 0.0;
|
|
|
|
|
|
|
|
if( csDim.Subtype == DIMENSION::SUBTYPE::ORTHOGONAL )
|
|
|
|
{
|
|
|
|
if( csDim.ExtensionLineParams.Start.x == csDim.Line.Start.x )
|
|
|
|
height = heightVector.y;
|
|
|
|
else
|
|
|
|
height = heightVector.x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-20 18:10:14 +00:00
|
|
|
EDA_ANGLE angle( crossbarVector );
|
|
|
|
angle += ANGLE_90;
|
|
|
|
height = heightVector.x * angle.Cos() + heightVector.y * angle.Sin();
|
2020-12-23 01:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dimension->SetHeight( height );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Radius and diameter dimensions are LEADERDIM (even if not actually leader)
|
|
|
|
// Angular dimensions are always ANGLEDIM
|
2021-06-26 19:21:30 +00:00
|
|
|
wxLogError( _( "Unexpected Dimension type (ID %s). This was not imported." ),
|
|
|
|
csDim.ID );
|
2020-12-23 01:49:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIMENSION::TYPE::LEADERDIM:
|
|
|
|
//TODO: update import when KiCad supports radius and diameter dimensions
|
|
|
|
|
|
|
|
if( csDim.Line.Style == DIMENSION::LINE::STYLE::INTERNAL )
|
|
|
|
{
|
|
|
|
// "internal" is a simple double sided arrow from start to end (no extension lines)
|
2021-12-04 23:52:00 +00:00
|
|
|
PCB_DIM_ALIGNED* dimension = new PCB_DIM_ALIGNED( m_board, PCB_DIM_ALIGNED_T );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( dimension, ADD_MODE::APPEND );
|
2020-12-23 01:49:23 +00:00
|
|
|
applyDimensionSettings( csDim, dimension );
|
2020-09-06 22:16:02 +00:00
|
|
|
|
2020-12-23 01:49:23 +00:00
|
|
|
// Lets set again start/end:
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetStart( getKiCadPoint( csDim.Line.Start ) );
|
|
|
|
dimension->SetEnd( getKiCadPoint( csDim.Line.End ) );
|
2020-09-06 22:16:02 +00:00
|
|
|
|
2020-12-23 01:49:23 +00:00
|
|
|
// Do not use any extension lines:
|
|
|
|
dimension->SetExtensionOffset( 0 );
|
|
|
|
dimension->SetExtensionHeight( 0 );
|
|
|
|
dimension->SetHeight( 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// "external" is a "leader" style dimension
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIM_LEADER* leaderDim = new PCB_DIM_LEADER( m_board );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( leaderDim, ADD_MODE::APPEND );
|
2020-12-23 01:49:23 +00:00
|
|
|
|
|
|
|
applyDimensionSettings( csDim, leaderDim );
|
|
|
|
leaderDim->SetStart( getKiCadPoint( csDim.Line.End ) );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In CADSTAR, the resulting shape orientation of the leader dimension depends on
|
2021-01-31 20:47:36 +00:00
|
|
|
* on the positions of the #Start (S) and #End (E) points as shown below. In the
|
2020-12-23 01:49:23 +00:00
|
|
|
* diagrams below, the leader angle (angRad) is represented by HEV
|
2021-01-31 20:47:36 +00:00
|
|
|
*
|
|
|
|
* Orientation 1: (orientX = -1, | Orientation 2: (orientX = 1,
|
2020-12-23 01:49:23 +00:00
|
|
|
* orientY = 1) | orientY = 1)
|
|
|
|
* |
|
|
|
|
* --------V | V----------
|
2021-01-31 20:47:36 +00:00
|
|
|
* \ | /
|
|
|
|
* \ | /
|
2020-12-23 01:49:23 +00:00
|
|
|
* H _E/ | \E_ H
|
2021-01-31 20:47:36 +00:00
|
|
|
* |
|
2020-12-23 01:49:23 +00:00
|
|
|
* S | S
|
|
|
|
* |
|
2021-01-31 20:47:36 +00:00
|
|
|
*
|
|
|
|
* Orientation 3: (orientX = -1, | Orientation 4: (orientX = 1,
|
2020-12-23 01:49:23 +00:00
|
|
|
* orientY = -1) | orientY = -1)
|
|
|
|
* |
|
|
|
|
* S | S
|
|
|
|
* _ | _
|
|
|
|
* H E\ | /E H
|
|
|
|
* / | \
|
|
|
|
* / | \
|
|
|
|
* ----------V | V-----------
|
|
|
|
* |
|
2021-01-31 20:47:36 +00:00
|
|
|
*
|
2020-12-23 01:49:23 +00:00
|
|
|
* Corner cases:
|
2021-01-31 20:47:36 +00:00
|
|
|
*
|
2020-12-23 01:49:23 +00:00
|
|
|
* It is not possible to generate a leader object with start and end point being
|
|
|
|
* identical. Assume Orientation 2 if start and end points are identical.
|
2021-01-31 20:47:36 +00:00
|
|
|
*
|
2020-12-23 01:49:23 +00:00
|
|
|
* If start and end points are aligned vertically (i.e. S.x == E.x):
|
|
|
|
* - If E.y > S.y - Orientation 2
|
|
|
|
* - If E.y < S.y - Orientation 4
|
2021-01-31 20:47:36 +00:00
|
|
|
*
|
2020-12-23 01:49:23 +00:00
|
|
|
* If start and end points are aligned horitontally (i.e. S.y == E.y):
|
|
|
|
* - If E.x > S.x - Orientation 2
|
|
|
|
* - If E.x < S.x - Orientation 1
|
|
|
|
*/
|
|
|
|
double angRad = DEG2RAD( getAngleDegrees( csDim.Line.LeaderAngle ) );
|
|
|
|
|
|
|
|
double orientX = 1;
|
|
|
|
double orientY = 1;
|
|
|
|
|
|
|
|
if( csDim.Line.End.x >= csDim.Line.Start.x )
|
2020-10-13 23:41:16 +00:00
|
|
|
{
|
2020-12-23 01:49:23 +00:00
|
|
|
if( csDim.Line.End.y >= csDim.Line.Start.y )
|
|
|
|
{
|
|
|
|
//Orientation 2
|
|
|
|
orientX = 1;
|
|
|
|
orientY = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Orientation 4
|
|
|
|
orientX = 1;
|
|
|
|
orientY = -1;
|
|
|
|
}
|
2020-10-13 23:41:16 +00:00
|
|
|
}
|
2020-12-23 01:49:23 +00:00
|
|
|
else
|
2020-09-06 22:16:02 +00:00
|
|
|
{
|
2020-12-23 01:49:23 +00:00
|
|
|
if( csDim.Line.End.y >= csDim.Line.Start.y )
|
|
|
|
{
|
|
|
|
//Orientation 1
|
|
|
|
orientX = -1;
|
|
|
|
orientY = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Orientation 3
|
|
|
|
orientX = -1;
|
|
|
|
orientY = -1;
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 22:16:02 +00:00
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
VECTOR2I endOffset( csDim.Line.LeaderLineLength * cos( angRad ) * orientX,
|
|
|
|
csDim.Line.LeaderLineLength * sin( angRad ) * orientY );
|
2020-09-06 22:16:02 +00:00
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
VECTOR2I endPoint = VECTOR2I( csDim.Line.End ) + endOffset;
|
|
|
|
VECTOR2I txtPoint( endPoint.x + ( csDim.Line.LeaderLineExtensionLength * orientX ),
|
|
|
|
endPoint.y );
|
2020-10-13 23:41:16 +00:00
|
|
|
|
2020-12-23 01:49:23 +00:00
|
|
|
leaderDim->SetEnd( getKiCadPoint( endPoint ) );
|
2023-03-04 23:15:43 +00:00
|
|
|
leaderDim->SetTextPos( getKiCadPoint( txtPoint ) );
|
|
|
|
leaderDim->SetOverrideText( ParseTextFields( csDim.Text.Text, &m_context ) );
|
2020-12-27 17:37:25 +00:00
|
|
|
leaderDim->SetPrefix( wxEmptyString );
|
|
|
|
leaderDim->SetSuffix( wxEmptyString );
|
|
|
|
leaderDim->SetUnitsFormat( DIM_UNITS_FORMAT::NO_SUFFIX );
|
2020-10-13 23:41:16 +00:00
|
|
|
|
2020-12-23 01:49:23 +00:00
|
|
|
if( orientX == 1 )
|
2023-03-04 23:15:43 +00:00
|
|
|
leaderDim->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-12-23 01:49:23 +00:00
|
|
|
else
|
2023-03-04 23:15:43 +00:00
|
|
|
leaderDim->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-09-06 22:16:02 +00:00
|
|
|
|
2020-12-23 01:49:23 +00:00
|
|
|
leaderDim->SetExtensionOffset( 0 );
|
2020-09-06 22:16:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIMENSION::TYPE::ANGLEDIM:
|
2020-12-23 01:49:23 +00:00
|
|
|
//TODO: update import when KiCad supports angular dimensions
|
2021-06-26 19:21:30 +00:00
|
|
|
wxLogError( _( "Dimension %s is an angular dimension which has no KiCad equivalent. "
|
|
|
|
"The object was not imported." ),
|
|
|
|
csDim.ID );
|
2020-09-06 22:16:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadAreas()
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
|
|
|
for( std::pair<AREA_ID, AREA> areaPair : Layout.Areas )
|
|
|
|
{
|
|
|
|
AREA& area = areaPair.second;
|
|
|
|
|
2020-10-13 22:35:09 +00:00
|
|
|
if( area.NoVias || area.NoTracks || area.Keepout || area.Routing )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2021-10-08 20:27:32 +00:00
|
|
|
int lineThickness = 0; // CADSTAR areas only use the line width for display purpose
|
|
|
|
ZONE* zone = getZoneFromCadstarShape( area.Shape, lineThickness, m_board );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
if( isLayerSet( area.LayerID ) )
|
|
|
|
zone->SetLayerSet( getKiCadLayerSet( area.LayerID ) );
|
|
|
|
else
|
|
|
|
zone->SetLayer( getKiCadLayer( area.LayerID ) );
|
|
|
|
|
2020-09-27 13:10:59 +00:00
|
|
|
zone->SetIsRuleArea( true ); //import all CADSTAR areas as Keepout zones
|
2020-08-23 10:34:27 +00:00
|
|
|
zone->SetDoNotAllowPads( false ); //no CADSTAR equivalent
|
|
|
|
zone->SetZoneName( area.Name );
|
|
|
|
|
|
|
|
zone->SetDoNotAllowFootprints( area.Keepout );
|
|
|
|
|
|
|
|
zone->SetDoNotAllowTracks( area.NoTracks );
|
|
|
|
zone->SetDoNotAllowCopperPour( area.NoTracks );
|
|
|
|
|
|
|
|
zone->SetDoNotAllowVias( area.NoVias );
|
|
|
|
|
2020-10-13 22:35:09 +00:00
|
|
|
if( area.Placement )
|
2021-06-27 23:26:54 +00:00
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format( _( "The CADSTAR area '%s' is marked as a placement "
|
|
|
|
"area in CADSTAR. Placement areas are not "
|
|
|
|
"supported in KiCad. Only the supported elements "
|
|
|
|
"for the area were imported." ),
|
|
|
|
area.Name ) );
|
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-27 23:26:54 +00:00
|
|
|
wxLogError( wxString::Format( _( "The CADSTAR area '%s' does not have a KiCad "
|
|
|
|
"equivalent. Pure Placement areas are not supported." ),
|
|
|
|
area.Name ) );
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//todo Process area.AreaHeight when KiCad supports 3D design rules
|
|
|
|
//TODO process attributes
|
|
|
|
//TODO process addition to a group
|
|
|
|
//TODO process "swaprule"
|
|
|
|
//TODO process re-use block
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadComponents()
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
for( std::pair<COMPONENT_ID, COMPONENT> compPair : Layout.Components )
|
|
|
|
{
|
2020-11-21 12:55:58 +00:00
|
|
|
COMPONENT& comp = compPair.second;
|
|
|
|
|
|
|
|
if( !comp.VariantID.empty() && comp.VariantParentComponentID != comp.ID )
|
|
|
|
continue; // Only load master Variant
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
auto fpIter = m_libraryMap.find( comp.SymdefID );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
if( fpIter == m_libraryMap.end() )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unable to find component '%s' in the library"
|
|
|
|
"(Symdef ID: '%s')" ),
|
2021-06-27 23:26:54 +00:00
|
|
|
comp.Name,
|
|
|
|
comp.SymdefID ) );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 23:26:27 +00:00
|
|
|
FOOTPRINT* libFootprint = fpIter->second;
|
|
|
|
|
2020-11-23 20:34:57 +00:00
|
|
|
// Use Duplicate() to ensure unique KIID for all objects
|
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( libFootprint->Duplicate() );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( footprint, ADD_MODE::APPEND );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-18 23:26:27 +00:00
|
|
|
// First lets fix the pad names on the footprint.
|
|
|
|
// CADSTAR defines the pad name in the PART definition and the SYMDEF (i.e. the PCB
|
|
|
|
// footprint definition) uses a numerical sequence. COMP is the only object that has
|
|
|
|
// visibility of both the SYMDEF and PART.
|
|
|
|
if( Parts.PartDefinitions.find( comp.PartID ) != Parts.PartDefinitions.end() )
|
|
|
|
{
|
|
|
|
PART part = Parts.PartDefinitions.at( comp.PartID );
|
|
|
|
|
|
|
|
// Only do this when the number of pins in the part definition equals the number of
|
|
|
|
// pads in the footprint.
|
|
|
|
if( part.Definition.Pins.size() == footprint->Pads().size() )
|
|
|
|
{
|
|
|
|
for( std::pair<PART_DEFINITION_PIN_ID, PART::DEFINITION::PIN> pinPair :
|
|
|
|
part.Definition.Pins )
|
|
|
|
{
|
|
|
|
PART::DEFINITION::PIN pin = pinPair.second;
|
|
|
|
wxString pinName = pin.Name;
|
|
|
|
|
|
|
|
if( pinName.empty() )
|
|
|
|
pinName = pin.Identifier;
|
|
|
|
|
|
|
|
if( pinName.empty() )
|
|
|
|
pinName = wxString::Format( wxT( "%ld" ), pin.ID );
|
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
getPadReference( footprint, pin.ID )->SetNumber( pinName );
|
2020-11-18 23:26:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
//Override pads with pad exceptions
|
|
|
|
if( comp.PadExceptions.size() > 0 )
|
|
|
|
{
|
|
|
|
SYMDEF_PCB fpLibEntry = Library.ComponentDefinitions.at( comp.SymdefID );
|
|
|
|
|
|
|
|
for( std::pair<PAD_ID, PADEXCEPTION> padPair : comp.PadExceptions )
|
|
|
|
{
|
|
|
|
PADEXCEPTION& padEx = padPair.second;
|
2020-11-12 21:12:58 +00:00
|
|
|
COMPONENT_PAD csPad = fpLibEntry.ComponentPads.at( padPair.first );
|
2020-10-24 17:02:44 +00:00
|
|
|
|
2023-03-29 18:44:36 +00:00
|
|
|
// Reset the pad to be around 0,0
|
|
|
|
csPad.Position -= fpLibEntry.Origin;
|
|
|
|
csPad.Position += m_designCenter;
|
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
if( !padEx.PadCode.IsEmpty() )
|
|
|
|
csPad.PadCodeID = padEx.PadCode;
|
|
|
|
|
|
|
|
if( padEx.OverrideExits )
|
|
|
|
csPad.Exits = padEx.Exits;
|
|
|
|
|
|
|
|
if( padEx.OverrideOrientation )
|
|
|
|
csPad.OrientAngle = padEx.OrientAngle;
|
|
|
|
|
|
|
|
if( padEx.OverrideSide )
|
|
|
|
csPad.Side = padEx.Side;
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Find the pad in the footprint definition
|
2022-02-05 19:18:49 +00:00
|
|
|
PAD* kiPad = getPadReference( footprint, padEx.ID );
|
2020-11-02 19:23:01 +00:00
|
|
|
|
2022-02-05 19:18:49 +00:00
|
|
|
wxString padNumber = kiPad->GetNumber();
|
2020-10-24 17:02:44 +00:00
|
|
|
|
2022-02-05 19:18:49 +00:00
|
|
|
delete kiPad;
|
2021-04-10 18:14:43 +00:00
|
|
|
|
2022-08-22 19:54:00 +00:00
|
|
|
if( ( kiPad = getKiCadPad( csPad, footprint ) ) )
|
2022-08-14 01:51:14 +00:00
|
|
|
{
|
|
|
|
kiPad->SetNumber( padNumber );
|
|
|
|
|
|
|
|
// Change the pointer in the footprint to the newly created pad
|
|
|
|
getPadReference( footprint, padEx.ID ) = kiPad;
|
|
|
|
}
|
2020-10-24 17:02:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
//set to empty string to avoid duplication when loading attributes:
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetValue( wxEmptyString );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetPosition( getKiCadPoint( comp.Origin ) );
|
2022-01-13 17:27:36 +00:00
|
|
|
footprint->SetOrientation( getAngle( comp.OrientAngle ) );
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetReference( comp.Name );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
if( comp.Mirror )
|
|
|
|
{
|
2022-01-13 17:27:36 +00:00
|
|
|
EDA_ANGLE mirroredAngle = - getAngle( comp.OrientAngle );
|
|
|
|
mirroredAngle.Normalize180();
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetOrientation( mirroredAngle );
|
|
|
|
footprint->Flip( getKiCadPoint( comp.Origin ), true );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
loadComponentAttributes( comp, footprint );
|
2020-09-08 13:01:32 +00:00
|
|
|
|
|
|
|
if( !comp.PartID.IsEmpty() && comp.PartID != wxT( "NO_PART" ) )
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetDescription( getPart( comp.PartID ).Definition.Name );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_componentMap.insert( { comp.ID, footprint } );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadDocumentationSymbols()
|
|
|
|
{
|
|
|
|
//No KiCad equivalent. Loaded as graphic and text elements instead
|
|
|
|
|
|
|
|
for( std::pair<DOCUMENTATION_SYMBOL_ID, DOCUMENTATION_SYMBOL> docPair :
|
|
|
|
Layout.DocumentationSymbols )
|
|
|
|
{
|
|
|
|
DOCUMENTATION_SYMBOL& docSymInstance = docPair.second;
|
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
auto docSymIter = Library.ComponentDefinitions.find( docSymInstance.SymdefID );
|
|
|
|
|
|
|
|
if( docSymIter == Library.ComponentDefinitions.end() )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unable to find documentation symbol in the "
|
|
|
|
"library (Symdef ID: '%s')" ),
|
|
|
|
docSymInstance.SymdefID ) );
|
|
|
|
}
|
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
SYMDEF_PCB& docSymDefinition = ( *docSymIter ).second;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I moveVector =
|
2020-09-05 15:31:57 +00:00
|
|
|
getKiCadPoint( docSymInstance.Origin ) - getKiCadPoint( docSymDefinition.Origin );
|
2020-09-10 20:58:20 +00:00
|
|
|
double rotationAngle = getAngleTenthDegree( docSymInstance.OrientAngle );
|
|
|
|
double scalingFactor = (double) docSymInstance.ScaleRatioNumerator
|
|
|
|
/ (double) docSymInstance.ScaleRatioDenominator;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I centreOfTransform = getKiCadPoint( docSymDefinition.Origin );
|
2020-09-05 15:31:57 +00:00
|
|
|
bool mirrorInvert = docSymInstance.Mirror;
|
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
//create a group to store the items in
|
|
|
|
wxString groupName = docSymDefinition.ReferenceName;
|
|
|
|
|
|
|
|
if( !docSymDefinition.Alternate.IsEmpty() )
|
|
|
|
groupName += wxT( " (" ) + docSymDefinition.Alternate + wxT( ")" );
|
|
|
|
|
|
|
|
GROUP_ID groupID = createUniqueGroupID( groupName );
|
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
LSEQ layers = getKiCadLayerSet( docSymInstance.LayerID ).Seq();
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : layers )
|
|
|
|
{
|
|
|
|
for( std::pair<FIGURE_ID, FIGURE> figPair : docSymDefinition.Figures )
|
|
|
|
{
|
|
|
|
FIGURE fig = figPair.second;
|
2020-09-08 17:35:06 +00:00
|
|
|
drawCadstarShape( fig.Shape, layer, getLineThickness( fig.LineCodeID ),
|
2022-02-05 02:06:25 +00:00
|
|
|
wxString::Format( wxT( "DOCUMENTATION SYMBOL %s, FIGURE %s" ),
|
|
|
|
docSymDefinition.ReferenceName, fig.ID ),
|
|
|
|
m_board, groupID, moveVector, rotationAngle, scalingFactor,
|
|
|
|
centreOfTransform, mirrorInvert );
|
2020-09-05 15:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( std::pair<TEXT_ID, TEXT> textPair : docSymDefinition.Texts )
|
|
|
|
{
|
|
|
|
TEXT txt = textPair.second;
|
2021-02-13 20:00:17 +00:00
|
|
|
drawCadstarText( txt, m_board, groupID, docSymInstance.LayerID, moveVector,
|
2020-09-10 20:58:20 +00:00
|
|
|
rotationAngle, scalingFactor, centreOfTransform, mirrorInvert );
|
2020-09-05 15:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadTemplates()
|
|
|
|
{
|
|
|
|
for( std::pair<TEMPLATE_ID, TEMPLATE> tempPair : Layout.Templates )
|
|
|
|
{
|
|
|
|
TEMPLATE& csTemplate = tempPair.second;
|
|
|
|
|
2021-02-06 19:36:51 +00:00
|
|
|
int zonelinethickness = 0; // The line thickness in CADSTAR is only for display purposes but
|
|
|
|
// does not affect the end copper result.
|
2021-02-13 20:00:17 +00:00
|
|
|
ZONE* zone = getZoneFromCadstarShape( csTemplate.Shape, zonelinethickness, m_board );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
zone->SetZoneName( csTemplate.Name );
|
|
|
|
zone->SetLayer( getKiCadLayer( csTemplate.LayerID ) );
|
2022-03-01 14:53:35 +00:00
|
|
|
zone->SetAssignedPriority( 1 ); // initially 1, we will increase in calculateZonePriorities
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
if( !( csTemplate.NetID.IsEmpty() || csTemplate.NetID == wxT( "NONE" ) ) )
|
2020-08-31 22:09:29 +00:00
|
|
|
zone->SetNet( getKiCadNet( csTemplate.NetID ) );
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.AllowInNoRouting )
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
2020-08-31 22:09:29 +00:00
|
|
|
_( "The CADSTAR template '%s' has the setting 'Allow in No Routing Areas' "
|
|
|
|
"enabled. This setting has no KiCad equivalent, so it has been ignored." ),
|
|
|
|
csTemplate.Name ) );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
if( csTemplate.Pouring.BoxIsolatedPins )
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
2020-12-30 18:43:54 +00:00
|
|
|
_( "The CADSTAR template '%s' has the setting 'Box Isolated Pins' "
|
2020-08-31 22:09:29 +00:00
|
|
|
"enabled. This setting has no KiCad equivalent, so it has been ignored." ),
|
|
|
|
csTemplate.Name ) );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
if( csTemplate.Pouring.AutomaticRepour )
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
wxLogWarning( wxString::Format(
|
2020-12-30 18:43:54 +00:00
|
|
|
_( "The CADSTAR template '%s' has the setting 'Automatic Repour' "
|
2020-08-31 22:09:29 +00:00
|
|
|
"enabled. This setting has no KiCad equivalent, so it has been ignored." ),
|
|
|
|
csTemplate.Name ) );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
// Sliver width has different behaviour to KiCad Zone's minimum thickness
|
|
|
|
// In Cadstar 'Sliver width' has to be greater than the Copper thickness, whereas in
|
|
|
|
// Kicad it is the opposite.
|
|
|
|
if( csTemplate.Pouring.SliverWidth != 0 )
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
2020-08-31 22:09:29 +00:00
|
|
|
_( "The CADSTAR template '%s' has a non-zero value defined for the "
|
|
|
|
"'Sliver Width' setting. There is no KiCad equivalent for "
|
|
|
|
"this, so this setting was ignored." ),
|
|
|
|
csTemplate.Name ) );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.MinIsolatedCopper != csTemplate.Pouring.MinDisjointCopper )
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
2020-08-31 22:09:29 +00:00
|
|
|
_( "The CADSTAR template '%s' has different settings for 'Retain Poured Copper "
|
|
|
|
"- Disjoint' and 'Retain Poured Copper - Isolated'. KiCad does not "
|
|
|
|
"distinguish between these two settings. The setting for disjoint copper "
|
|
|
|
"has been applied as the minimum island area of the KiCad Zone." ),
|
|
|
|
csTemplate.Name ) );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long long minIslandArea = -1;
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.MinDisjointCopper != UNDEFINED_VALUE )
|
|
|
|
{
|
|
|
|
minIslandArea = (long long) getKiCadLength( csTemplate.Pouring.MinDisjointCopper )
|
|
|
|
* (long long) getKiCadLength( csTemplate.Pouring.MinDisjointCopper );
|
|
|
|
|
|
|
|
zone->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::AREA );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::ALWAYS );
|
|
|
|
}
|
|
|
|
|
|
|
|
zone->SetMinIslandArea( minIslandArea );
|
|
|
|
|
2021-10-09 23:17:24 +00:00
|
|
|
// In cadstar zone clearance is in addition to the global clearance.
|
|
|
|
// TODO: need to create custom rules for individual items: zone to pad, zone to track, etc.
|
2021-02-08 10:40:32 +00:00
|
|
|
int clearance = getKiCadLength( csTemplate.Pouring.AdditionalIsolation );
|
2021-10-09 23:17:24 +00:00
|
|
|
clearance += m_board->GetDesignSettings().m_MinClearance;
|
2021-02-08 10:40:32 +00:00
|
|
|
|
|
|
|
zone->SetLocalClearance( clearance );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
COPPERCODE pouringCopperCode = getCopperCode( csTemplate.Pouring.CopperCodeID );
|
|
|
|
int minThickness = getKiCadLength( pouringCopperCode.CopperWidth );
|
|
|
|
zone->SetMinThickness( minThickness );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-10-15 08:48:02 +00:00
|
|
|
if( csTemplate.Pouring.FillType == TEMPLATE::POURING::COPPER_FILL_TYPE::HATCHED )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
|
|
|
|
zone->SetHatchGap( getKiCadHatchCodeGap( csTemplate.Pouring.HatchCodeID ) );
|
|
|
|
zone->SetHatchThickness( getKiCadHatchCodeThickness( csTemplate.Pouring.HatchCodeID ) );
|
2022-01-19 00:22:40 +00:00
|
|
|
zone->SetHatchOrientation( getHatchCodeAngle( csTemplate.Pouring.HatchCodeID ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.ThermalReliefOnPads != csTemplate.Pouring.ThermalReliefOnVias
|
2021-02-08 10:40:32 +00:00
|
|
|
|| csTemplate.Pouring.ThermalReliefPadsAngle
|
|
|
|
!= csTemplate.Pouring.ThermalReliefViasAngle )
|
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The CADSTAR template '%s' has different settings for thermal relief "
|
|
|
|
"in pads and vias. KiCad only supports one single setting for both. The "
|
|
|
|
"setting for pads has been applied." ),
|
|
|
|
csTemplate.Name ) );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
COPPERCODE reliefCopperCode = getCopperCode( csTemplate.Pouring.ReliefCopperCodeID );
|
|
|
|
int spokeWidth = getKiCadLength( reliefCopperCode.CopperWidth );
|
|
|
|
int reliefWidth = getKiCadLength( csTemplate.Pouring.ClearanceWidth );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
// Cadstar supports having a spoke width thinner than the minimum thickness of the zone, but
|
|
|
|
// this is not permitted in KiCad. We load it as solid fill instead.
|
2021-10-08 16:32:58 +00:00
|
|
|
if( csTemplate.Pouring.ThermalReliefOnPads && reliefWidth > 0 )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-10-08 16:32:58 +00:00
|
|
|
if( spokeWidth < minThickness )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The CADSTAR template '%s' has thermal reliefs in the original design "
|
|
|
|
"but the spoke width (%.2f mm) is thinner than the minimum thickness of "
|
|
|
|
"the zone (%.2f mm). KiCad requires the minimum thickness of the zone "
|
|
|
|
"to be preserved. Therefore the minimum thickness has been applied as "
|
|
|
|
"the new spoke width and will be applied next time the zones are "
|
|
|
|
"filled." ),
|
|
|
|
csTemplate.Name, (double) getKiCadLength( spokeWidth ) / 1E6,
|
|
|
|
(double) getKiCadLength( minThickness ) / 1E6 ) );
|
|
|
|
|
|
|
|
spokeWidth = minThickness;
|
|
|
|
}
|
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
zone->SetThermalReliefGap( reliefWidth );
|
|
|
|
zone->SetThermalReliefSpokeWidth( spokeWidth );
|
2020-08-31 22:09:29 +00:00
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::THERMAL );
|
|
|
|
}
|
|
|
|
else
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::FULL );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_zonesMap.insert( { csTemplate.ID, zone } );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Now create power plane layers:
|
2021-02-13 20:00:17 +00:00
|
|
|
for( LAYER_ID layer : m_powerPlaneLayers )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
wxASSERT(
|
|
|
|
Assignments.Layerdefs.Layers.find( layer ) != Assignments.Layerdefs.Layers.end() );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
//The net name will equal the layer name
|
2020-09-14 08:02:07 +00:00
|
|
|
wxString powerPlaneLayerName = Assignments.Layerdefs.Layers.at( layer ).Name;
|
2020-09-10 20:58:20 +00:00
|
|
|
NET_ID netid = wxEmptyString;
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
for( std::pair<NET_ID, NET_PCB> netPair : Layout.Nets )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
NET_PCB net = netPair.second;
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
if( net.Name == powerPlaneLayerName )
|
|
|
|
{
|
|
|
|
netid = net.ID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( netid.IsEmpty() )
|
|
|
|
{
|
2021-06-26 19:21:30 +00:00
|
|
|
wxLogError( _( "The CADSTAR layer '%s' is defined as a power plane layer. However no "
|
|
|
|
"net with such name exists. The layer has been loaded but no copper "
|
|
|
|
"zone was created." ),
|
|
|
|
powerPlaneLayerName );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<BOARD_ID, CADSTAR_BOARD> boardPair : Layout.Boards )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
//create a zone in each board shape
|
2021-02-13 20:00:17 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
CADSTAR_BOARD& board = boardPair.second;
|
2020-11-11 23:05:59 +00:00
|
|
|
int defaultLineThicknesss = bds.GetLineThickness( PCB_LAYER_ID::Edge_Cuts );
|
2021-02-13 20:00:17 +00:00
|
|
|
ZONE* zone = getZoneFromCadstarShape( board.Shape, defaultLineThicknesss, m_board );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
zone->SetZoneName( powerPlaneLayerName );
|
|
|
|
zone->SetLayer( getKiCadLayer( layer ) );
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
|
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::FULL );
|
|
|
|
zone->SetMinIslandArea( -1 );
|
2022-03-01 14:53:35 +00:00
|
|
|
zone->SetAssignedPriority( 0 ); // Priority always 0 (lowest priority) for implied power planes.
|
2020-08-31 22:09:29 +00:00
|
|
|
zone->SetNet( getKiCadNet( netid ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadCoppers()
|
|
|
|
{
|
|
|
|
for( std::pair<COPPER_ID, COPPER> copPair : Layout.Coppers )
|
|
|
|
{
|
|
|
|
COPPER& csCopper = copPair.second;
|
|
|
|
|
2021-09-09 21:15:38 +00:00
|
|
|
checkPoint();
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
if( !csCopper.PouredTemplateID.IsEmpty() )
|
2021-02-06 19:36:51 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
ZONE* pouredZone = m_zonesMap.at( csCopper.PouredTemplateID );
|
2022-02-16 15:33:12 +00:00
|
|
|
SHAPE_POLY_SET fill;
|
2021-02-06 19:36:51 +00:00
|
|
|
|
|
|
|
int copperWidth = getKiCadLength( getCopperCode( csCopper.CopperCodeID ).CopperWidth );
|
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
if( csCopper.Shape.Type == SHAPE_TYPE::OPENSHAPE )
|
|
|
|
{
|
|
|
|
// This is usually for themal reliefs. They are lines of copper with a thickness.
|
|
|
|
// We convert them to an oval in most cases, but handle also the possibility of
|
|
|
|
// encountering arcs in here.
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_SHAPE*> outlineShapes = getShapesFromVertices( csCopper.Shape.Vertices );
|
2021-02-08 10:40:32 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
for( PCB_SHAPE* shape : outlineShapes )
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
2021-02-08 10:40:32 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
if( shape->GetShape() == SHAPE_T::ARC )
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
2021-07-17 18:52:13 +00:00
|
|
|
TransformArcToPolygon( poly, shape->GetStart(), shape->GetArcMid(),
|
|
|
|
shape->GetEnd(), copperWidth, ARC_HIGH_DEF,
|
2021-02-08 10:40:32 +00:00
|
|
|
ERROR_LOC::ERROR_INSIDE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
TransformOvalToPolygon( poly, shape->GetStart(), shape->GetEnd(),
|
|
|
|
copperWidth, ARC_HIGH_DEF,
|
|
|
|
ERROR_LOC::ERROR_INSIDE );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:09:06 +00:00
|
|
|
poly.ClearArcs();
|
2022-02-16 15:33:12 +00:00
|
|
|
fill.BooleanAdd( poly, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-02-06 19:36:51 +00:00
|
|
|
else
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
2022-02-16 15:33:12 +00:00
|
|
|
fill = getPolySetFromCadstarShape( csCopper.Shape, -1 );
|
|
|
|
fill.ClearArcs();
|
|
|
|
fill.Inflate( copperWidth / 2, 32 );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
|
|
|
|
2021-02-06 19:36:51 +00:00
|
|
|
if( pouredZone->HasFilledPolysForLayer( getKiCadLayer( csCopper.LayerID ) ) )
|
2021-02-08 10:40:32 +00:00
|
|
|
{
|
2022-02-16 15:33:12 +00:00
|
|
|
fill.BooleanAdd( *pouredZone->GetFill( getKiCadLayer( csCopper.LayerID ) ),
|
|
|
|
SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2022-02-16 15:33:12 +00:00
|
|
|
fill.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2022-02-16 15:33:12 +00:00
|
|
|
pouredZone->SetFilledPolysList( getKiCadLayer( csCopper.LayerID ), fill );
|
2021-02-06 19:36:51 +00:00
|
|
|
pouredZone->SetIsFilled( true );
|
|
|
|
pouredZone->SetNeedRefill( false );
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
// For now we are going to load coppers to a KiCad zone however this isn't perfect
|
|
|
|
//TODO: Load onto a graphical polygon with a net (when KiCad has this feature)
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
if( !m_doneCopperWarning )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
wxLogWarning(
|
|
|
|
_( "The CADSTAR design contains COPPER elements, which have no direct KiCad "
|
|
|
|
"equivalent. These have been imported as a KiCad Zone if solid or hatch "
|
|
|
|
"filled, or as a KiCad Track if the shape was an unfilled outline (open or "
|
|
|
|
"closed)." ) );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_doneCopperWarning = true;
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( csCopper.Shape.Type == SHAPE_TYPE::OPENSHAPE
|
2021-10-08 17:09:06 +00:00
|
|
|
|| csCopper.Shape.Type == SHAPE_TYPE::OUTLINE )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_SHAPE*> outlineShapes = getShapesFromVertices( csCopper.Shape.Vertices );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_TRACK*> outlineTracks = makeTracksFromShapes( outlineShapes, m_board,
|
|
|
|
getKiCadNet( csCopper.NetRef.NetID ),
|
|
|
|
getKiCadLayer( csCopper.LayerID ),
|
|
|
|
getKiCadLength( getCopperCode( csCopper.CopperCodeID ).CopperWidth ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
//cleanup
|
2021-07-18 12:31:56 +00:00
|
|
|
for( PCB_SHAPE* shape : outlineShapes )
|
|
|
|
delete shape;
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
for( CUTOUT cutout : csCopper.Shape.Cutouts )
|
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_SHAPE*> cutoutShapes = getShapesFromVertices( cutout.Vertices );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_TRACK*> cutoutTracks = makeTracksFromShapes( cutoutShapes, m_board,
|
|
|
|
getKiCadNet( csCopper.NetRef.NetID ),
|
|
|
|
getKiCadLayer( csCopper.LayerID ),
|
|
|
|
getKiCadLength( getCopperCode( csCopper.CopperCodeID ).CopperWidth ));
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
//cleanup
|
2021-07-18 12:31:56 +00:00
|
|
|
for( PCB_SHAPE* shape : cutoutShapes )
|
|
|
|
delete shape;
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = getZoneFromCadstarShape( csCopper.Shape,
|
|
|
|
getKiCadLength( getCopperCode( csCopper.CopperCodeID ).CopperWidth ),
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
zone->SetZoneName( csCopper.ID );
|
|
|
|
zone->SetLayer( getKiCadLayer( csCopper.LayerID ) );
|
2021-02-08 10:40:32 +00:00
|
|
|
zone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
if( csCopper.Shape.Type == SHAPE_TYPE::HATCHED )
|
|
|
|
{
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
|
|
|
|
zone->SetHatchGap( getKiCadHatchCodeGap( csCopper.Shape.HatchCodeID ) );
|
|
|
|
zone->SetHatchThickness( getKiCadHatchCodeThickness( csCopper.Shape.HatchCodeID ) );
|
2022-01-19 00:22:40 +00:00
|
|
|
zone->SetHatchOrientation( getHatchCodeAngle( csCopper.Shape.HatchCodeID ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
|
|
|
|
}
|
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
zone->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::NEVER );
|
2020-08-31 22:09:29 +00:00
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::FULL );
|
|
|
|
zone->SetNet( getKiCadNet( csCopper.NetRef.NetID ) );
|
2022-03-01 14:53:35 +00:00
|
|
|
zone->SetAssignedPriority( m_zonesMap.size() + 1 ); // Highest priority (always fill first)
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2022-02-16 15:33:12 +00:00
|
|
|
SHAPE_POLY_SET fill( *zone->Outline() );
|
|
|
|
fill.Fracture( SHAPE_POLY_SET::POLYGON_MODE::PM_STRICTLY_SIMPLE );
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2022-02-16 15:33:12 +00:00
|
|
|
zone->SetFilledPolysList( getKiCadLayer( csCopper.LayerID ), fill );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadNets()
|
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
for( std::pair<NET_ID, NET_PCB> netPair : Layout.Nets )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
NET_PCB net = netPair.second;
|
2020-09-05 15:31:57 +00:00
|
|
|
wxString netnameForErrorReporting = net.Name;
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2021-03-25 11:28:22 +00:00
|
|
|
std::map<NETELEMENT_ID, long> netelementSizes;
|
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
if( netnameForErrorReporting.IsEmpty() )
|
2022-02-05 02:06:25 +00:00
|
|
|
netnameForErrorReporting = wxString::Format( wxT( "$%ld" ), net.SignalNum );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
for( std::pair<NETELEMENT_ID, NET_PCB::VIA> viaPair : net.Vias )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
NET_PCB::VIA via = viaPair.second;
|
2021-03-25 11:28:22 +00:00
|
|
|
|
|
|
|
// viasize is used for calculating route offset (as done in CADSTAR post processor)
|
|
|
|
int viaSize = loadNetVia( net.ID, via );
|
|
|
|
netelementSizes.insert( { viaPair.first, viaSize } );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
for( std::pair<NETELEMENT_ID, NET_PCB::PIN> pinPair : net.Pins )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
NET_PCB::PIN pin = pinPair.second;
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = getFootprintFromCadstarID( pin.ComponentID );
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( footprint == nullptr )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The net '%s' references component ID '%s' which does not exist. "
|
2020-11-02 19:23:01 +00:00
|
|
|
"This has been ignored." ),
|
2020-09-05 15:31:57 +00:00
|
|
|
netnameForErrorReporting, pin.ComponentID ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
2020-11-13 15:15:52 +00:00
|
|
|
else if( ( pin.PadID - (long) 1 ) > footprint->Pads().size() )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxLogWarning( wxString::Format( _( "The net '%s' references non-existent pad index"
|
2021-07-26 19:35:12 +00:00
|
|
|
" '%d' in component '%s'. This has been "
|
|
|
|
"ignored." ),
|
2020-11-13 15:15:52 +00:00
|
|
|
netnameForErrorReporting,
|
|
|
|
pin.PadID,
|
|
|
|
footprint->GetReference() ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
// The below works because we have added the pads in the correct order to the
|
|
|
|
// footprint and the PAD_ID in Cadstar is a sequential, numerical ID
|
2021-04-10 18:14:43 +00:00
|
|
|
PAD* pad = getPadReference( footprint, pin.PadID );
|
2021-03-25 11:28:22 +00:00
|
|
|
pad->SetNet( getKiCadNet( net.ID ) );
|
|
|
|
|
2021-04-10 18:14:43 +00:00
|
|
|
// also set the net to any copper pads (i.e. copper elements that we have imported
|
|
|
|
// as pads instead:
|
|
|
|
SYMDEF_ID symdefid = Layout.Components.at( pin.ComponentID ).SymdefID;
|
|
|
|
|
|
|
|
if( m_librarycopperpads.find( symdefid ) != m_librarycopperpads.end() )
|
|
|
|
{
|
|
|
|
ASSOCIATED_COPPER_PADS assocPads = m_librarycopperpads.at( symdefid );
|
|
|
|
|
|
|
|
if( assocPads.find( pin.PadID ) != assocPads.end() )
|
|
|
|
{
|
|
|
|
for( PAD_ID copperPadID : assocPads.at( pin.PadID ) )
|
|
|
|
{
|
|
|
|
PAD* copperpad = getPadReference( footprint, copperPadID );
|
|
|
|
copperpad->SetNet( getKiCadNet( net.ID ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-25 11:28:22 +00:00
|
|
|
// padsize is used for calculating route offset (as done in CADSTAR post processor)
|
|
|
|
int padsize = std::min( pad->GetSizeX(), pad->GetSizeY() );
|
|
|
|
netelementSizes.insert( { pinPair.first, padsize } );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-25 11:28:22 +00:00
|
|
|
|
|
|
|
// For junction points we need to find out the biggest size of the other routes connecting
|
|
|
|
// at the junction in order to correctly apply the same "route offset" operation that the
|
2021-10-08 19:07:21 +00:00
|
|
|
// CADSTAR post processor applies when generating Manufacturing output. The only exception
|
|
|
|
// is if there is just a single route at the junction point, we use that route width
|
2021-03-25 11:28:22 +00:00
|
|
|
auto getJunctionSize =
|
2021-04-23 16:50:41 +00:00
|
|
|
[&]( NETELEMENT_ID aJptNetElemId, const NET_PCB::CONNECTION_PCB& aConnectionToIgnore ) -> int
|
2021-03-25 11:28:22 +00:00
|
|
|
{
|
|
|
|
int jptsize = 0;
|
|
|
|
|
|
|
|
for( NET_PCB::CONNECTION_PCB connection : net.Connections )
|
|
|
|
{
|
|
|
|
if( connection.Route.RouteVertices.size() == 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( connection.StartNode == aConnectionToIgnore.StartNode
|
|
|
|
&& connection.EndNode == aConnectionToIgnore.EndNode )
|
2021-10-08 19:07:21 +00:00
|
|
|
{
|
2021-03-25 11:28:22 +00:00
|
|
|
continue;
|
2021-10-08 19:07:21 +00:00
|
|
|
}
|
2021-03-25 11:28:22 +00:00
|
|
|
|
|
|
|
if( connection.StartNode == aJptNetElemId )
|
|
|
|
{
|
|
|
|
int s = getKiCadLength( connection.Route.RouteVertices.front().RouteWidth );
|
|
|
|
jptsize = std::max( jptsize, s );
|
|
|
|
}
|
|
|
|
else if( connection.EndNode == aJptNetElemId )
|
|
|
|
{
|
|
|
|
int s = getKiCadLength( connection.Route.RouteVertices.back().RouteWidth );
|
|
|
|
jptsize = std::max( jptsize, s );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-08 19:07:21 +00:00
|
|
|
if( jptsize == 0 )
|
|
|
|
{
|
|
|
|
// aConnectionToIgnore is actually the only one that has a route, so lets use that
|
|
|
|
// to determine junction size
|
|
|
|
NET_PCB::ROUTE_VERTEX vertex = aConnectionToIgnore.Route.RouteVertices.front();
|
|
|
|
|
|
|
|
if( aConnectionToIgnore.EndNode == aJptNetElemId )
|
|
|
|
vertex = aConnectionToIgnore.Route.RouteVertices.back();
|
|
|
|
|
|
|
|
jptsize = getKiCadLength( vertex.RouteWidth );
|
|
|
|
}
|
|
|
|
|
2021-03-25 11:28:22 +00:00
|
|
|
return jptsize;
|
|
|
|
};
|
|
|
|
|
|
|
|
for( NET_PCB::CONNECTION_PCB connection : net.Connections )
|
|
|
|
{
|
|
|
|
int startSize = std::numeric_limits<int>::max();
|
|
|
|
int endSize = std::numeric_limits<int>::max();
|
|
|
|
|
|
|
|
if( netelementSizes.find( connection.StartNode ) != netelementSizes.end() )
|
|
|
|
startSize = netelementSizes.at( connection.StartNode );
|
|
|
|
else if( net.Junctions.find( connection.StartNode ) != net.Junctions.end() )
|
|
|
|
startSize = getJunctionSize( connection.StartNode, connection );
|
|
|
|
|
|
|
|
if( netelementSizes.find( connection.EndNode ) != netelementSizes.end() )
|
|
|
|
endSize = netelementSizes.at( connection.EndNode );
|
|
|
|
else if( net.Junctions.find( connection.EndNode ) != net.Junctions.end() )
|
|
|
|
endSize = getJunctionSize( connection.EndNode, connection );
|
|
|
|
|
|
|
|
startSize /= KiCadUnitMultiplier;
|
|
|
|
endSize /= KiCadUnitMultiplier;
|
|
|
|
|
|
|
|
if( !connection.Unrouted )
|
|
|
|
loadNetTracks( net.ID, connection.Route, startSize, endSize );
|
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-13 15:40:03 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadTextVariables()
|
|
|
|
{
|
2021-01-31 20:47:36 +00:00
|
|
|
auto findAndReplaceTextField =
|
|
|
|
[&]( TEXT_FIELD_NAME aField, wxString aValue )
|
2020-12-13 15:40:03 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_context.TextFieldToValuesMap.find( aField ) !=
|
|
|
|
m_context.TextFieldToValuesMap.end() )
|
2020-12-13 15:40:03 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_context.TextFieldToValuesMap.at( aField ) != aValue )
|
2020-12-13 15:40:03 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
m_context.TextFieldToValuesMap.at( aField ) = aValue;
|
|
|
|
m_context.InconsistentTextFields.insert( aField );
|
2020-12-13 15:40:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
m_context.TextFieldToValuesMap.insert( { aField, aValue } );
|
2020-12-13 15:40:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_project )
|
2020-12-13 15:40:03 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
std::map<wxString, wxString>& txtVars = m_project->GetTextVars();
|
2020-12-13 15:40:03 +00:00
|
|
|
|
|
|
|
// Most of the design text fields can be derived from other elements
|
|
|
|
if( Layout.VariantHierarchy.Variants.size() > 0 )
|
|
|
|
{
|
|
|
|
VARIANT loadedVar = Layout.VariantHierarchy.Variants.begin()->second;
|
|
|
|
|
|
|
|
findAndReplaceTextField( TEXT_FIELD_NAME::VARIANT_NAME, loadedVar.Name );
|
|
|
|
findAndReplaceTextField( TEXT_FIELD_NAME::VARIANT_DESCRIPTION, loadedVar.Description );
|
|
|
|
}
|
|
|
|
|
|
|
|
findAndReplaceTextField( TEXT_FIELD_NAME::DESIGN_TITLE, Header.JobTitle );
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<TEXT_FIELD_NAME, wxString> txtvalue : m_context.TextFieldToValuesMap )
|
2020-12-13 15:40:03 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
wxString varName = CADSTAR_TO_KICAD_FIELDS.at( txtvalue.first );
|
2020-12-13 15:40:03 +00:00
|
|
|
wxString varValue = txtvalue.second;
|
|
|
|
|
|
|
|
txtVars.insert( { varName, varValue } );
|
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<wxString, wxString> txtvalue : m_context.FilenamesToTextMap )
|
2020-12-13 15:40:03 +00:00
|
|
|
{
|
|
|
|
wxString varName = txtvalue.first;
|
|
|
|
wxString varValue = txtvalue.second;
|
|
|
|
|
|
|
|
txtVars.insert( { varName, varValue } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-13 17:28:47 +00:00
|
|
|
wxLogError( _( "Text Variables could not be set as there is no project loaded." ) );
|
2020-12-13 15:40:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadComponentAttributes( const COMPONENT& aComponent,
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* aFootprint )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
for( std::pair<ATTRIBUTE_ID, ATTRIBUTE_VALUE> attrPair : aComponent.AttributeValues )
|
|
|
|
{
|
|
|
|
ATTRIBUTE_VALUE& attrval = attrPair.second;
|
|
|
|
|
|
|
|
if( attrval.HasLocation ) //only import attributes with location. Ignore the rest
|
2020-11-13 01:12:36 +00:00
|
|
|
{
|
|
|
|
addAttribute( attrval.AttributeLocation, attrval.AttributeID, aFootprint,
|
|
|
|
attrval.Value );
|
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( std::pair<ATTRIBUTE_ID, TEXT_LOCATION> textlocPair : aComponent.TextLocations )
|
|
|
|
{
|
|
|
|
TEXT_LOCATION& textloc = textlocPair.second;
|
|
|
|
wxString attrval;
|
|
|
|
|
|
|
|
if( textloc.AttributeID == COMPONENT_NAME_ATTRID )
|
|
|
|
{
|
|
|
|
attrval = wxEmptyString; // Designator is loaded separately
|
|
|
|
}
|
|
|
|
else if( textloc.AttributeID == COMPONENT_NAME_2_ATTRID )
|
|
|
|
{
|
|
|
|
attrval = wxT( "${REFERENCE}" );
|
|
|
|
}
|
|
|
|
else if( textloc.AttributeID == PART_NAME_ATTRID )
|
|
|
|
{
|
|
|
|
attrval = getPart( aComponent.PartID ).Name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
attrval = getAttributeValue( textloc.AttributeID, aComponent.AttributeValues );
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
addAttribute( textloc, textloc.AttributeID, aFootprint, attrval );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-25 11:28:22 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadNetTracks( const NET_ID& aCadstarNetID,
|
|
|
|
const NET_PCB::ROUTE& aCadstarRoute,
|
|
|
|
long aStartWidth, long aEndWidth )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-04-06 20:55:21 +00:00
|
|
|
if( aCadstarRoute.RouteVertices.size() == 0 )
|
|
|
|
return;
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-04-06 20:55:21 +00:00
|
|
|
std::vector<PCB_SHAPE*> shapes;
|
|
|
|
std::vector<NET_PCB::ROUTE_VERTEX> routeVertices = aCadstarRoute.RouteVertices;
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Add thin route at front so that route offsetting works as expected
|
2021-04-06 20:55:21 +00:00
|
|
|
if( aStartWidth < routeVertices.front().RouteWidth )
|
2021-03-25 11:28:22 +00:00
|
|
|
{
|
2021-04-06 20:55:21 +00:00
|
|
|
NET_PCB::ROUTE_VERTEX newFrontVertex = aCadstarRoute.RouteVertices.front();
|
|
|
|
newFrontVertex.RouteWidth = aStartWidth;
|
|
|
|
newFrontVertex.Vertex.End = aCadstarRoute.StartPoint;
|
|
|
|
routeVertices.insert( routeVertices.begin(), newFrontVertex );
|
|
|
|
}
|
2021-03-25 11:28:22 +00:00
|
|
|
|
2021-04-06 20:55:21 +00:00
|
|
|
// Add thin route at the back if required
|
|
|
|
if( aEndWidth < routeVertices.back().RouteWidth )
|
|
|
|
{
|
|
|
|
NET_PCB::ROUTE_VERTEX newBackVertex = aCadstarRoute.RouteVertices.back();
|
|
|
|
newBackVertex.RouteWidth = aEndWidth;
|
|
|
|
routeVertices.push_back( newBackVertex );
|
2021-03-25 11:28:22 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 20:55:21 +00:00
|
|
|
POINT prevEnd = aCadstarRoute.StartPoint;
|
2021-03-25 11:28:22 +00:00
|
|
|
|
2021-04-06 20:55:21 +00:00
|
|
|
for( const NET_PCB::ROUTE_VERTEX& v : routeVertices )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
PCB_SHAPE* shape = getShapeFromVertex( prevEnd, v.Vertex );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( getKiCadLayer( aCadstarRoute.LayerID ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( getKiCadLength( v.RouteWidth ), PLOT_DASH_TYPE::SOLID ) );
|
2021-03-25 11:28:22 +00:00
|
|
|
shape->SetLocked( v.Fixed );
|
2020-10-04 23:34:59 +00:00
|
|
|
shapes.push_back( shape );
|
2020-08-31 22:09:29 +00:00
|
|
|
prevEnd = v.Vertex.End;
|
2022-09-03 20:03:23 +00:00
|
|
|
|
|
|
|
if( !m_doneTearDropWarning && ( v.TeardropAtEnd || v.TeardropAtStart ) )
|
|
|
|
{
|
|
|
|
// TODO: load teardrops
|
|
|
|
wxLogError( _( "The CADSTAR design contains teardrops. This importer does not yet "
|
|
|
|
"support them, so the teardrops in the design have been ignored." ) );
|
|
|
|
|
|
|
|
m_doneTearDropWarning = true;
|
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
NETINFO_ITEM* net = getKiCadNet( aCadstarNetID );
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_TRACK*> tracks = makeTracksFromShapes( shapes, m_board, net );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
//cleanup
|
2020-10-04 23:34:59 +00:00
|
|
|
for( PCB_SHAPE* shape : shapes )
|
|
|
|
delete shape;
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-25 11:28:22 +00:00
|
|
|
int CADSTAR_PCB_ARCHIVE_LOADER::loadNetVia(
|
2020-09-10 20:58:20 +00:00
|
|
|
const NET_ID& aCadstarNetID, const NET_PCB::VIA& aCadstarVia )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_VIA* via = new PCB_VIA( m_board );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( via, ADD_MODE::APPEND );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
VIACODE csViaCode = getViaCode( aCadstarVia.ViaCodeID );
|
|
|
|
LAYERPAIR csLayerPair = getLayerPair( aCadstarVia.LayerPairID );
|
|
|
|
|
|
|
|
via->SetPosition( getKiCadPoint( aCadstarVia.Location ) );
|
|
|
|
via->SetDrill( getKiCadLength( csViaCode.DrillDiameter ) );
|
|
|
|
via->SetLocked( aCadstarVia.Fixed );
|
|
|
|
|
|
|
|
if( csViaCode.Shape.ShapeType != PAD_SHAPE_TYPE::CIRCLE )
|
2021-06-26 19:21:30 +00:00
|
|
|
{
|
|
|
|
wxLogError( _( "The CADSTAR via code '%s' has different shape from a circle defined. "
|
|
|
|
"KiCad only supports circular vias so this via type has been changed to "
|
|
|
|
"be a via with circular shape of %.2f mm diameter." ),
|
|
|
|
csViaCode.Name,
|
|
|
|
(double) ( (double) getKiCadLength( csViaCode.Shape.Size ) / 1E6 ) );
|
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
via->SetWidth( getKiCadLength( csViaCode.Shape.Size ) );
|
|
|
|
|
|
|
|
bool start_layer_outside =
|
|
|
|
csLayerPair.PhysicalLayerStart == 1
|
|
|
|
|| csLayerPair.PhysicalLayerStart == Assignments.Technology.MaxPhysicalLayer;
|
|
|
|
bool end_layer_outside =
|
|
|
|
csLayerPair.PhysicalLayerEnd == 1
|
|
|
|
|| csLayerPair.PhysicalLayerEnd == Assignments.Technology.MaxPhysicalLayer;
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
via->SetLayerPair( getKiCadCopperLayerID( csLayerPair.PhysicalLayerStart ),
|
|
|
|
getKiCadCopperLayerID( csLayerPair.PhysicalLayerEnd ) );
|
|
|
|
via->SetNet( getKiCadNet( aCadstarNetID ) );
|
|
|
|
///todo add netcode to the via
|
2021-03-25 11:28:22 +00:00
|
|
|
|
|
|
|
return via->GetWidth();
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText(
|
|
|
|
const TEXT& aCadstarText, BOARD_ITEM_CONTAINER* aContainer, const GROUP_ID& aCadstarGroupID,
|
|
|
|
const LAYER_ID& aCadstarLayerOverride, const VECTOR2I& aMoveVector,
|
|
|
|
const double& aRotationAngle, const double& aScalingFactor,
|
|
|
|
const VECTOR2I& aTransformCentre, const bool& aMirrorInvert )
|
2020-09-05 15:31:57 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_TEXT* txt = new PCB_TEXT( aContainer );
|
2020-09-05 15:31:57 +00:00
|
|
|
aContainer->Add( txt );
|
|
|
|
txt->SetText( aCadstarText.Text );
|
|
|
|
|
2022-01-13 23:30:52 +00:00
|
|
|
EDA_ANGLE rotationAngle( aRotationAngle, TENTHS_OF_A_DEGREE_T );
|
|
|
|
VECTOR2I rotatedTextPos = getKiCadPoint( aCadstarText.Position );
|
|
|
|
RotatePoint( rotatedTextPos, aTransformCentre, rotationAngle );
|
2020-09-06 21:20:32 +00:00
|
|
|
rotatedTextPos.x =
|
|
|
|
KiROUND( (double) ( rotatedTextPos.x - aTransformCentre.x ) * aScalingFactor );
|
|
|
|
rotatedTextPos.y =
|
|
|
|
KiROUND( (double) ( rotatedTextPos.y - aTransformCentre.y ) * aScalingFactor );
|
2020-09-05 15:31:57 +00:00
|
|
|
rotatedTextPos += aTransformCentre;
|
|
|
|
txt->SetTextPos( rotatedTextPos );
|
|
|
|
txt->SetPosition( rotatedTextPos );
|
|
|
|
|
2022-01-13 23:30:52 +00:00
|
|
|
txt->SetTextAngle( getAngle( aCadstarText.OrientAngle ) + rotationAngle );
|
2020-10-18 17:26:31 +00:00
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
txt->SetMirrored( aCadstarText.Mirror );
|
2020-09-05 15:31:57 +00:00
|
|
|
|
2023-01-29 16:02:43 +00:00
|
|
|
applyTextCode( txt, aCadstarText.TextCodeID );
|
2020-09-05 15:31:57 +00:00
|
|
|
|
|
|
|
switch( aCadstarText.Alignment )
|
|
|
|
{
|
|
|
|
case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
|
|
|
|
case ALIGNMENT::BOTTOMLEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-09-05 15:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMCENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2020-09-05 15:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMRIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-09-05 15:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERLEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-09-05 15:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERCENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2020-09-05 15:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERRIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-09-05 15:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPLEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-09-05 15:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPCENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2020-09-05 15:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPRIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-09-05 15:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unknown Alignment - needs review!" ) );
|
2020-09-05 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aMirrorInvert )
|
|
|
|
{
|
|
|
|
txt->Flip( aTransformCentre, true );
|
|
|
|
}
|
2020-09-06 21:20:32 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
//scale it after flipping:
|
|
|
|
if( aScalingFactor != 1.0 )
|
|
|
|
{
|
2023-01-29 16:02:43 +00:00
|
|
|
VECTOR2I unscaledTextSize = txt->GetTextSize();
|
|
|
|
int unscaledThickness = txt->GetTextThickness();
|
|
|
|
|
|
|
|
VECTOR2I scaledTextSize;
|
2021-02-04 18:57:09 +00:00
|
|
|
scaledTextSize.x = KiROUND( (double) unscaledTextSize.x * aScalingFactor );
|
|
|
|
scaledTextSize.y = KiROUND( (double) unscaledTextSize.y * aScalingFactor );
|
2023-01-29 16:02:43 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
txt->SetTextSize( scaledTextSize );
|
2023-01-29 16:02:43 +00:00
|
|
|
txt->SetTextThickness( KiROUND( (double) unscaledThickness * aScalingFactor ) );
|
2020-09-05 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
txt->Move( aMoveVector );
|
|
|
|
|
2020-12-30 02:04:19 +00:00
|
|
|
if( aCadstarText.Alignment == ALIGNMENT::NO_ALIGNMENT )
|
|
|
|
FixTextPositionNoAlignment( txt );
|
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
LAYER_ID layersToDrawOn = aCadstarLayerOverride;
|
|
|
|
|
|
|
|
if( layersToDrawOn.IsEmpty() )
|
|
|
|
layersToDrawOn = aCadstarText.LayerID;
|
|
|
|
|
|
|
|
if( isLayerSet( layersToDrawOn ) )
|
|
|
|
{
|
|
|
|
//Make a copy on each layer
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
LSEQ layers = getKiCadLayerSet( layersToDrawOn ).Seq();
|
|
|
|
PCB_TEXT* newtxt;
|
2020-09-05 15:31:57 +00:00
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : layers )
|
|
|
|
{
|
|
|
|
txt->SetLayer( layer );
|
2020-11-23 20:34:57 +00:00
|
|
|
newtxt = static_cast<PCB_TEXT*>( txt->Duplicate() );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Add( newtxt, ADD_MODE::APPEND );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
|
|
|
if( !aCadstarGroupID.IsEmpty() )
|
|
|
|
addToGroup( aCadstarGroupID, newtxt );
|
2020-09-05 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->Remove( txt );
|
2020-09-05 15:31:57 +00:00
|
|
|
delete txt;
|
|
|
|
}
|
|
|
|
else
|
2020-09-06 21:20:32 +00:00
|
|
|
{
|
2020-09-05 15:31:57 +00:00
|
|
|
txt->SetLayer( getKiCadLayer( layersToDrawOn ) );
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
if( !aCadstarGroupID.IsEmpty() )
|
|
|
|
addToGroup( aCadstarGroupID, txt );
|
|
|
|
}
|
2020-09-05 15:31:57 +00:00
|
|
|
//TODO Handle different font types when KiCad can support it.
|
|
|
|
}
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarShape( const SHAPE& aCadstarShape,
|
2020-11-13 15:15:52 +00:00
|
|
|
const PCB_LAYER_ID& aKiCadLayer,
|
|
|
|
const int& aLineThickness,
|
|
|
|
const wxString& aShapeName,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aMoveVector,
|
2020-11-13 15:15:52 +00:00
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aTransformCentre,
|
2020-11-13 15:15:52 +00:00
|
|
|
const bool& aMirrorInvert )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2022-09-03 21:39:49 +00:00
|
|
|
auto drawAsOutline = [&]()
|
|
|
|
{
|
|
|
|
drawCadstarVerticesAsShapes( aCadstarShape.Vertices, aKiCadLayer, aLineThickness,
|
|
|
|
aContainer, aCadstarGroupID, aMoveVector, aRotationAngle,
|
|
|
|
aScalingFactor, aTransformCentre, aMirrorInvert );
|
|
|
|
drawCadstarCutoutsAsShapes( aCadstarShape.Cutouts, aKiCadLayer, aLineThickness, aContainer,
|
|
|
|
aCadstarGroupID, aMoveVector, aRotationAngle, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert );
|
|
|
|
};
|
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
switch( aCadstarShape.Type )
|
|
|
|
{
|
|
|
|
case SHAPE_TYPE::OPENSHAPE:
|
|
|
|
case SHAPE_TYPE::OUTLINE:
|
2020-08-23 10:34:27 +00:00
|
|
|
///TODO update this when Polygons in KiCad can be defined with no fill
|
2022-09-03 21:39:49 +00:00
|
|
|
drawAsOutline();
|
2020-08-16 17:12:08 +00:00
|
|
|
break;
|
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
case SHAPE_TYPE::HATCHED:
|
|
|
|
///TODO update this when Polygons in KiCad can be defined with hatch fill
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The shape for '%s' is Hatch filled in CADSTAR, which has no KiCad equivalent. "
|
|
|
|
"Using solid fill instead." ),
|
|
|
|
aShapeName ) );
|
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
case SHAPE_TYPE::SOLID:
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2022-09-03 21:39:49 +00:00
|
|
|
// Special case solid shapes that are effectively a single line
|
|
|
|
if( aCadstarShape.Vertices.size() < 3
|
|
|
|
|| ( aCadstarShape.Vertices.size() == 3
|
|
|
|
&& aCadstarShape.Vertices.at( 0 ).End == aCadstarShape.Vertices.at( 2 ).End ) )
|
|
|
|
{
|
|
|
|
drawAsOutline();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( isFootprint( aContainer ) )
|
2021-07-21 18:31:25 +00:00
|
|
|
shape = new FP_SHAPE( (FOOTPRINT*) aContainer, SHAPE_T::POLY );
|
2020-08-28 20:32:53 +00:00
|
|
|
else
|
2021-07-17 18:52:13 +00:00
|
|
|
shape = new PCB_SHAPE( aContainer, SHAPE_T::POLY );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-12-03 00:24:45 +00:00
|
|
|
shape->SetFilled( true );
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
SHAPE_POLY_SET shapePolys = getPolySetFromCadstarShape( aCadstarShape, -1, aContainer,
|
|
|
|
aMoveVector, aRotationAngle,
|
|
|
|
aScalingFactor, aTransformCentre,
|
|
|
|
aMirrorInvert );
|
2021-02-06 19:36:51 +00:00
|
|
|
|
|
|
|
shapePolys.Fracture( SHAPE_POLY_SET::POLYGON_MODE::PM_STRICTLY_SIMPLE );
|
|
|
|
|
|
|
|
shape->SetPolyShape( shapePolys );
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( aLineThickness, PLOT_DASH_TYPE::SOLID ) );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( aKiCadLayer );
|
|
|
|
aContainer->Add( shape, ADD_MODE::APPEND );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
|
|
|
if( !aCadstarGroupID.IsEmpty() )
|
2020-10-04 23:34:59 +00:00
|
|
|
addToGroup( aCadstarGroupID, shape );
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarCutoutsAsShapes( const std::vector<CUTOUT>& aCutouts,
|
|
|
|
const PCB_LAYER_ID& aKiCadLayer,
|
|
|
|
const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aMoveVector,
|
2021-07-18 12:31:56 +00:00
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aTransformCentre,
|
2021-07-18 12:31:56 +00:00
|
|
|
const bool& aMirrorInvert )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
|
|
|
for( CUTOUT cutout : aCutouts )
|
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
drawCadstarVerticesAsShapes( cutout.Vertices, aKiCadLayer, aLineThickness, aContainer,
|
|
|
|
aCadstarGroupID, aMoveVector, aRotationAngle, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert );
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarVerticesAsShapes( const std::vector<VERTEX>& aCadstarVertices,
|
|
|
|
const PCB_LAYER_ID& aKiCadLayer,
|
|
|
|
const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aMoveVector,
|
2021-07-18 12:31:56 +00:00
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aTransformCentre,
|
2021-07-18 12:31:56 +00:00
|
|
|
const bool& aMirrorInvert )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_SHAPE*> shapes = getShapesFromVertices( aCadstarVertices, aContainer,
|
|
|
|
aCadstarGroupID, aMoveVector,
|
|
|
|
aRotationAngle, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
for( PCB_SHAPE* shape : shapes )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( aLineThickness, PLOT_DASH_TYPE::SOLID ) );
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->SetLayer( aKiCadLayer );
|
|
|
|
shape->SetParent( aContainer );
|
|
|
|
aContainer->Add( shape, ADD_MODE::APPEND );
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_SHAPE*> CADSTAR_PCB_ARCHIVE_LOADER::getShapesFromVertices(
|
|
|
|
const std::vector<VERTEX>& aCadstarVertices,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aMoveVector,
|
2021-07-18 12:31:56 +00:00
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aTransformCentre,
|
2021-07-18 12:31:56 +00:00
|
|
|
const bool& aMirrorInvert )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<PCB_SHAPE*> drawSegments;
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
if( aCadstarVertices.size() < 2 )
|
|
|
|
//need at least two points to draw a segment! (unlikely but possible to have only one)
|
|
|
|
return drawSegments;
|
|
|
|
|
|
|
|
const VERTEX* prev = &aCadstarVertices.at( 0 ); // first one should always be a point vertex
|
2020-08-31 22:09:29 +00:00
|
|
|
const VERTEX* cur;
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
for( size_t i = 1; i < aCadstarVertices.size(); i++ )
|
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
cur = &aCadstarVertices.at( i );
|
2021-07-18 12:31:56 +00:00
|
|
|
drawSegments.push_back( getShapeFromVertex( prev->End, *cur, aContainer, aCadstarGroupID,
|
|
|
|
aMoveVector, aRotationAngle, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
prev = cur;
|
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
return drawSegments;
|
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
PCB_SHAPE* CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex( const POINT& aCadstarStartPoint,
|
|
|
|
const VERTEX& aCadstarVertex,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aMoveVector,
|
2021-07-18 12:31:56 +00:00
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aTransformCentre,
|
2021-07-18 12:31:56 +00:00
|
|
|
const bool& aMirrorInvert )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
PCB_SHAPE* shape = nullptr;
|
2020-10-04 23:34:59 +00:00
|
|
|
bool cw = false;
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I startPoint = getKiCadPoint( aCadstarStartPoint );
|
|
|
|
VECTOR2I endPoint = getKiCadPoint( aCadstarVertex.End );
|
|
|
|
VECTOR2I centerPoint;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
if( aCadstarVertex.Type == VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE
|
|
|
|
|| aCadstarVertex.Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE )
|
2021-07-18 12:31:56 +00:00
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
centerPoint = ( startPoint + endPoint ) / 2;
|
2021-07-18 12:31:56 +00:00
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
2021-07-18 12:31:56 +00:00
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
centerPoint = getKiCadPoint( aCadstarVertex.Center );
|
2021-07-18 12:31:56 +00:00
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
switch( aCadstarVertex.Type )
|
|
|
|
{
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
case VERTEX_TYPE::POINT:
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( isFootprint( aContainer ) )
|
2021-07-21 18:31:25 +00:00
|
|
|
shape = new FP_SHAPE( static_cast<FOOTPRINT*>( aContainer ), SHAPE_T::SEGMENT );
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
2021-07-17 18:52:13 +00:00
|
|
|
shape = new PCB_SHAPE( aContainer, SHAPE_T::SEGMENT );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->SetStart( startPoint );
|
|
|
|
shape->SetEnd( endPoint );
|
2020-08-31 22:09:29 +00:00
|
|
|
break;
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
case VERTEX_TYPE::CLOCKWISE_SEMICIRCLE:
|
|
|
|
case VERTEX_TYPE::CLOCKWISE_ARC:
|
|
|
|
cw = true;
|
2020-09-16 10:27:15 +00:00
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
case VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE:
|
|
|
|
case VERTEX_TYPE::ANTICLOCKWISE_ARC:
|
2022-01-14 15:34:41 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
if( isFootprint( aContainer ) )
|
2021-07-21 18:31:25 +00:00
|
|
|
shape = new FP_SHAPE((FOOTPRINT*) aContainer, SHAPE_T::ARC );
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
2021-07-17 18:52:13 +00:00
|
|
|
shape = new PCB_SHAPE( aContainer, SHAPE_T::ARC );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetCenter( centerPoint );
|
|
|
|
shape->SetStart( startPoint );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2022-01-14 15:34:41 +00:00
|
|
|
EDA_ANGLE arcStartAngle( startPoint - centerPoint );
|
|
|
|
EDA_ANGLE arcEndAngle( endPoint - centerPoint );
|
2023-01-29 12:21:45 +00:00
|
|
|
EDA_ANGLE arcAngle = ( arcEndAngle - arcStartAngle ).Normalize();
|
2020-08-31 22:09:29 +00:00
|
|
|
//TODO: detect if we are supposed to draw a circle instead (i.e. two SEMICIRCLEs
|
|
|
|
// with opposite start/end points and same centre point)
|
|
|
|
|
2023-01-29 12:21:45 +00:00
|
|
|
if( !cw )
|
|
|
|
arcAngle.NormalizeNegative(); // anticlockwise arc
|
|
|
|
|
|
|
|
shape->SetArcAngleAndEnd( arcAngle, true );
|
2020-09-16 10:27:15 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
break;
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
2022-01-14 15:34:41 +00:00
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
//Apply transforms
|
|
|
|
if( aMirrorInvert )
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->Flip( aTransformCentre, true );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
if( aScalingFactor != 1.0 )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
shape->Move( -1*aTransformCentre );
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->Scale( aScalingFactor );
|
|
|
|
shape->Move( aTransformCentre );
|
2020-09-05 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aRotationAngle != 0.0 )
|
2022-01-13 19:32:00 +00:00
|
|
|
shape->Rotate( aTransformCentre, EDA_ANGLE( aRotationAngle, TENTHS_OF_A_DEGREE_T ) );
|
2020-09-05 15:31:57 +00:00
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
if( aMoveVector != VECTOR2I{ 0, 0 } )
|
2021-07-18 12:31:56 +00:00
|
|
|
shape->Move( aMoveVector );
|
2020-09-05 15:31:57 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
if( isFootprint( aContainer ) && shape != nullptr )
|
|
|
|
static_cast<FP_SHAPE*>( shape )->SetLocalCoord();
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
if( !aCadstarGroupID.IsEmpty() )
|
2021-07-18 12:31:56 +00:00
|
|
|
addToGroup( aCadstarGroupID, shape );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
return shape;
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* CADSTAR_PCB_ARCHIVE_LOADER::getZoneFromCadstarShape( const SHAPE& aCadstarShape,
|
|
|
|
const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aParentContainer )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
ZONE* zone = new ZONE( aParentContainer, isFootprint( aParentContainer ) );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
if( aCadstarShape.Type == SHAPE_TYPE::HATCHED )
|
|
|
|
{
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
|
|
|
|
zone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL );
|
|
|
|
}
|
|
|
|
else
|
2020-09-16 10:27:15 +00:00
|
|
|
{
|
2020-08-23 10:34:27 +00:00
|
|
|
zone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
|
2020-09-16 10:27:15 +00:00
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
SHAPE_POLY_SET polygon = getPolySetFromCadstarShape( aCadstarShape, aLineThickness );
|
|
|
|
|
|
|
|
zone->AddPolygon( polygon.COutline( 0 ) );
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
for( int i = 0; i < polygon.HoleCount( 0 ); i++ )
|
|
|
|
zone->AddPolygon( polygon.CHole( 0, i ) );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
return zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
SHAPE_POLY_SET CADSTAR_PCB_ARCHIVE_LOADER::getPolySetFromCadstarShape( const SHAPE& aCadstarShape,
|
2020-11-13 15:15:52 +00:00
|
|
|
const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aMoveVector,
|
2020-11-13 15:15:52 +00:00
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aTransformCentre,
|
2020-11-13 15:15:52 +00:00
|
|
|
const bool& aMirrorInvert )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2020-09-06 21:20:32 +00:00
|
|
|
GROUP_ID noGroup = wxEmptyString;
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_SHAPE*> outlineShapes = getShapesFromVertices( aCadstarShape.Vertices,
|
|
|
|
aContainer, noGroup, aMoveVector,
|
|
|
|
aRotationAngle, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
SHAPE_POLY_SET polySet( getLineChainFromShapes( outlineShapes ) );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
//cleanup
|
2021-07-18 12:31:56 +00:00
|
|
|
for( PCB_SHAPE* shape : outlineShapes )
|
|
|
|
delete shape;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
for( CUTOUT cutout : aCadstarShape.Cutouts )
|
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_SHAPE*> cutoutShapes = getShapesFromVertices( cutout.Vertices, aContainer,
|
|
|
|
noGroup, aMoveVector,
|
|
|
|
aRotationAngle, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
polySet.AddHole( getLineChainFromShapes( cutoutShapes ) );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
//cleanup
|
2021-07-18 12:31:56 +00:00
|
|
|
for( PCB_SHAPE* shape : cutoutShapes )
|
|
|
|
delete shape;
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:09:06 +00:00
|
|
|
polySet.ClearArcs();
|
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
if( aLineThickness > 0 )
|
2021-11-05 17:12:13 +00:00
|
|
|
{
|
2021-07-26 19:35:12 +00:00
|
|
|
polySet.Inflate( aLineThickness / 2, 32,
|
|
|
|
SHAPE_POLY_SET::CORNER_STRATEGY::ROUND_ALL_CORNERS );
|
2021-11-05 17:12:13 +00:00
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
for( int i = 0; i < polySet.OutlineCount(); ++i )
|
|
|
|
{
|
|
|
|
wxASSERT( polySet.Outline( i ).PointCount() > 2 );
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
for( int j = 0; j < polySet.HoleCount( i ); ++j )
|
|
|
|
{
|
|
|
|
wxASSERT( polySet.Hole( i, j ).PointCount() > 2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
return polySet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
SHAPE_LINE_CHAIN CADSTAR_PCB_ARCHIVE_LOADER::getLineChainFromShapes( const std::vector<PCB_SHAPE*> aShapes )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN lineChain;
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
for( PCB_SHAPE* shape : aShapes )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
switch( shape->GetShape() )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
if( shape->GetClass() == wxT( "MGRAPHIC" ) )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
FP_SHAPE* fp_shape = (FP_SHAPE*) shape;
|
2022-01-14 15:34:41 +00:00
|
|
|
SHAPE_ARC arc( fp_shape->GetCenter0(), fp_shape->GetStart0(), fp_shape->GetArcAngle() );
|
2021-11-05 17:12:13 +00:00
|
|
|
|
|
|
|
if( shape->EndsSwapped() )
|
|
|
|
arc.Reverse();
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
lineChain.Append( arc );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-14 15:34:41 +00:00
|
|
|
SHAPE_ARC arc( shape->GetCenter(), shape->GetStart(), shape->GetArcAngle() );
|
2021-11-05 17:12:13 +00:00
|
|
|
|
|
|
|
if( shape->EndsSwapped() )
|
|
|
|
arc.Reverse();
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
lineChain.Append( arc );
|
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2021-07-18 12:31:56 +00:00
|
|
|
if( shape->GetClass() == wxT( "MGRAPHIC" ) )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
FP_SHAPE* fp_shape = (FP_SHAPE*) shape;
|
|
|
|
lineChain.Append( fp_shape->GetStart0().x, fp_shape->GetStart0().y );
|
|
|
|
lineChain.Append( fp_shape->GetEnd0().x, fp_shape->GetEnd0().y );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
lineChain.Append( shape->GetStartX(), shape->GetStartY() );
|
|
|
|
lineChain.Append( shape->GetEndX(), shape->GetEndY() );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Drawsegment type is unexpected. Ignored." ) );
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
// Shouldn't have less than 3 points to make a closed shape!
|
2020-09-05 15:31:57 +00:00
|
|
|
wxASSERT( lineChain.PointCount() > 2 );
|
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
// Check if it is closed
|
|
|
|
if( lineChain.GetPoint( 0 ) != lineChain.GetPoint( lineChain.PointCount() - 1 ) )
|
|
|
|
{
|
|
|
|
lineChain.Append( lineChain.GetPoint( 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
lineChain.SetClosed( true );
|
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
return lineChain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
std::vector<PCB_TRACK*> CADSTAR_PCB_ARCHIVE_LOADER::makeTracksFromShapes(
|
|
|
|
const std::vector<PCB_SHAPE*> aShapes,
|
2020-10-04 14:19:33 +00:00
|
|
|
BOARD_ITEM_CONTAINER* aParentContainer,
|
|
|
|
NETINFO_ITEM* aNet, PCB_LAYER_ID aLayerOverride,
|
|
|
|
int aWidthOverride )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
std::vector<PCB_TRACK*> tracks;
|
|
|
|
PCB_TRACK* prevTrack = nullptr;
|
|
|
|
PCB_TRACK* track = nullptr;
|
2021-04-06 20:55:21 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
auto addTrack =
|
|
|
|
[&]( PCB_TRACK* aTrack )
|
|
|
|
{
|
|
|
|
// Ignore zero length tracks in the same way as the CADSTAR postprocessor does
|
|
|
|
// when generating gerbers. Note that CADSTAR reports these as "Route offset
|
|
|
|
// errors" when running a DRC within CADSTAR, so we shouldn't be getting this in
|
|
|
|
// general, however it is used to remove any synthetic points added to
|
|
|
|
// aDrawSegments by the caller of this function.
|
|
|
|
if( aTrack->GetLength() != 0 )
|
|
|
|
{
|
|
|
|
tracks.push_back( aTrack );
|
|
|
|
aParentContainer->Add( aTrack, ADD_MODE::APPEND );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete aTrack;
|
|
|
|
}
|
|
|
|
};
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
for( PCB_SHAPE* shape : aShapes )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
switch( shape->GetShape() )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2021-07-18 12:31:56 +00:00
|
|
|
if( shape->GetClass() == wxT( "MGRAPHIC" ) )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
FP_SHAPE* fp_shape = (FP_SHAPE*) shape;
|
2021-10-17 14:22:07 +00:00
|
|
|
SHAPE_ARC arc( fp_shape->GetStart0(), fp_shape->GetArcMid0(), fp_shape->GetEnd0(), 0 );
|
|
|
|
|
|
|
|
if( fp_shape->EndsSwapped() )
|
|
|
|
arc.Reverse();
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
track = new PCB_ARC( aParentContainer, &arc );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-17 14:22:07 +00:00
|
|
|
SHAPE_ARC arc( shape->GetStart(), shape->GetArcMid(), shape->GetEnd(), 0 );
|
|
|
|
|
|
|
|
if( shape->EndsSwapped() )
|
|
|
|
arc.Reverse();
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
track = new PCB_ARC( aParentContainer, &arc );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2021-07-18 12:31:56 +00:00
|
|
|
if( shape->GetClass() == wxT( "MGRAPHIC" ) )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-07-18 12:31:56 +00:00
|
|
|
FP_SHAPE* fp_shape = (FP_SHAPE*) shape;
|
2021-06-11 21:07:02 +00:00
|
|
|
track = new PCB_TRACK( aParentContainer );
|
2021-07-18 12:31:56 +00:00
|
|
|
track->SetStart( fp_shape->GetStart0() );
|
|
|
|
track->SetEnd( fp_shape->GetEnd0() );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
track = new PCB_TRACK( aParentContainer );
|
2021-07-18 12:31:56 +00:00
|
|
|
track->SetStart( shape->GetStart() );
|
|
|
|
track->SetEnd( shape->GetEnd() );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Drawsegment type is unexpected. Ignored." ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aWidthOverride == -1 )
|
2021-07-18 12:31:56 +00:00
|
|
|
track->SetWidth( shape->GetWidth() );
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
|
|
|
track->SetWidth( aWidthOverride );
|
|
|
|
|
|
|
|
if( aLayerOverride == PCB_LAYER_ID::UNDEFINED_LAYER )
|
2021-07-18 12:31:56 +00:00
|
|
|
track->SetLayer( shape->GetLayer() );
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
|
|
|
track->SetLayer( aLayerOverride );
|
|
|
|
|
|
|
|
if( aNet != nullptr )
|
|
|
|
track->SetNet( aNet );
|
2021-10-08 19:24:42 +00:00
|
|
|
else
|
|
|
|
track->SetNetCode( -1 );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
track->SetLocked( shape->IsLocked() );
|
2021-03-25 11:28:22 +00:00
|
|
|
|
|
|
|
// Apply route offsetting, mimmicking the behaviour of the CADSTAR post processor
|
|
|
|
if( prevTrack != nullptr )
|
|
|
|
{
|
|
|
|
int offsetAmount = ( track->GetWidth() / 2 ) - ( prevTrack->GetWidth() / 2 );
|
|
|
|
|
|
|
|
if( offsetAmount > 0 )
|
|
|
|
{
|
|
|
|
// modify the start of the current track
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I newStart = track->GetStart();
|
2021-03-25 11:28:22 +00:00
|
|
|
applyRouteOffset( &newStart, track->GetEnd(), offsetAmount );
|
|
|
|
track->SetStart( newStart );
|
|
|
|
}
|
|
|
|
else if( offsetAmount < 0 )
|
|
|
|
{
|
2021-06-09 19:32:58 +00:00
|
|
|
// amend the end of the previous track
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I newEnd = prevTrack->GetEnd();
|
2021-03-25 11:28:22 +00:00
|
|
|
applyRouteOffset( &newEnd, prevTrack->GetStart(), -offsetAmount );
|
|
|
|
prevTrack->SetEnd( newEnd );
|
|
|
|
} // don't do anything if offsetAmount == 0
|
2021-04-06 20:55:21 +00:00
|
|
|
|
|
|
|
// Add a synthetic track of the thinnest width between the tracks
|
|
|
|
// to ensure KiCad features works as expected on the imported design
|
2021-06-09 19:32:58 +00:00
|
|
|
// (KiCad expects tracks are contiguous segments)
|
2021-04-06 20:55:21 +00:00
|
|
|
if( track->GetStart() != prevTrack->GetEnd() )
|
|
|
|
{
|
|
|
|
int minWidth = std::min( track->GetWidth(), prevTrack->GetWidth() );
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* synthTrack = new PCB_TRACK( aParentContainer );
|
2021-04-06 20:55:21 +00:00
|
|
|
synthTrack->SetStart( prevTrack->GetEnd() );
|
|
|
|
synthTrack->SetEnd( track->GetStart() );
|
|
|
|
synthTrack->SetWidth( minWidth );
|
|
|
|
synthTrack->SetLocked( track->IsLocked() );
|
|
|
|
synthTrack->SetNet( track->GetNet() );
|
|
|
|
synthTrack->SetLayer( track->GetLayer() );
|
|
|
|
addTrack( synthTrack );
|
|
|
|
}
|
2021-03-25 11:28:22 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 20:55:21 +00:00
|
|
|
if( prevTrack )
|
|
|
|
addTrack( prevTrack );
|
|
|
|
|
2021-03-25 11:28:22 +00:00
|
|
|
prevTrack = track;
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 20:55:21 +00:00
|
|
|
if( track )
|
|
|
|
addTrack( track );
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
return tracks;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::addAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
2020-11-13 01:12:36 +00:00
|
|
|
const ATTRIBUTE_ID& aCadstarAttributeID,
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* aFootprint,
|
2020-11-13 01:12:36 +00:00
|
|
|
const wxString& aAttributeValue )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* txt;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
if( aCadstarAttributeID == COMPONENT_NAME_ATTRID )
|
2020-10-18 17:15:46 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
txt = &aFootprint->Reference(); //text should be set outside this function
|
2020-10-18 17:15:46 +00:00
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
else if( aCadstarAttributeID == PART_NAME_ATTRID )
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
if( aFootprint->Value().GetText().IsEmpty() )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
// Use PART_NAME_ATTRID as the value is value field is blank
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->SetValue( aAttributeValue );
|
|
|
|
txt = &aFootprint->Value();
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
txt = new FP_TEXT( aFootprint );
|
|
|
|
aFootprint->Add( txt );
|
2020-08-28 20:32:53 +00:00
|
|
|
txt->SetText( aAttributeValue );
|
|
|
|
}
|
|
|
|
txt->SetVisible( false ); //make invisible to avoid clutter.
|
|
|
|
}
|
|
|
|
else if( aCadstarAttributeID != COMPONENT_NAME_2_ATTRID
|
|
|
|
&& getAttributeName( aCadstarAttributeID ) == wxT( "Value" ) )
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
if( !aFootprint->Value().GetText().IsEmpty() )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
//copy the object
|
2020-11-23 20:34:57 +00:00
|
|
|
aFootprint->Add( aFootprint->Value().Duplicate() );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->SetValue( aAttributeValue );
|
|
|
|
txt = &aFootprint->Value();
|
2020-08-28 20:32:53 +00:00
|
|
|
txt->SetVisible( false ); //make invisible to avoid clutter.
|
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
else
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
txt = new FP_TEXT( aFootprint );
|
|
|
|
aFootprint->Add( txt );
|
2020-08-28 20:32:53 +00:00
|
|
|
txt->SetText( aAttributeValue );
|
|
|
|
txt->SetVisible( false ); //make all user attributes invisible to avoid clutter.
|
|
|
|
//TODO: Future improvement - allow user to decide what to do with attributes
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I rotatedTextPos = getKiCadPoint( aCadstarAttrLoc.Position ) - aFootprint->GetPosition();
|
|
|
|
RotatePoint( rotatedTextPos, -aFootprint->GetOrientation() );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
txt->SetTextPos( getKiCadPoint( aCadstarAttrLoc.Position ) );
|
|
|
|
txt->SetPos0( rotatedTextPos );
|
|
|
|
txt->SetLayer( getKiCadLayer( aCadstarAttrLoc.LayerID ) );
|
|
|
|
txt->SetMirrored( aCadstarAttrLoc.Mirror );
|
2022-01-13 17:27:36 +00:00
|
|
|
txt->SetTextAngle( getAngle( aCadstarAttrLoc.OrientAngle ) - aFootprint->GetOrientation() );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-18 17:26:31 +00:00
|
|
|
if( aCadstarAttrLoc.Mirror ) // If mirroring, invert angle to match CADSTAR
|
|
|
|
txt->SetTextAngle( -txt->GetTextAngle() );
|
|
|
|
|
2023-01-29 16:02:43 +00:00
|
|
|
applyTextCode( txt, aCadstarAttrLoc.TextCodeID );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-19 15:25:20 +00:00
|
|
|
txt->SetKeepUpright( false ); //Keeping it upright seems to result in incorrect orientation
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
switch( aCadstarAttrLoc.Alignment )
|
|
|
|
{
|
|
|
|
case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
|
2020-12-30 02:04:19 +00:00
|
|
|
FixTextPositionNoAlignment( txt );
|
|
|
|
KI_FALLTHROUGH;
|
2020-08-28 20:32:53 +00:00
|
|
|
case ALIGNMENT::BOTTOMLEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-08-28 20:32:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMCENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2020-08-28 20:32:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMRIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-08-28 20:32:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERLEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-08-28 20:32:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERCENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2020-08-28 20:32:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERRIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-08-28 20:32:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPLEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-08-28 20:32:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPCENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2020-08-28 20:32:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPRIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
txt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-08-28 20:32:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unknown Alignment - needs review!" ) );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO Handle different font types when KiCad can support it.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::applyRouteOffset( VECTOR2I* aPointToOffset,
|
|
|
|
const VECTOR2I& aRefPoint,
|
2021-03-25 11:28:22 +00:00
|
|
|
const long& aOffsetAmount )
|
|
|
|
{
|
|
|
|
VECTOR2I v( *aPointToOffset - aRefPoint );
|
|
|
|
int newLength = v.EuclideanNorm() - aOffsetAmount;
|
|
|
|
|
|
|
|
if( newLength > 0 )
|
|
|
|
{
|
|
|
|
VECTOR2I offsetted = v.Resize( newLength ) + VECTOR2I( aRefPoint );
|
|
|
|
aPointToOffset->x = offsetted.x;
|
|
|
|
aPointToOffset->y = offsetted.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*aPointToOffset = aRefPoint; // zero length track. Needs to be removed to mimmick
|
|
|
|
// cadstar behaviour
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-29 16:02:43 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER:: applyTextCode( EDA_TEXT* aKiCadText,
|
|
|
|
const TEXTCODE_ID& aCadstarTextCodeID )
|
|
|
|
{
|
|
|
|
TEXTCODE tc = getTextCode( aCadstarTextCodeID );
|
|
|
|
|
|
|
|
aKiCadText->SetTextThickness( getKiCadLength( tc.LineWidth ) );
|
|
|
|
|
|
|
|
VECTOR2I textSize;
|
|
|
|
textSize.x = getKiCadLength( tc.Width );
|
|
|
|
|
|
|
|
// The width is zero for all non-cadstar fonts. Using a width equal to the height seems
|
|
|
|
// to work well for most fonts.
|
|
|
|
if( textSize.x == 0 )
|
|
|
|
textSize.x = getKiCadLength( tc.Height );
|
|
|
|
|
|
|
|
textSize.y = KiROUND( TXT_HEIGHT_RATIO * (double) getKiCadLength( tc.Height ) );
|
|
|
|
|
|
|
|
if( textSize.x == 0 || textSize.y == 0 )
|
|
|
|
{
|
|
|
|
// Make zero sized text not visible
|
|
|
|
|
|
|
|
aKiCadText->SetTextSize(
|
|
|
|
VECTOR2I( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, DEFAULT_SIZE_TEXT ),
|
|
|
|
EDA_UNIT_UTILS::Mils2IU( pcbIUScale, DEFAULT_SIZE_TEXT ) ) );
|
|
|
|
|
|
|
|
aKiCadText->SetVisible( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aKiCadText->SetTextSize( textSize );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
int CADSTAR_PCB_ARCHIVE_LOADER::getLineThickness( const LINECODE_ID& aCadstarLineCodeID )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID )
|
|
|
|
!= Assignments.Codedefs.LineCodes.end(),
|
2021-02-13 20:00:17 +00:00
|
|
|
m_board->GetDesignSettings().GetLineThickness( PCB_LAYER_ID::Edge_Cuts ) );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
return getKiCadLength( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Width );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::COPPERCODE CADSTAR_PCB_ARCHIVE_LOADER::getCopperCode(
|
|
|
|
const COPPERCODE_ID& aCadstaCopperCodeID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.CopperCodes.find( aCadstaCopperCodeID )
|
|
|
|
!= Assignments.Codedefs.CopperCodes.end(),
|
|
|
|
COPPERCODE() );
|
|
|
|
|
|
|
|
return Assignments.Codedefs.CopperCodes.at( aCadstaCopperCodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::TEXTCODE CADSTAR_PCB_ARCHIVE_LOADER::getTextCode(
|
|
|
|
const TEXTCODE_ID& aCadstarTextCodeID )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.TextCodes.find( aCadstarTextCodeID )
|
|
|
|
!= Assignments.Codedefs.TextCodes.end(),
|
|
|
|
TEXTCODE() );
|
|
|
|
|
|
|
|
return Assignments.Codedefs.TextCodes.at( aCadstarTextCodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::PADCODE CADSTAR_PCB_ARCHIVE_LOADER::getPadCode(
|
|
|
|
const PADCODE_ID& aCadstarPadCodeID )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.PadCodes.find( aCadstarPadCodeID )
|
|
|
|
!= Assignments.Codedefs.PadCodes.end(),
|
|
|
|
PADCODE() );
|
|
|
|
|
|
|
|
return Assignments.Codedefs.PadCodes.at( aCadstarPadCodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::VIACODE CADSTAR_PCB_ARCHIVE_LOADER::getViaCode(
|
|
|
|
const VIACODE_ID& aCadstarViaCodeID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.ViaCodes.find( aCadstarViaCodeID )
|
|
|
|
!= Assignments.Codedefs.ViaCodes.end(),
|
|
|
|
VIACODE() );
|
|
|
|
|
|
|
|
return Assignments.Codedefs.ViaCodes.at( aCadstarViaCodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::LAYERPAIR CADSTAR_PCB_ARCHIVE_LOADER::getLayerPair(
|
|
|
|
const LAYERPAIR_ID& aCadstarLayerPairID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.LayerPairs.find( aCadstarLayerPairID )
|
|
|
|
!= Assignments.Codedefs.LayerPairs.end(),
|
|
|
|
LAYERPAIR() );
|
|
|
|
|
|
|
|
return Assignments.Codedefs.LayerPairs.at( aCadstarLayerPairID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
wxString CADSTAR_PCB_ARCHIVE_LOADER::getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.AttributeNames.find( aCadstarAttributeID )
|
|
|
|
!= Assignments.Codedefs.AttributeNames.end(),
|
|
|
|
wxEmptyString );
|
|
|
|
|
|
|
|
return Assignments.Codedefs.AttributeNames.at( aCadstarAttributeID ).Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
wxString CADSTAR_PCB_ARCHIVE_LOADER::getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
|
2020-08-31 22:09:29 +00:00
|
|
|
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
|
|
|
wxCHECK( aCadstarAttributeMap.find( aCadstarAttributeID ) != aCadstarAttributeMap.end(),
|
|
|
|
wxEmptyString );
|
|
|
|
|
|
|
|
return aCadstarAttributeMap.at( aCadstarAttributeID ).Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-09 19:06:56 +00:00
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::LAYER_TYPE
|
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::getLayerType( const LAYER_ID aCadstarLayerID )
|
|
|
|
{
|
|
|
|
if( Assignments.Layerdefs.Layers.find( aCadstarLayerID ) != Assignments.Layerdefs.Layers.end() )
|
|
|
|
{
|
|
|
|
return Assignments.Layerdefs.Layers.at( aCadstarLayerID ).Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LAYER_TYPE::UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::PART CADSTAR_PCB_ARCHIVE_LOADER::getPart(
|
|
|
|
const PART_ID& aCadstarPartID )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2020-08-30 12:23:25 +00:00
|
|
|
wxCHECK( Parts.PartDefinitions.find( aCadstarPartID ) != Parts.PartDefinitions.end(), PART() );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
return Parts.PartDefinitions.at( aCadstarPartID );
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-06 15:24:40 +00:00
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::ROUTECODE CADSTAR_PCB_ARCHIVE_LOADER::getRouteCode(
|
|
|
|
const ROUTECODE_ID& aCadstarRouteCodeID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.RouteCodes.find( aCadstarRouteCodeID )
|
|
|
|
!= Assignments.Codedefs.RouteCodes.end(),
|
|
|
|
ROUTECODE() );
|
|
|
|
|
|
|
|
return Assignments.Codedefs.RouteCodes.at( aCadstarRouteCodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::HATCHCODE CADSTAR_PCB_ARCHIVE_LOADER::getHatchCode(
|
|
|
|
const HATCHCODE_ID& aCadstarHatchcodeID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.HatchCodes.find( aCadstarHatchcodeID )
|
|
|
|
!= Assignments.Codedefs.HatchCodes.end(),
|
|
|
|
HATCHCODE() );
|
|
|
|
|
|
|
|
return Assignments.Codedefs.HatchCodes.at( aCadstarHatchcodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-19 00:22:40 +00:00
|
|
|
EDA_ANGLE CADSTAR_PCB_ARCHIVE_LOADER::getHatchCodeAngle( const HATCHCODE_ID& aCadstarHatchcodeID )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
checkAndLogHatchCode( aCadstarHatchcodeID );
|
|
|
|
HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
|
|
|
|
|
|
|
|
if( hcode.Hatches.size() < 1 )
|
2021-02-13 20:00:17 +00:00
|
|
|
return m_board->GetDesignSettings().GetDefaultZoneSettings().m_HatchOrientation;
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
2022-01-19 00:22:40 +00:00
|
|
|
return getAngle( hcode.Hatches.at( 0 ).OrientAngle );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CADSTAR_PCB_ARCHIVE_LOADER::getKiCadHatchCodeThickness(
|
|
|
|
const HATCHCODE_ID& aCadstarHatchcodeID )
|
|
|
|
{
|
|
|
|
checkAndLogHatchCode( aCadstarHatchcodeID );
|
|
|
|
HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
|
|
|
|
|
|
|
|
if( hcode.Hatches.size() < 1 )
|
2021-02-13 20:00:17 +00:00
|
|
|
return m_board->GetDesignSettings().GetDefaultZoneSettings().m_HatchThickness;
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
|
|
|
return getKiCadLength( hcode.Hatches.at( 0 ).LineWidth );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CADSTAR_PCB_ARCHIVE_LOADER::getKiCadHatchCodeGap( const HATCHCODE_ID& aCadstarHatchcodeID )
|
|
|
|
{
|
|
|
|
checkAndLogHatchCode( aCadstarHatchcodeID );
|
|
|
|
HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
|
|
|
|
|
|
|
|
if( hcode.Hatches.size() < 1 )
|
2021-02-13 20:00:17 +00:00
|
|
|
return m_board->GetDesignSettings().GetDefaultZoneSettings().m_HatchGap;
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
|
|
|
return getKiCadLength( hcode.Hatches.at( 0 ).Step );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
PCB_GROUP* CADSTAR_PCB_ARCHIVE_LOADER::getKiCadGroup( const GROUP_ID& aCadstarGroupID )
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
wxCHECK( m_groupMap.find( aCadstarGroupID ) != m_groupMap.end(), nullptr );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
return m_groupMap.at( aCadstarGroupID );
|
2020-09-06 21:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::checkAndLogHatchCode( const HATCHCODE_ID& aCadstarHatchcodeID )
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_hatchcodesTested.find( aCadstarHatchcodeID ) != m_hatchcodesTested.end() )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
return; //already checked
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
|
|
|
|
|
|
|
|
if( hcode.Hatches.size() != 2 )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The CADSTAR Hatching code '%s' has %d hatches defined. "
|
|
|
|
"KiCad only supports 2 hatches (crosshatching) 90 degrees apart. "
|
|
|
|
"The imported hatching is crosshatched." ),
|
|
|
|
hcode.Name, (int) hcode.Hatches.size() ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( hcode.Hatches.at( 0 ).LineWidth != hcode.Hatches.at( 1 ).LineWidth )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The CADSTAR Hatching code '%s' has different line widths for each "
|
2021-11-08 23:50:27 +00:00
|
|
|
"hatch. KiCad only supports one width for the hatching. The imported "
|
2020-08-31 22:09:29 +00:00
|
|
|
"hatching uses the width defined in the first hatch definition, i.e. "
|
|
|
|
"%.2f mm." ),
|
|
|
|
hcode.Name,
|
2020-09-10 20:58:20 +00:00
|
|
|
(double) ( (double) getKiCadLength( hcode.Hatches.at( 0 ).LineWidth ) )
|
|
|
|
/ 1E6 ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( hcode.Hatches.at( 0 ).Step != hcode.Hatches.at( 1 ).Step )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The CADSTAR Hatching code '%s' has different step sizes for each "
|
2021-11-08 23:50:27 +00:00
|
|
|
"hatch. KiCad only supports one step size for the hatching. The imported "
|
2020-08-31 22:09:29 +00:00
|
|
|
"hatching uses the step size defined in the first hatching definition, "
|
|
|
|
"i.e. %.2f mm." ),
|
|
|
|
hcode.Name,
|
|
|
|
(double) ( (double) getKiCadLength( hcode.Hatches.at( 0 ).Step ) )
|
|
|
|
/ 1E6 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( abs( hcode.Hatches.at( 0 ).OrientAngle - hcode.Hatches.at( 1 ).OrientAngle )
|
|
|
|
!= 90000 )
|
|
|
|
{
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The hatches in CADSTAR Hatching code '%s' have an angle "
|
|
|
|
"difference of %.1f degrees. KiCad only supports hatching 90 "
|
|
|
|
"degrees apart. The imported hatching has two hatches 90 "
|
|
|
|
"degrees apart, oriented %.1f degrees from horizontal." ),
|
|
|
|
hcode.Name,
|
2022-01-13 17:27:36 +00:00
|
|
|
getAngle( abs( hcode.Hatches.at( 0 ).OrientAngle
|
|
|
|
- hcode.Hatches.at( 1 ).OrientAngle ) ).AsDegrees(),
|
|
|
|
getAngle( hcode.Hatches.at( 0 ).OrientAngle ).AsDegrees() ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_hatchcodesTested.insert( aCadstarHatchcodeID );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-23 01:49:23 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::applyDimensionSettings( const DIMENSION& aCadstarDim,
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIMENSION_BASE* aKiCadDim )
|
2020-12-23 01:49:23 +00:00
|
|
|
{
|
|
|
|
UNITS dimensionUnits = aCadstarDim.LinearUnits;
|
|
|
|
LINECODE linecode = Assignments.Codedefs.LineCodes.at( aCadstarDim.Line.LineCodeID );
|
|
|
|
|
|
|
|
aKiCadDim->SetLayer( getKiCadLayer( aCadstarDim.LayerID ) );
|
2023-03-05 13:27:22 +00:00
|
|
|
aKiCadDim->SetPrecision( static_cast<DIM_PRECISION>( aCadstarDim.Precision ) );
|
2020-12-23 01:49:23 +00:00
|
|
|
aKiCadDim->SetStart( getKiCadPoint( aCadstarDim.ExtensionLineParams.Start ) );
|
|
|
|
aKiCadDim->SetEnd( getKiCadPoint( aCadstarDim.ExtensionLineParams.End ) );
|
|
|
|
aKiCadDim->SetExtensionOffset( getKiCadLength( aCadstarDim.ExtensionLineParams.Offset ) );
|
|
|
|
aKiCadDim->SetLineThickness( getKiCadLength( linecode.Width ) );
|
2023-01-29 16:02:43 +00:00
|
|
|
|
2023-03-04 23:15:43 +00:00
|
|
|
applyTextCode( aKiCadDim, aCadstarDim.Text.TextCodeID );
|
2020-12-23 01:49:23 +00:00
|
|
|
|
2020-12-27 17:37:25 +00:00
|
|
|
// Find prefix and suffix:
|
|
|
|
wxString prefix = wxEmptyString;
|
|
|
|
wxString suffix = wxEmptyString;
|
|
|
|
size_t startpos = aCadstarDim.Text.Text.Find( wxT( "<@DISTANCE" ) );
|
|
|
|
|
|
|
|
if( startpos != wxNOT_FOUND )
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
prefix = ParseTextFields( aCadstarDim.Text.Text.SubString( 0, startpos - 1 ), &m_context );
|
2020-12-27 17:37:25 +00:00
|
|
|
wxString remainingStr = aCadstarDim.Text.Text.Mid( startpos );
|
|
|
|
size_t endpos = remainingStr.Find( "@>" );
|
2021-02-13 20:00:17 +00:00
|
|
|
suffix = ParseTextFields( remainingStr.Mid( endpos + 2 ), &m_context );
|
2020-12-27 17:37:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( suffix.StartsWith( wxT( "mm" ) ) )
|
2020-12-27 17:37:25 +00:00
|
|
|
{
|
|
|
|
aKiCadDim->SetUnitsFormat( DIM_UNITS_FORMAT::BARE_SUFFIX );
|
|
|
|
suffix = suffix.Mid( 2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aKiCadDim->SetUnitsFormat( DIM_UNITS_FORMAT::NO_SUFFIX );
|
|
|
|
}
|
|
|
|
|
|
|
|
aKiCadDim->SetPrefix( prefix );
|
|
|
|
aKiCadDim->SetSuffix( suffix );
|
|
|
|
|
2020-12-23 01:49:23 +00:00
|
|
|
if( aCadstarDim.LinearUnits == UNITS::DESIGN )
|
|
|
|
{
|
|
|
|
// For now we will hardcode the units as per the original CADSTAR design.
|
|
|
|
// TODO: update this when KiCad supports design units
|
2023-03-05 13:27:22 +00:00
|
|
|
aKiCadDim->SetPrecision( static_cast<DIM_PRECISION>( Assignments.Technology.UnitDisplPrecision ) );
|
2020-12-23 01:49:23 +00:00
|
|
|
dimensionUnits = Assignments.Technology.Units;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( dimensionUnits )
|
|
|
|
{
|
|
|
|
case UNITS::METER:
|
|
|
|
case UNITS::CENTIMETER:
|
|
|
|
case UNITS::MICROMETRE:
|
|
|
|
wxLogWarning( wxString::Format( _( "Dimension ID %s uses a type of unit that "
|
2021-11-08 23:51:57 +00:00
|
|
|
"is not supported in KiCad. Millimeters were "
|
2020-12-23 01:49:23 +00:00
|
|
|
"applied instead." ),
|
|
|
|
aCadstarDim.ID ) );
|
|
|
|
KI_FALLTHROUGH;
|
2021-01-31 20:47:36 +00:00
|
|
|
case UNITS::MM:
|
2020-12-23 01:49:23 +00:00
|
|
|
aKiCadDim->SetUnitsMode( DIM_UNITS_MODE::MILLIMETRES );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNITS::INCH:
|
|
|
|
aKiCadDim->SetUnitsMode( DIM_UNITS_MODE::INCHES );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNITS::THOU:
|
|
|
|
aKiCadDim->SetUnitsMode( DIM_UNITS_MODE::MILS );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNITS::DESIGN:
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "We should have handled design units before coming here!" ) );
|
2020-12-23 01:49:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 17:39:04 +00:00
|
|
|
bool CADSTAR_PCB_ARCHIVE_LOADER::calculateZonePriorities( PCB_LAYER_ID& aLayer )
|
2021-02-06 19:36:51 +00:00
|
|
|
{
|
|
|
|
std::map<TEMPLATE_ID, std::set<TEMPLATE_ID>> winningOverlaps;
|
|
|
|
|
2021-10-12 17:39:04 +00:00
|
|
|
auto inflateValue =
|
|
|
|
[&]( ZONE* aZoneA, ZONE* aZoneB )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
int extra = getKiCadLength( Assignments.Codedefs.SpacingCodes.at( wxT( "C_C" ) ).Spacing )
|
2021-10-12 17:39:04 +00:00
|
|
|
- m_board->GetDesignSettings().m_MinClearance;
|
|
|
|
|
|
|
|
int retval = std::max( aZoneA->GetLocalClearance(), aZoneB->GetLocalClearance() );
|
|
|
|
|
|
|
|
retval += extra;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Find the error in fill area when guessing that aHigherZone gets filled before aLowerZone
|
|
|
|
auto errorArea =
|
|
|
|
[&]( ZONE* aLowerZone, ZONE* aHigherZone ) -> double
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET intersectShape( *aHigherZone->Outline() );
|
|
|
|
intersectShape.Inflate( inflateValue( aLowerZone, aHigherZone ) , 32 );
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2022-02-15 17:34:38 +00:00
|
|
|
SHAPE_POLY_SET lowerZoneFill( *aLowerZone->GetFilledPolysList( aLayer ) );
|
2021-10-12 17:39:04 +00:00
|
|
|
SHAPE_POLY_SET lowerZoneOutline( *aLowerZone->Outline() );
|
|
|
|
|
2022-02-15 17:34:38 +00:00
|
|
|
lowerZoneOutline.BooleanSubtract( intersectShape, SHAPE_POLY_SET::PM_FAST );
|
2021-10-12 17:39:04 +00:00
|
|
|
|
2022-02-15 17:34:38 +00:00
|
|
|
lowerZoneFill.BooleanSubtract( lowerZoneOutline, SHAPE_POLY_SET::PM_FAST );
|
2021-10-12 17:39:04 +00:00
|
|
|
|
|
|
|
double leftOverArea = lowerZoneFill.Area();
|
|
|
|
|
|
|
|
return leftOverArea;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto intersectionAreaOfZoneOutlines =
|
|
|
|
[&]( ZONE* aZoneA, ZONE* aZoneB ) -> double
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET outLineA( *aZoneA->Outline() );
|
|
|
|
outLineA.Inflate( inflateValue( aZoneA, aZoneB ), 32 );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET outLineB( *aZoneA->Outline() );
|
|
|
|
outLineB.Inflate( inflateValue( aZoneA, aZoneB ), 32 );
|
|
|
|
|
|
|
|
outLineA.BooleanIntersection( outLineB, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
return outLineA.Area();
|
|
|
|
};
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
// Lambda to determine if the zone with template ID 'a' is lower priority than 'b'
|
2021-10-12 17:39:04 +00:00
|
|
|
auto isLowerPriority =
|
|
|
|
[&]( const TEMPLATE_ID& a, const TEMPLATE_ID& b ) -> bool
|
|
|
|
{
|
|
|
|
return winningOverlaps[b].count( a ) > 0;
|
|
|
|
};
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::map<TEMPLATE_ID, ZONE*>::iterator it1 = m_zonesMap.begin();
|
|
|
|
it1 != m_zonesMap.end(); ++it1 )
|
2021-02-06 19:36:51 +00:00
|
|
|
{
|
2021-10-12 17:39:04 +00:00
|
|
|
TEMPLATE& thisTemplate = Layout.Templates.at( it1->first );
|
|
|
|
ZONE* thisZone = it1->second;
|
|
|
|
|
|
|
|
if( !thisZone->GetLayerSet().Contains( aLayer ) )
|
|
|
|
continue;
|
2021-02-06 19:36:51 +00:00
|
|
|
|
|
|
|
for( std::map<TEMPLATE_ID, ZONE*>::iterator it2 = it1;
|
2021-02-13 20:00:17 +00:00
|
|
|
it2 != m_zonesMap.end(); ++it2 )
|
2021-02-06 19:36:51 +00:00
|
|
|
{
|
2021-10-12 17:39:04 +00:00
|
|
|
TEMPLATE& otherTemplate = Layout.Templates.at( it2->first );
|
|
|
|
ZONE* otherZone = it2->second;
|
2021-02-06 19:36:51 +00:00
|
|
|
|
|
|
|
if( thisTemplate.ID == otherTemplate.ID )
|
|
|
|
continue;
|
|
|
|
|
2021-10-12 17:39:04 +00:00
|
|
|
if( !otherZone->GetLayerSet().Contains( aLayer ) )
|
|
|
|
{
|
|
|
|
checkPoint();
|
2021-02-06 19:36:51 +00:00
|
|
|
continue;
|
2021-10-12 17:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( intersectionAreaOfZoneOutlines( thisZone, otherZone ) == 0 )
|
|
|
|
{
|
|
|
|
checkPoint();
|
|
|
|
continue; // The zones do not interact in any way
|
|
|
|
}
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2022-02-15 17:34:38 +00:00
|
|
|
SHAPE_POLY_SET thisZonePolyFill = *thisZone->GetFilledPolysList( aLayer );
|
|
|
|
SHAPE_POLY_SET otherZonePolyFill = *otherZone->GetFilledPolysList( aLayer );
|
2021-02-06 19:36:51 +00:00
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
if( thisZonePolyFill.Area() > 0.0 && otherZonePolyFill.Area() > 0.0 )
|
|
|
|
{
|
2021-10-12 17:39:04 +00:00
|
|
|
// Test if this zone were lower priority than other zone, what is the error?
|
|
|
|
double areaThis = errorArea( thisZone, otherZone );
|
Fix typos in pcbnew sub-directory
Found via `codespell -q 3 -S *.po,./thirdparty,./Documentation/changelogs -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,ba,busses,dout,einstance,leaded,modul,ontext,ot,overide,serie,te,,tesselate,tesselator,tht`
2022-06-29 20:21:10 +00:00
|
|
|
// Vice-versa
|
2021-10-12 17:39:04 +00:00
|
|
|
double areaOther = errorArea( otherZone, thisZone );
|
2021-02-08 10:40:32 +00:00
|
|
|
|
|
|
|
if( areaThis > areaOther )
|
|
|
|
{
|
2021-10-12 17:39:04 +00:00
|
|
|
// thisTemplate is filled before otherTemplate
|
2021-02-08 10:40:32 +00:00
|
|
|
winningOverlaps[thisTemplate.ID].insert( otherTemplate.ID );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-12 17:39:04 +00:00
|
|
|
// thisTemplate is filled AFTER otherTemplate
|
|
|
|
winningOverlaps[otherTemplate.ID].insert( thisTemplate.ID );
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-12 17:39:04 +00:00
|
|
|
else if( thisZonePolyFill.Area() > 0.0 )
|
|
|
|
{
|
|
|
|
// The other template is not filled, this one wins
|
|
|
|
winningOverlaps[thisTemplate.ID].insert( otherTemplate.ID );
|
|
|
|
}
|
|
|
|
else if( otherZonePolyFill.Area() > 0.0 )
|
|
|
|
{
|
|
|
|
// This template is not filled, the other one wins
|
|
|
|
winningOverlaps[otherTemplate.ID].insert( thisTemplate.ID );
|
|
|
|
}
|
2021-02-08 10:40:32 +00:00
|
|
|
else
|
|
|
|
{
|
2021-10-12 17:39:04 +00:00
|
|
|
// Neither of the templates is poured - use zone outlines instead (bigger outlines
|
|
|
|
// get a lower priority)
|
|
|
|
if( intersectionAreaOfZoneOutlines( thisZone, otherZone ) != 0 )
|
|
|
|
{
|
|
|
|
if( thisZone->Outline()->Area() > otherZone->Outline()->Area() )
|
|
|
|
winningOverlaps[otherTemplate.ID].insert( thisTemplate.ID );
|
|
|
|
else
|
|
|
|
winningOverlaps[thisTemplate.ID].insert( otherTemplate.ID );
|
|
|
|
}
|
2021-02-08 10:40:32 +00:00
|
|
|
}
|
2021-10-12 17:39:04 +00:00
|
|
|
|
|
|
|
checkPoint();
|
2021-02-06 19:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build a set of unique TEMPLATE_IDs of all the zones that intersect with another one
|
|
|
|
std::set<TEMPLATE_ID> intersectingIDs;
|
|
|
|
|
|
|
|
for( const std::pair<TEMPLATE_ID, std::set<TEMPLATE_ID>>& idPair : winningOverlaps )
|
|
|
|
{
|
|
|
|
intersectingIDs.insert( idPair.first );
|
|
|
|
intersectingIDs.insert( idPair.second.begin(), idPair.second.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now store them in a vector
|
|
|
|
std::vector<TEMPLATE_ID> sortedIDs;
|
|
|
|
|
|
|
|
for( const TEMPLATE_ID& id : intersectingIDs )
|
|
|
|
{
|
|
|
|
sortedIDs.push_back( id );
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort by priority
|
|
|
|
std::sort( sortedIDs.begin(), sortedIDs.end(), isLowerPriority );
|
|
|
|
|
|
|
|
TEMPLATE_ID prevID = wxEmptyString;
|
|
|
|
|
|
|
|
for( const TEMPLATE_ID& id : sortedIDs )
|
|
|
|
{
|
|
|
|
if( prevID.IsEmpty() )
|
|
|
|
{
|
|
|
|
prevID = id;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxASSERT( !isLowerPriority( id, prevID ) );
|
|
|
|
|
2022-03-01 14:53:35 +00:00
|
|
|
int newPriority = m_zonesMap.at( prevID )->GetAssignedPriority();
|
2021-02-06 19:36:51 +00:00
|
|
|
|
|
|
|
// Only increase priority of the current zone
|
|
|
|
if( isLowerPriority( prevID, id ) )
|
|
|
|
newPriority++;
|
|
|
|
|
2022-03-01 14:53:35 +00:00
|
|
|
m_zonesMap.at( id )->SetAssignedPriority( newPriority );
|
2021-02-06 19:36:51 +00:00
|
|
|
prevID = id;
|
|
|
|
}
|
|
|
|
|
2021-10-12 17:39:04 +00:00
|
|
|
// Verify
|
|
|
|
for( const std::pair<TEMPLATE_ID, std::set<TEMPLATE_ID>>& idPair : winningOverlaps )
|
|
|
|
{
|
|
|
|
const TEMPLATE_ID& winningID = idPair.first;
|
|
|
|
|
|
|
|
for( const TEMPLATE_ID& losingID : idPair.second )
|
|
|
|
{
|
2022-03-01 14:53:35 +00:00
|
|
|
if( m_zonesMap.at( losingID )->GetAssignedPriority()
|
|
|
|
> m_zonesMap.at( winningID )->GetAssignedPriority() )
|
2021-10-12 17:39:04 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-02-06 19:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
FOOTPRINT* CADSTAR_PCB_ARCHIVE_LOADER::getFootprintFromCadstarID(
|
|
|
|
const COMPONENT_ID& aCadstarComponentID )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_componentMap.find( aCadstarComponentID ) == m_componentMap.end() )
|
2020-08-31 22:09:29 +00:00
|
|
|
return nullptr;
|
|
|
|
else
|
2021-02-13 20:00:17 +00:00
|
|
|
return m_componentMap.at( aCadstarComponentID );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I CADSTAR_PCB_ARCHIVE_LOADER::getKiCadPoint( const VECTOR2I& aCadstarPoint )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I retval;
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
retval.x = ( aCadstarPoint.x - m_designCenter.x ) * KiCadUnitMultiplier;
|
|
|
|
retval.y = -( aCadstarPoint.y - m_designCenter.y ) * KiCadUnitMultiplier;
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
NETINFO_ITEM* CADSTAR_PCB_ARCHIVE_LOADER::getKiCadNet( const NET_ID& aCadstarNetID )
|
|
|
|
{
|
|
|
|
if( aCadstarNetID.IsEmpty() )
|
2021-10-08 19:07:21 +00:00
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
return nullptr;
|
2021-10-08 19:07:21 +00:00
|
|
|
}
|
2021-02-13 20:00:17 +00:00
|
|
|
else if( m_netMap.find( aCadstarNetID ) != m_netMap.end() )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
return m_netMap.at( aCadstarNetID );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxCHECK( Layout.Nets.find( aCadstarNetID ) != Layout.Nets.end(), nullptr );
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
NET_PCB csNet = Layout.Nets.at( aCadstarNetID );
|
2020-09-05 15:31:57 +00:00
|
|
|
wxString newName = csNet.Name;
|
2020-09-02 21:48:18 +00:00
|
|
|
|
|
|
|
if( csNet.Name.IsEmpty() )
|
2020-09-05 15:31:57 +00:00
|
|
|
{
|
|
|
|
if( csNet.Pins.size() > 0 )
|
|
|
|
{
|
|
|
|
// Create default KiCad net naming:
|
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
NET_PCB::PIN firstPin = ( *csNet.Pins.begin() ).second;
|
2020-09-05 15:31:57 +00:00
|
|
|
//we should have already loaded the component with loadComponents() :
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* m = getFootprintFromCadstarID( firstPin.ComponentID );
|
2020-09-05 15:31:57 +00:00
|
|
|
newName = wxT( "Net-(" );
|
|
|
|
newName << m->Reference().GetText();
|
2022-02-05 02:06:25 +00:00
|
|
|
newName << wxT( "-Pad" ) << wxString::Format( wxT( "%ld" ), firstPin.PadID );
|
|
|
|
newName << wxT( ")" );
|
2020-09-05 15:31:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "A net with no pins associated?" ) );
|
2020-09-05 15:31:57 +00:00
|
|
|
newName = wxT( "csNet-" );
|
2022-02-05 02:06:25 +00:00
|
|
|
newName << wxString::Format( wxT( "%i" ), csNet.SignalNum );
|
2020-09-05 15:31:57 +00:00
|
|
|
}
|
2020-09-06 15:24:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
if( !m_doneNetClassWarning && !csNet.NetClassID.IsEmpty()
|
2020-09-06 15:24:40 +00:00
|
|
|
&& csNet.NetClassID != wxT( "NONE" ) )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogMessage( _( "The CADSTAR design contains nets with a 'Net Class' assigned. KiCad "
|
|
|
|
"does not have an equivalent to CADSTAR's Net Class so these elements "
|
|
|
|
"were not imported. Note: KiCad's version of 'Net Class' is closer to "
|
|
|
|
"CADSTAR's 'Net Route Code' (which has been imported for all nets)." ) );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_doneNetClassWarning = true;
|
2020-09-06 15:24:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
if( !m_doneSpacingClassWarning && !csNet.SpacingClassID.IsEmpty()
|
2020-09-06 15:24:40 +00:00
|
|
|
&& csNet.SpacingClassID != wxT( "NONE" ) )
|
|
|
|
{
|
2021-01-13 12:07:06 +00:00
|
|
|
wxLogWarning( _( "The CADSTAR design contains nets with a 'Spacing Class' assigned. "
|
|
|
|
"KiCad does not have an equivalent to CADSTAR's Spacing Class so "
|
|
|
|
"these elements were not imported. Please review the design rules as "
|
|
|
|
"copper pours will affected by this." ) );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_doneSpacingClassWarning = true;
|
2020-09-06 15:24:40 +00:00
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NET_SETTINGS>& netSettings = m_board->GetDesignSettings().m_NetSettings;
|
|
|
|
NETINFO_ITEM* netInfo = new NETINFO_ITEM( m_board, newName, ++m_numNets );
|
|
|
|
std::shared_ptr<NETCLASS> netclass;
|
2020-09-06 15:24:40 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::tuple<ROUTECODE_ID, NETCLASS_ID, SPACING_CLASS_ID> key = { csNet.RouteCodeID,
|
2021-10-10 19:05:27 +00:00
|
|
|
csNet.NetClassID,
|
|
|
|
csNet.SpacingClassID };
|
|
|
|
|
|
|
|
if( m_netClassMap.find( key ) != m_netClassMap.end() )
|
2020-09-06 15:24:40 +00:00
|
|
|
{
|
2021-10-10 19:05:27 +00:00
|
|
|
netclass = m_netClassMap.at( key );
|
2020-09-06 15:24:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-10 19:05:27 +00:00
|
|
|
wxString netClassName;
|
|
|
|
|
|
|
|
ROUTECODE rc = getRouteCode( csNet.RouteCodeID );
|
|
|
|
netClassName += wxT( "Route code: " ) + rc.Name;
|
|
|
|
|
|
|
|
if( !csNet.NetClassID.IsEmpty() )
|
|
|
|
{
|
|
|
|
CADSTAR_NETCLASS nc = Assignments.Codedefs.NetClasses.at( csNet.NetClassID );
|
|
|
|
netClassName += wxT( " | Net class: " ) + nc.Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !csNet.SpacingClassID.IsEmpty() )
|
|
|
|
{
|
|
|
|
SPCCLASSNAME sp = Assignments.Codedefs.SpacingClassNames.at( csNet.SpacingClassID );
|
|
|
|
netClassName += wxT( " | Spacing class: " ) + sp.Name;
|
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
netclass.reset( new NETCLASS( *netSettings->m_DefaultNetClass ) );
|
2021-10-10 19:05:27 +00:00
|
|
|
netclass->SetName( netClassName );
|
2022-08-14 11:03:18 +00:00
|
|
|
netSettings->m_NetClasses[ netClassName ] = netclass;
|
2020-09-06 15:24:40 +00:00
|
|
|
netclass->SetTrackWidth( getKiCadLength( rc.OptimalWidth ) );
|
2021-10-10 19:05:27 +00:00
|
|
|
m_netClassMap.insert( { key, netclass } );
|
2020-09-06 15:24:40 +00:00
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_board->GetDesignSettings().m_NetSettings->m_NetClassPatternAssignments.push_back(
|
|
|
|
{
|
|
|
|
std::make_unique<EDA_COMBINED_MATCHER>( newName, CTX_NETCLASS ),
|
|
|
|
netclass->GetName()
|
|
|
|
} );
|
|
|
|
|
2021-10-08 19:24:42 +00:00
|
|
|
netInfo->SetNetClass( netclass );
|
|
|
|
m_board->Add( netInfo, ADD_MODE::APPEND );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_netMap.insert( { aCadstarNetID, netInfo } );
|
2020-08-31 22:09:29 +00:00
|
|
|
return netInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
PCB_LAYER_ID CADSTAR_PCB_ARCHIVE_LOADER::getKiCadCopperLayerID( unsigned int aLayerNum,
|
|
|
|
bool aDetectMaxLayer )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2021-10-09 19:06:56 +00:00
|
|
|
if( aDetectMaxLayer && aLayerNum == m_numCopperLayers )
|
2020-08-31 22:09:29 +00:00
|
|
|
return PCB_LAYER_ID::B_Cu;
|
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
switch( aLayerNum )
|
|
|
|
{
|
2020-08-28 20:32:53 +00:00
|
|
|
case 1: return PCB_LAYER_ID::F_Cu;
|
|
|
|
case 2: return PCB_LAYER_ID::In1_Cu;
|
|
|
|
case 3: return PCB_LAYER_ID::In2_Cu;
|
|
|
|
case 4: return PCB_LAYER_ID::In3_Cu;
|
|
|
|
case 5: return PCB_LAYER_ID::In4_Cu;
|
|
|
|
case 6: return PCB_LAYER_ID::In5_Cu;
|
|
|
|
case 7: return PCB_LAYER_ID::In6_Cu;
|
|
|
|
case 8: return PCB_LAYER_ID::In7_Cu;
|
|
|
|
case 9: return PCB_LAYER_ID::In8_Cu;
|
|
|
|
case 10: return PCB_LAYER_ID::In9_Cu;
|
|
|
|
case 11: return PCB_LAYER_ID::In10_Cu;
|
|
|
|
case 12: return PCB_LAYER_ID::In11_Cu;
|
|
|
|
case 13: return PCB_LAYER_ID::In12_Cu;
|
|
|
|
case 14: return PCB_LAYER_ID::In13_Cu;
|
|
|
|
case 15: return PCB_LAYER_ID::In14_Cu;
|
|
|
|
case 16: return PCB_LAYER_ID::In15_Cu;
|
|
|
|
case 17: return PCB_LAYER_ID::In16_Cu;
|
|
|
|
case 18: return PCB_LAYER_ID::In17_Cu;
|
|
|
|
case 19: return PCB_LAYER_ID::In18_Cu;
|
|
|
|
case 20: return PCB_LAYER_ID::In19_Cu;
|
|
|
|
case 21: return PCB_LAYER_ID::In20_Cu;
|
|
|
|
case 22: return PCB_LAYER_ID::In21_Cu;
|
|
|
|
case 23: return PCB_LAYER_ID::In22_Cu;
|
|
|
|
case 24: return PCB_LAYER_ID::In23_Cu;
|
|
|
|
case 25: return PCB_LAYER_ID::In24_Cu;
|
|
|
|
case 26: return PCB_LAYER_ID::In25_Cu;
|
|
|
|
case 27: return PCB_LAYER_ID::In26_Cu;
|
|
|
|
case 28: return PCB_LAYER_ID::In27_Cu;
|
|
|
|
case 29: return PCB_LAYER_ID::In28_Cu;
|
|
|
|
case 30: return PCB_LAYER_ID::In29_Cu;
|
|
|
|
case 31: return PCB_LAYER_ID::In30_Cu;
|
2020-09-06 17:00:02 +00:00
|
|
|
case 32: return PCB_LAYER_ID::B_Cu;
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
return PCB_LAYER_ID::UNDEFINED_LAYER;
|
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
bool CADSTAR_PCB_ARCHIVE_LOADER::isLayerSet( const LAYER_ID& aCadstarLayerID )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
wxCHECK( Assignments.Layerdefs.Layers.find( aCadstarLayerID )
|
|
|
|
!= Assignments.Layerdefs.Layers.end(),
|
|
|
|
false );
|
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
LAYER& layer = Assignments.Layerdefs.Layers.at( aCadstarLayerID );
|
|
|
|
|
|
|
|
switch( layer.Type )
|
|
|
|
{
|
|
|
|
case LAYER_TYPE::ALLDOC:
|
|
|
|
case LAYER_TYPE::ALLELEC:
|
|
|
|
case LAYER_TYPE::ALLLAYER:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
PCB_LAYER_ID CADSTAR_PCB_ARCHIVE_LOADER::getKiCadLayer( const LAYER_ID& aCadstarLayerID )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2021-10-09 19:06:56 +00:00
|
|
|
if( getLayerType( aCadstarLayerID ) == LAYER_TYPE::NOLAYER )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2021-10-09 19:06:56 +00:00
|
|
|
//The "no layer" is common for CADSTAR documentation symbols
|
|
|
|
//map it to undefined layer for later processing
|
|
|
|
return PCB_LAYER_ID::UNDEFINED_LAYER;
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
wxCHECK( m_layermap.find( aCadstarLayerID ) != m_layermap.end(),
|
|
|
|
PCB_LAYER_ID::UNDEFINED_LAYER );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
return m_layermap.at( aCadstarLayerID );
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
LSET CADSTAR_PCB_ARCHIVE_LOADER::getKiCadLayerSet( const LAYER_ID& aCadstarLayerID )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2021-10-09 19:06:56 +00:00
|
|
|
LAYER_TYPE layerType = getLayerType( aCadstarLayerID );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2021-10-09 19:06:56 +00:00
|
|
|
switch( layerType )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
|
|
|
case LAYER_TYPE::ALLDOC:
|
|
|
|
return LSET( 4, PCB_LAYER_ID::Dwgs_User, PCB_LAYER_ID::Cmts_User, PCB_LAYER_ID::Eco1_User,
|
|
|
|
PCB_LAYER_ID::Eco2_User );
|
|
|
|
|
|
|
|
case LAYER_TYPE::ALLELEC:
|
2021-10-09 19:06:56 +00:00
|
|
|
return LSET::AllCuMask( m_numCopperLayers );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
case LAYER_TYPE::ALLLAYER:
|
2021-10-09 19:06:56 +00:00
|
|
|
return LSET::AllLayersMask()
|
|
|
|
^ ( LSET::AllCuMask( m_numCopperLayers ) ^ LSET::AllCuMask( MAX_CU_LAYERS ) )
|
|
|
|
^ ( LSET( PCB_LAYER_ID::Rescue ) );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return LSET( getKiCadLayer( aCadstarLayerID ) );
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 21:20:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::addToGroup(
|
|
|
|
const GROUP_ID& aCadstarGroupID, BOARD_ITEM* aKiCadItem )
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
wxCHECK( m_groupMap.find( aCadstarGroupID ) != m_groupMap.end(), );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
PCB_GROUP* parentGroup = m_groupMap.at( aCadstarGroupID );
|
2020-09-06 21:20:32 +00:00
|
|
|
parentGroup->AddItem( aKiCadItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::GROUP_ID CADSTAR_PCB_ARCHIVE_LOADER::createUniqueGroupID(
|
|
|
|
const wxString& aName )
|
|
|
|
{
|
|
|
|
wxString groupName = aName;
|
|
|
|
int num = 0;
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
while( m_groupMap.find( groupName ) != m_groupMap.end() )
|
2020-09-06 21:20:32 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
groupName = aName + wxT( "_" ) + wxString::Format( wxT( "%i" ), ++num );
|
2020-09-06 21:20:32 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
PCB_GROUP* docSymGroup = new PCB_GROUP( m_board );
|
|
|
|
m_board->Add( docSymGroup );
|
2020-09-06 21:20:32 +00:00
|
|
|
docSymGroup->SetName( groupName );
|
|
|
|
GROUP_ID groupID( groupName );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_groupMap.insert( { groupID, docSymGroup } );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
|
|
|
return groupID;
|
|
|
|
}
|