2020-07-12 16:58:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-09-06 17:00:02 +00:00
|
|
|
* Copyright (C) 2020 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
|
2020-07-12 16:58:35 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
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>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <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>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <track.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>
|
|
|
|
|
|
|
|
#include <limits> // std::numeric_limits
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::Load( ::BOARD* aBoard )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-07-30 22:42:56 +00:00
|
|
|
mBoard = aBoard;
|
|
|
|
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
|
|
|
|
|
|
|
mDesignCenter =
|
|
|
|
( 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
|
|
|
|
|
|
|
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();
|
|
|
|
loadCoppers();
|
|
|
|
loadNets();
|
2020-08-28 20:32:53 +00:00
|
|
|
|
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-09-08 13:01:32 +00:00
|
|
|
wxLogWarning(
|
|
|
|
_( "The CADSTAR design contains variants which has no KiCad equivalent. All "
|
|
|
|
"components have been loaded on top of each other. " ) );
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-01 22:47:38 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::logBoardStackupWarning( const wxString& aCadstarLayerName,
|
|
|
|
const PCB_LAYER_ID& aKiCadLayer )
|
2020-08-30 12:23:25 +00:00
|
|
|
{
|
2020-10-01 22:47:38 +00:00
|
|
|
if( mLogLayerWarnings )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if( mLogLayerWarnings )
|
|
|
|
{
|
|
|
|
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-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadBoardStackup()
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-09-19 22:05:02 +00:00
|
|
|
std::map<LAYER_ID, LAYER>& cpaLayers = Assignments.Layerdefs.Layers;
|
|
|
|
std::map<MATERIAL_ID, MATERIAL>& cpaMaterials = Assignments.Layerdefs.Materials;
|
|
|
|
std::vector<LAYER_ID>& cpaLayerStack = Assignments.Layerdefs.LayerStack;
|
|
|
|
unsigned numElecAndPowerLayers = 0;
|
|
|
|
BOARD_DESIGN_SETTINGS& designSettings = mBoard->GetDesignSettings();
|
|
|
|
BOARD_STACKUP& stackup = designSettings.GetStackupDescriptor();
|
|
|
|
int noOfKiCadStackupLayers = 0;
|
2020-07-30 22:42:56 +00:00
|
|
|
int lastElectricalLayerIndex = 0;
|
|
|
|
int dielectricSublayer = 0;
|
|
|
|
int numDielectricLayers = 0;
|
|
|
|
bool prevWasDielectric = false;
|
2020-09-16 10:27:15 +00:00
|
|
|
BOARD_STACKUP_ITEM* tempKiCadLayer = nullptr;
|
2020-07-30 22:42:56 +00:00
|
|
|
std::vector<PCB_LAYER_ID> layerIDs;
|
2020-07-12 16:58:35 +00:00
|
|
|
|
|
|
|
//Remove all layers except required ones
|
|
|
|
stackup.RemoveAll();
|
|
|
|
layerIDs.push_back( PCB_LAYER_ID::F_CrtYd );
|
|
|
|
layerIDs.push_back( PCB_LAYER_ID::B_CrtYd );
|
|
|
|
layerIDs.push_back( PCB_LAYER_ID::Margin );
|
|
|
|
layerIDs.push_back( PCB_LAYER_ID::Edge_Cuts );
|
|
|
|
designSettings.SetEnabledLayers( LSET( &layerIDs[0], layerIDs.size() ) );
|
|
|
|
|
|
|
|
for( auto it = cpaLayerStack.begin(); it != cpaLayerStack.end(); ++it )
|
|
|
|
{
|
|
|
|
BOARD_STACKUP_ITEM_TYPE kicadLayerType = BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_UNDEFINED;
|
|
|
|
LAYER_T copperType = LAYER_T::LT_UNDEFINED;
|
|
|
|
PCB_LAYER_ID kicadLayerID = PCB_LAYER_ID::UNDEFINED_LAYER;
|
|
|
|
wxString layerTypeName = wxEmptyString;
|
|
|
|
|
2020-10-19 17:11:52 +00:00
|
|
|
if( cpaLayers.find( *it ) == cpaLayers.end() )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt: The layer "
|
|
|
|
"stack refers to layer ID '%s' which does not exist in the layer "
|
|
|
|
"definitions." ) );
|
|
|
|
}
|
2020-11-02 19:23:01 +00:00
|
|
|
|
2020-10-19 17:11:52 +00:00
|
|
|
LAYER curLayer = cpaLayers.at( *it );
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
if( prevWasDielectric && ( curLayer.Type != LAYER_TYPE::CONSTRUCTION ) )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
|
|
|
stackup.Add( tempKiCadLayer ); //only add dielectric layers here after all are done
|
|
|
|
dielectricSublayer = 0;
|
|
|
|
prevWasDielectric = false;
|
|
|
|
noOfKiCadStackupLayers++;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-09-19 22:05:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "Unexpected layer '%s' in layer stack." ), curLayer.Name ) );
|
2020-09-16 10:27:15 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_TYPE::JUMPERLAYER:
|
2020-07-12 16:58:35 +00:00
|
|
|
copperType = LAYER_T::LT_JUMPER;
|
2020-08-16 17:12:08 +00:00
|
|
|
kicadLayerID = getKiCadCopperLayerID( ++numElecAndPowerLayers );
|
2020-07-12 16:58:35 +00:00
|
|
|
kicadLayerType = BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_COPPER;
|
|
|
|
layerTypeName = KEY_COPPER;
|
|
|
|
break;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_TYPE::ELEC:
|
2020-07-12 16:58:35 +00:00
|
|
|
copperType = LAYER_T::LT_SIGNAL;
|
2020-08-16 17:12:08 +00:00
|
|
|
kicadLayerID = getKiCadCopperLayerID( ++numElecAndPowerLayers );
|
2020-07-12 16:58:35 +00:00
|
|
|
kicadLayerType = BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_COPPER;
|
|
|
|
layerTypeName = KEY_COPPER;
|
|
|
|
break;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_TYPE::POWER:
|
2020-07-12 16:58:35 +00:00
|
|
|
copperType = LAYER_T::LT_POWER;
|
2020-08-16 17:12:08 +00:00
|
|
|
kicadLayerID = getKiCadCopperLayerID( ++numElecAndPowerLayers );
|
2020-07-12 16:58:35 +00:00
|
|
|
kicadLayerType = BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_COPPER;
|
|
|
|
layerTypeName = KEY_COPPER;
|
2020-08-31 22:09:29 +00:00
|
|
|
mPowerPlaneLayers.push_back( curLayer.ID ); //we will need to add a Copper zone
|
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::CONSTRUCTION:
|
2020-07-12 16:58:35 +00:00
|
|
|
kicadLayerID = PCB_LAYER_ID::UNDEFINED_LAYER;
|
|
|
|
kicadLayerType = BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_DIELECTRIC;
|
|
|
|
prevWasDielectric = true;
|
|
|
|
layerTypeName = KEY_PREPREG;
|
|
|
|
//TODO handle KEY_CORE and KEY_PREPREG
|
2020-08-23 10:34:27 +00:00
|
|
|
//will need to look at CADSTAR layer embedding (see LAYER->Embedding) to
|
2020-07-12 16:58:35 +00:00
|
|
|
//check electrical layers above and below to decide if current layer is prepreg
|
|
|
|
// or core
|
|
|
|
break;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_TYPE::DOC:
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::Dwgs_User;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::Cmts_User;
|
|
|
|
|
2020-08-30 12:23:25 +00:00
|
|
|
logBoardStackupWarning( curLayer.Name, kicadLayerID );
|
|
|
|
//TODO: allow user to decide which layer this should be mapped onto.
|
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-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::B_Fab;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::F_Fab;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_PLACEMENT:
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
if( numElecAndPowerLayers > 0 )
|
2020-08-23 10:34:27 +00:00
|
|
|
kicadLayerID = PCB_LAYER_ID::B_CrtYd;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::F_CrtYd;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_NONE:
|
|
|
|
|
|
|
|
if( curLayer.Name.Lower().Contains( "glue" )
|
|
|
|
|| curLayer.Name.Lower().Contains( "adhesive" ) )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-08-23 10:34:27 +00:00
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::B_Adhes;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::F_Adhes;
|
2020-08-30 12:23:25 +00:00
|
|
|
|
2020-10-01 22:47:38 +00:00
|
|
|
logBoardStackupMessage( curLayer.Name, kicadLayerID );
|
|
|
|
}
|
|
|
|
else if( curLayer.Name.Lower().Contains( "silk" )
|
|
|
|
|| curLayer.Name.Lower().Contains( "legend" ) )
|
|
|
|
{
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::B_SilkS;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::F_SilkS;
|
|
|
|
|
|
|
|
logBoardStackupMessage( curLayer.Name, kicadLayerID );
|
|
|
|
}
|
|
|
|
else if( curLayer.Name.Lower().Contains( "assembly" )
|
|
|
|
|| curLayer.Name.Lower().Contains( "fabrication" ) )
|
|
|
|
{
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::B_Fab;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::F_Fab;
|
|
|
|
|
|
|
|
logBoardStackupMessage( curLayer.Name, kicadLayerID );
|
|
|
|
}
|
|
|
|
else if( curLayer.Name.Lower().Contains( "resist" )
|
|
|
|
|| curLayer.Name.Lower().Contains( "mask" ) )
|
|
|
|
{
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::B_Mask;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::F_Mask;
|
|
|
|
|
|
|
|
logBoardStackupMessage( curLayer.Name, kicadLayerID );
|
|
|
|
}
|
|
|
|
else if( curLayer.Name.Lower().Contains( "paste" ) )
|
|
|
|
{
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::B_Paste;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::F_Paste;
|
|
|
|
|
|
|
|
logBoardStackupMessage( curLayer.Name, kicadLayerID );
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
|
|
|
else
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::Eco2_User;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::Eco1_User;
|
2020-08-30 12:23:25 +00:00
|
|
|
|
|
|
|
logBoardStackupWarning( curLayer.Name, kicadLayerID );
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_PASTE:
|
|
|
|
kicadLayerType = BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_SOLDERPASTE;
|
|
|
|
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
|
|
|
kicadLayerID = PCB_LAYER_ID::B_Paste;
|
|
|
|
layerTypeName = _HKI( "Bottom Solder Paste" );
|
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
kicadLayerID = PCB_LAYER_ID::F_Paste;
|
|
|
|
layerTypeName = _HKI( "Top Solder Paste" );
|
|
|
|
}
|
|
|
|
|
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-07-12 16:58:35 +00:00
|
|
|
kicadLayerType = BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_SILKSCREEN;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
if( numElecAndPowerLayers > 0 )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-08-23 10:34:27 +00:00
|
|
|
kicadLayerID = PCB_LAYER_ID::B_SilkS;
|
|
|
|
layerTypeName = _HKI( "Bottom Silk Screen" );
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-23 10:34:27 +00:00
|
|
|
kicadLayerID = PCB_LAYER_ID::F_SilkS;
|
|
|
|
layerTypeName = _HKI( "Top Silk Screen" );
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
|
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-07-12 16:58:35 +00:00
|
|
|
kicadLayerType = BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_SOLDERMASK;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
if( numElecAndPowerLayers > 0 )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-08-23 10:34:27 +00:00
|
|
|
kicadLayerID = PCB_LAYER_ID::B_Mask;
|
|
|
|
layerTypeName = _HKI( "Bottom Solder Mask" );
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-23 10:34:27 +00:00
|
|
|
kicadLayerID = PCB_LAYER_ID::F_Mask;
|
|
|
|
layerTypeName = _HKI( "Top Solder Mask" );
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
|
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:
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::Eco2_User;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::Eco1_User;
|
|
|
|
|
|
|
|
logBoardStackupWarning( curLayer.Name, kicadLayerID );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_SUBTYPE::LAYERSUBTYPE_CLEARANCE:
|
|
|
|
if( numElecAndPowerLayers > 0 )
|
|
|
|
kicadLayerID = PCB_LAYER_ID::Eco2_User;
|
|
|
|
else
|
|
|
|
kicadLayerID = PCB_LAYER_ID::Eco1_User;
|
|
|
|
|
|
|
|
logBoardStackupWarning( curLayer.Name, kicadLayerID );
|
|
|
|
break;
|
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
default:
|
2020-10-19 17:11:52 +00:00
|
|
|
wxFAIL_MSG( "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:
|
2020-10-19 17:11:52 +00:00
|
|
|
wxFAIL_MSG( "Unknown CADSTAR Layer Type" );
|
2020-07-12 16:58:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
mLayermap.insert( std::make_pair( curLayer.ID, kicadLayerID ) );
|
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
if( dielectricSublayer == 0 )
|
|
|
|
tempKiCadLayer = new BOARD_STACKUP_ITEM( kicadLayerType );
|
|
|
|
|
|
|
|
tempKiCadLayer->SetLayerName( curLayer.Name );
|
|
|
|
tempKiCadLayer->SetBrdLayerId( kicadLayerID );
|
|
|
|
|
|
|
|
if( prevWasDielectric )
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( kicadLayerID == PCB_LAYER_ID::UNDEFINED_LAYER,
|
|
|
|
wxT( "Error Processing Dielectric Layer. "
|
|
|
|
"Expected to have undefined layer type" ) );
|
|
|
|
|
|
|
|
if( dielectricSublayer == 0 )
|
|
|
|
tempKiCadLayer->SetDielectricLayerId( ++numDielectricLayers );
|
|
|
|
else
|
|
|
|
tempKiCadLayer->AddDielectricPrms( dielectricSublayer );
|
|
|
|
}
|
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
if( curLayer.MaterialId != UNDEFINED_MATERIAL_ID )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
|
|
|
tempKiCadLayer->SetMaterial(
|
|
|
|
cpaMaterials[curLayer.MaterialId].Name, dielectricSublayer );
|
|
|
|
tempKiCadLayer->SetEpsilonR( cpaMaterials[curLayer.MaterialId].Permittivity.GetDouble(),
|
|
|
|
dielectricSublayer );
|
|
|
|
tempKiCadLayer->SetLossTangent(
|
|
|
|
cpaMaterials[curLayer.MaterialId].LossTangent.GetDouble(), dielectricSublayer );
|
|
|
|
//TODO add Resistivity when KiCad supports it
|
|
|
|
}
|
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
tempKiCadLayer->SetThickness(
|
|
|
|
curLayer.Thickness * KiCadUnitMultiplier, dielectricSublayer );
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
if( layerTypeName != wxEmptyString )
|
|
|
|
tempKiCadLayer->SetTypeName( layerTypeName );
|
2020-07-12 16:58:35 +00:00
|
|
|
|
|
|
|
if( !prevWasDielectric )
|
|
|
|
{
|
|
|
|
stackup.Add( tempKiCadLayer ); //only add non-dielectric layers here
|
|
|
|
++noOfKiCadStackupLayers;
|
|
|
|
layerIDs.push_back( tempKiCadLayer->GetBrdLayerId() );
|
|
|
|
designSettings.SetEnabledLayers( LSET( &layerIDs[0], layerIDs.size() ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++dielectricSublayer;
|
|
|
|
|
|
|
|
if( copperType != LAYER_T::LT_UNDEFINED )
|
|
|
|
{
|
|
|
|
wxASSERT( mBoard->SetLayerType( tempKiCadLayer->GetBrdLayerId(),
|
|
|
|
copperType ) ); //move to outside, need to enable layer in board first
|
|
|
|
lastElectricalLayerIndex = noOfKiCadStackupLayers - 1;
|
|
|
|
wxASSERT( mBoard->SetLayerName(
|
|
|
|
tempKiCadLayer->GetBrdLayerId(), tempKiCadLayer->GetLayerName() ) );
|
|
|
|
//TODO set layer names for other CADSTAR layers when KiCad supports custom
|
|
|
|
//layer names on non-copper layers
|
2020-07-18 09:04:22 +00:00
|
|
|
mCopperLayers.insert( std::make_pair( curLayer.PhysicalLayer, curLayer.ID ) );
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//change last copper layer to be B_Cu instead of an inner layer
|
2020-08-23 10:34:27 +00:00
|
|
|
LAYER_ID cadstarlastElecLayer = mCopperLayers.rbegin()->second;
|
2020-10-06 12:46:15 +00:00
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
PCB_LAYER_ID lastElecBrdId =
|
|
|
|
stackup.GetStackupLayer( lastElectricalLayerIndex )->GetBrdLayerId();
|
2020-10-06 12:46:15 +00:00
|
|
|
|
|
|
|
layerIDs.erase(
|
|
|
|
std::remove( layerIDs.begin(), layerIDs.end(), lastElecBrdId ), layerIDs.end() );
|
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
layerIDs.push_back( PCB_LAYER_ID::B_Cu );
|
|
|
|
tempKiCadLayer = stackup.GetStackupLayer( lastElectricalLayerIndex );
|
|
|
|
tempKiCadLayer->SetBrdLayerId( PCB_LAYER_ID::B_Cu );
|
2020-10-06 12:46:15 +00:00
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
wxASSERT( mBoard->SetLayerName(
|
|
|
|
tempKiCadLayer->GetBrdLayerId(), tempKiCadLayer->GetLayerName() ) );
|
2020-10-06 12:46:15 +00:00
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
mLayermap.at( cadstarlastElecLayer ) = PCB_LAYER_ID::B_Cu;
|
2020-07-12 16:58:35 +00:00
|
|
|
|
|
|
|
//make all layers enabled and visible
|
|
|
|
mBoard->SetEnabledLayers( LSET( &layerIDs[0], layerIDs.size() ) );
|
|
|
|
mBoard->SetVisibleLayers( LSET( &layerIDs[0], layerIDs.size() ) );
|
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
mBoard->SetCopperLayerCount( numElecAndPowerLayers );
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-01 22:47:38 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::remapUnsureLayers()
|
|
|
|
{
|
|
|
|
LSET enabledLayers = mBoard->GetEnabledLayers();
|
|
|
|
LSET validRemappingLayers = enabledLayers | LSET::AllBoardTechMask() |
|
|
|
|
LSET::UserMask() | LSET::UserDefinedLayers();
|
|
|
|
|
|
|
|
std::vector<INPUT_LAYER_DESC> inputLayers;
|
|
|
|
std::map<wxString, LAYER_ID> cadstarLayerNameMap;
|
|
|
|
|
|
|
|
for( std::pair<LAYER_ID, PCB_LAYER_ID> layerPair : mLayermap )
|
|
|
|
{
|
|
|
|
LAYER* curLayer = &Assignments.Layerdefs.Layers.at( layerPair.first );
|
|
|
|
|
|
|
|
//Only remap layers that we aren't sure about
|
|
|
|
if( curLayer->Type == LAYER_TYPE::DOC
|
|
|
|
|| ( curLayer->Type == LAYER_TYPE::NONELEC
|
2020-10-26 21:15:24 +00:00
|
|
|
&& curLayer->SubType == LAYER_SUBTYPE::LAYERSUBTYPE_NONE )
|
|
|
|
|| ( curLayer->Type == LAYER_TYPE::NONELEC
|
|
|
|
&& curLayer->SubType == LAYER_SUBTYPE::LAYERSUBTYPE_ROUT )
|
|
|
|
|| ( curLayer->Type == LAYER_TYPE::NONELEC
|
|
|
|
&& curLayer->SubType == LAYER_SUBTYPE::LAYERSUBTYPE_CLEARANCE ) )
|
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:
|
2020-10-09 16:58:21 +00:00
|
|
|
std::map<wxString, PCB_LAYER_ID> reMappedLayers = mLayerMappingHandler( 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 )
|
|
|
|
{
|
2020-10-19 17:11:52 +00:00
|
|
|
wxFAIL_MSG( "Unexpected Layer ID" );
|
2020-10-01 22:47:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
LAYER_ID cadstarLayerID = cadstarLayerNameMap.at( layerPair.first );
|
|
|
|
mLayermap.at( cadstarLayerID ) = layerPair.second;
|
|
|
|
enabledLayers |= LSET( layerPair.second );
|
|
|
|
}
|
|
|
|
|
|
|
|
mBoard->SetEnabledLayers( enabledLayers );
|
|
|
|
mBoard->SetVisibleLayers( enabledLayers );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-02 18:35:12 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadDesignRules()
|
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& ds = mBoard->GetDesignSettings();
|
|
|
|
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
|
|
|
|
|
|
|
|
applyRule( "T_T", &ds.m_MinClearance );
|
|
|
|
applyRule( "C_B", &ds.m_CopperEdgeClearance );
|
2020-09-14 08:02:07 +00:00
|
|
|
applyRule( "H_H", &ds.m_HoleToHoleMin );
|
2020-09-02 18:35:12 +00:00
|
|
|
|
|
|
|
ds.m_TrackMinWidth = Assignments.Technology.MinRouteWidth;
|
|
|
|
|
2020-09-27 13:10:59 +00:00
|
|
|
auto applyNetClassRule = [&]( wxString aID, ::NETCLASS* aNetClassPtr,
|
|
|
|
void ( ::NETCLASS::*aFunc )( int ) ) {
|
|
|
|
int value = -1;
|
|
|
|
applyRule( aID, &value );
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2020-09-27 13:10:59 +00:00
|
|
|
if( value != -1 )
|
|
|
|
( aNetClassPtr->*aFunc )( value );
|
|
|
|
};
|
2020-09-02 18:35:12 +00:00
|
|
|
|
|
|
|
applyNetClassRule( "T_T", ds.GetDefault(), &::NETCLASS::SetClearance );
|
|
|
|
|
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." ) );
|
|
|
|
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( "" ) );
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = new FOOTPRINT( mBoard );
|
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-11-13 11:17:15 +00:00
|
|
|
libID.Parse( fpName, LIB_ID::LIB_ID_TYPE::ID_PCB, true );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetFPID( libID );
|
|
|
|
loadLibraryFigures( component, footprint );
|
|
|
|
loadLibraryCoppers( component, footprint );
|
|
|
|
loadLibraryAreas( component, footprint );
|
|
|
|
loadLibraryPads( component, footprint );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
mLibraryMap.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 ),
|
|
|
|
wxString::Format( "Component %s:%s -> Figure %s",
|
|
|
|
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
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadLibraryCoppers( const SYMDEF_PCB& aComponent, FOOTPRINT* aFootprint )
|
2020-09-08 17:35:06 +00:00
|
|
|
{
|
|
|
|
for( COMPONENT_COPPER compCopper : aComponent.ComponentCoppers )
|
|
|
|
{
|
|
|
|
int lineThickness = getKiCadLength( getCopperCode( compCopper.CopperCodeID ).CopperWidth );
|
|
|
|
|
|
|
|
drawCadstarShape( compCopper.Shape, getKiCadLayer( compCopper.LayerID ), lineThickness,
|
2020-11-13 01:12:36 +00:00
|
|
|
wxString::Format( "Component %s:%s -> Copper element",
|
|
|
|
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 )
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = getZoneFromCadstarShape( area.Shape, getLineThickness( area.LineCodeID ),
|
2020-11-13 01:12:36 +00:00
|
|
|
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 "
|
|
|
|
"have a KiCad equivalent. The area is neither a via or"
|
|
|
|
"route keepout area. The area was not imported. " ),
|
|
|
|
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
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
PAD* pad = getKiCadPad( padPair.second, aFootprint );
|
|
|
|
aFootprint->Add( pad, ADD_MODE::INSERT ); // insert 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 );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = new PAD( aParent );
|
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
|
|
|
|
pad->SetAttribute( PAD_ATTR_T::PAD_ATTRIB_SMD );
|
|
|
|
pad->SetLayerSet( LSET( 3, B_Cu, B_Paste, B_Mask ) );
|
|
|
|
break;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
case PAD_SIDE::MINIMUM: //TOP side
|
|
|
|
pad->SetAttribute( PAD_ATTR_T::PAD_ATTRIB_SMD );
|
|
|
|
pad->SetLayerSet( LSET( 3, F_Cu, F_Paste, F_Mask ) );
|
|
|
|
break;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
case PAD_SIDE::THROUGH_HOLE:
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
if( csPadcode.Plated )
|
|
|
|
pad->SetAttribute( PAD_ATTR_T::PAD_ATTRIB_PTH );
|
|
|
|
else
|
|
|
|
pad->SetAttribute( PAD_ATTR_T::PAD_ATTRIB_NPTH );
|
2020-09-05 15:31:57 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetLayerSet( pad->PTHMask() ); // for now we will assume no paste layers
|
|
|
|
//TODO: We need to read the csPad->Reassigns vector to make sure no paste
|
|
|
|
break;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "Unknown Pad type" );
|
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetName( 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 )
|
|
|
|
// zero sized pads seems to break KiCad so lets make it very small instead
|
|
|
|
csPadcode.Shape.Size = 1;
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-24 23:40:26 +00:00
|
|
|
wxPoint padOffset = { 0, 0 }; // offset of the pad origin (before rotating)
|
|
|
|
wxPoint drillOffset = { 0, 0 }; // offset of the drill origin w.r.t. the pad (before rotating)
|
|
|
|
|
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)
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_CIRCLE );
|
|
|
|
pad->SetSize( { getKiCadLength( csPadcode.Shape.Size ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TYPE::BULLET:
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_CHAMFERED_RECT );
|
|
|
|
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:
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_CIRCLE );
|
|
|
|
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);
|
2020-10-24 17:02:44 +00:00
|
|
|
pad->SetShape( PAD_SHAPE_T::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:
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_OVAL );
|
|
|
|
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:
|
|
|
|
pad->SetShape( PAD_SHAPE_CHAMFERED_RECT );
|
|
|
|
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:
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_RECT );
|
|
|
|
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:
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_RECT );
|
|
|
|
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:
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_RECT );
|
|
|
|
pad->SetSize( { getKiCadLength( csPadcode.Shape.Size ),
|
|
|
|
getKiCadLength( csPadcode.Shape.Size ) } );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "Unknown Pad Shape" );
|
|
|
|
}
|
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 );
|
2020-10-25 23:28:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 19:23:01 +00:00
|
|
|
|
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 );
|
|
|
|
int maxError = mBoard->GetDesignSettings().m_MaxError;
|
|
|
|
|
|
|
|
pad->SetPosition( { 0, 0 } );
|
|
|
|
pad->SetPos0( { 0, 0 } );
|
|
|
|
pad->TransformShapeWithClearanceToPolygon( padOutline, layer, 0, maxError,
|
|
|
|
ERROR_LOC::ERROR_INSIDE );
|
|
|
|
|
|
|
|
PCB_SHAPE* padShape = new PCB_SHAPE;
|
2020-11-14 01:16:02 +00:00
|
|
|
padShape->SetShape( S_POLYGON );
|
|
|
|
padShape->SetFilled( true );
|
2020-10-25 23:28:04 +00:00
|
|
|
padShape->SetPolyShape( padOutline );
|
|
|
|
padShape->SetWidth( 0 );
|
|
|
|
padShape->Move( padOffset - drillOffset );
|
|
|
|
padShape->Rotate( wxPoint( 0, 0 ), 1800.0 - getAngleTenthDegree( csPadcode.SlotOrientation ) );
|
|
|
|
|
|
|
|
|
|
|
|
SHAPE_POLY_SET editedPadOutline = padShape->GetPolyShape();
|
|
|
|
|
|
|
|
if( editedPadOutline.Contains( { 0, 0 } ) )
|
2020-11-02 19:23:01 +00:00
|
|
|
{
|
2020-10-25 23:28:04 +00:00
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE_T::PAD_SHAPE_RECT );
|
|
|
|
pad->SetSize( wxSize( { 4, 4 } ) );
|
|
|
|
pad->SetShape( PAD_SHAPE_T::PAD_SHAPE_CUSTOM );
|
|
|
|
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 };
|
|
|
|
|
|
|
|
if( mPadcodesTested.find( csPadcode.ID ) == mPadcodesTested.end() )
|
|
|
|
{
|
|
|
|
wxLogError( 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 ) );
|
|
|
|
|
|
|
|
mPadcodesTested.insert( csPadcode.ID );
|
|
|
|
}
|
|
|
|
}
|
2020-10-24 23:40:26 +00:00
|
|
|
|
2020-10-25 23:28:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( "No copper layers defined in the pad?" );
|
|
|
|
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
|
|
|
|
|
|
|
double padOrientation = getAngleTenthDegree( aCadstarPad.OrientAngle )
|
|
|
|
+ getAngleTenthDegree( csPadcode.Shape.OrientAngle );
|
|
|
|
|
|
|
|
RotatePoint( &padOffset, padOrientation );
|
|
|
|
RotatePoint( &drillOffset, padOrientation );
|
|
|
|
pad->SetPos0( getKiCadPoint( aCadstarPad.Position ) - aParent->GetPosition() - padOffset
|
|
|
|
- drillOffset );
|
2020-10-25 23:28:04 +00:00
|
|
|
pad->SetOrientation( padOrientation + getAngleTenthDegree( 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
|
|
|
|
|
|
|
|
return pad;
|
2020-08-28 20:32:53 +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;
|
|
|
|
|
|
|
|
PCB_GROUP* kiGroup = new PCB_GROUP( mBoard );
|
|
|
|
|
|
|
|
mBoard->Add( kiGroup );
|
|
|
|
kiGroup->SetName( csGroup.Name );
|
|
|
|
kiGroup->SetLocked( csGroup.Fixed );
|
|
|
|
|
|
|
|
mGroupMap.insert( { csGroup.ID, kiGroup } );
|
|
|
|
}
|
|
|
|
|
|
|
|
//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() )
|
|
|
|
{
|
|
|
|
if( mGroupMap.find( csGroup.ID ) == mGroupMap.end() )
|
2020-09-16 10:27:15 +00:00
|
|
|
{
|
2020-09-06 21:20:32 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "The file appears to be corrupt. Unable to find group ID %s "
|
|
|
|
"in the group definitions." ),
|
|
|
|
csGroup.ID ) );
|
2020-09-16 10:27:15 +00:00
|
|
|
}
|
2020-09-06 21:20:32 +00:00
|
|
|
else if( mGroupMap.find( csGroup.ID ) == mGroupMap.end() )
|
2020-09-16 10:27:15 +00:00
|
|
|
{
|
2020-09-06 21:20:32 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "The file appears to be corrupt. 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
|
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
PCB_GROUP* kiCadGroup = mGroupMap.at( csGroup.ID );
|
2020-09-06 21:20:32 +00:00
|
|
|
PCB_GROUP* parentGroup = mGroupMap.at( csGroup.GroupID );
|
|
|
|
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
|
|
|
{
|
|
|
|
for( std::pair<BOARD_ID, BOARD> boardPair : Layout.Boards )
|
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
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,
|
|
|
|
getLineThickness( board.LineCodeID ), wxString::Format( "BOARD %s", board.ID ),
|
|
|
|
mBoard, 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 ),
|
|
|
|
getLineThickness( fig.LineCodeID ), wxString::Format( "FIGURE %s", fig.ID ), mBoard,
|
|
|
|
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;
|
2020-09-05 15:31:57 +00:00
|
|
|
drawCadstarText( csTxt, mBoard );
|
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 )
|
|
|
|
{
|
|
|
|
case DIMENSION::SUBTYPE::DIRECT:
|
|
|
|
case DIMENSION::SUBTYPE::ORTHOGONAL:
|
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
::ALIGNED_DIMENSION* dimension = new ::ALIGNED_DIMENSION( mBoard );
|
|
|
|
TEXTCODE dimText = getTextCode( csDim.Text.TextCodeID );
|
2020-09-06 22:16:02 +00:00
|
|
|
mBoard->Add( dimension, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
dimension->SetLayer( getKiCadLayer( csDim.LayerID ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetPrecision( csDim.Precision );
|
|
|
|
dimension->SetStart( getKiCadPoint( csDim.Line.Start ) );
|
|
|
|
dimension->SetEnd( getKiCadPoint( csDim.Line.End ) );
|
2020-09-06 22:16:02 +00:00
|
|
|
dimension->Text().SetTextThickness( getKiCadLength( dimText.LineWidth ) );
|
|
|
|
dimension->Text().SetTextSize( wxSize(
|
|
|
|
getKiCadLength( dimText.Width ), getKiCadLength( dimText.Height ) ) );
|
|
|
|
|
2020-10-13 23:41:16 +00:00
|
|
|
if( csDim.LinearUnits == UNITS::DESIGN )
|
|
|
|
{
|
|
|
|
csDim.LinearUnits = Assignments.Technology.Units;
|
|
|
|
}
|
|
|
|
|
2020-09-06 22:16:02 +00:00
|
|
|
switch( csDim.LinearUnits )
|
|
|
|
{
|
|
|
|
case UNITS::METER:
|
|
|
|
case UNITS::CENTIMETER:
|
|
|
|
case UNITS::MM:
|
|
|
|
case UNITS::MICROMETRE:
|
2020-10-02 20:51:24 +00:00
|
|
|
dimension->SetUnits( EDA_UNITS::MILLIMETRES );
|
2020-09-06 22:16:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNITS::INCH:
|
2020-10-02 20:51:24 +00:00
|
|
|
dimension->SetUnits( EDA_UNITS::INCHES );
|
2020-09-06 22:16:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNITS::THOU:
|
2020-10-02 22:04:16 +00:00
|
|
|
dimension->SetUnits( EDA_UNITS::MILS );
|
2020-09-06 22:16:02 +00:00
|
|
|
break;
|
2020-10-13 23:41:16 +00:00
|
|
|
|
|
|
|
case UNITS::DESIGN:
|
2020-10-19 17:11:52 +00:00
|
|
|
wxFAIL_MSG( "DESIGN units requested - this should not happen." );
|
2020-10-13 23:41:16 +00:00
|
|
|
break;
|
|
|
|
|
2020-09-06 22:16:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default: //all others
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "Dimension ID %s has no KiCad equivalent. This was not imported" ),
|
|
|
|
csDim.ID ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIMENSION::TYPE::ANGLEDIM:
|
|
|
|
case DIMENSION::TYPE::LEADERDIM:
|
|
|
|
default:
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "Dimension ID %s has no KiCad equivalent. This was not imported" ),
|
|
|
|
csDim.ID ) );
|
|
|
|
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
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = getZoneFromCadstarShape( area.Shape, getLineThickness( area.LineCodeID ),
|
|
|
|
mBoard );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
mBoard->Add( zone, ADD_MODE::APPEND );
|
|
|
|
|
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 )
|
2020-08-23 10:34:27 +00:00
|
|
|
wxLogWarning( wxString::Format(
|
2020-10-13 22:35:09 +00:00
|
|
|
_( "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." ),
|
2020-08-23 10:34:27 +00:00
|
|
|
area.Name ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-28 20:32:53 +00:00
|
|
|
wxLogError(
|
|
|
|
wxString::Format( _( "The CADSTAR area '%s' does not have a KiCad equivalent. "
|
2020-10-13 22:35:09 +00:00
|
|
|
"Pure Placement areas are not supported." ),
|
2020-08-28 20:32:53 +00:00
|
|
|
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 )
|
|
|
|
{
|
|
|
|
COMPONENT& comp = compPair.second;
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
auto fpIter = mLibraryMap.find( comp.SymdefID );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
if( fpIter == mLibraryMap.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')" ),
|
|
|
|
comp.Name, comp.SymdefID ) );
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// copy constructor to clone the footprint from the library
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = new FOOTPRINT( *fpIter->second );
|
2020-11-13 11:17:15 +00:00
|
|
|
const_cast<KIID&>( footprint->m_Uuid ) = KIID();
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
mBoard->Add( footprint, ADD_MODE::APPEND );
|
2020-08-28 20:32:53 +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
|
|
|
|
|
|
|
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
|
|
|
|
PAD* kiPad = footprint->Pads().at( padEx.ID - (long) 1 );
|
2020-11-02 19:23:01 +00:00
|
|
|
|
2020-10-24 17:02:44 +00:00
|
|
|
if( kiPad )
|
|
|
|
delete kiPad;
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Pads().at( padEx.ID - (long) 1 ) = getKiCadPad( csPad, footprint );
|
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 ) );
|
|
|
|
footprint->SetOrientation( getAngleTenthDegree( comp.OrientAngle ) );
|
|
|
|
footprint->SetReference( comp.Name );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
if( comp.Mirror )
|
|
|
|
{
|
2020-10-18 16:41:17 +00:00
|
|
|
double mirroredAngle = - getAngleTenthDegree( comp.OrientAngle );
|
|
|
|
NORMALIZE_ANGLE_180( mirroredAngle );
|
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
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
mComponentMap.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;
|
|
|
|
wxPoint 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;
|
2020-09-05 15:31:57 +00:00
|
|
|
wxPoint centreOfTransform = getKiCadPoint( docSymDefinition.Origin );
|
|
|
|
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 ),
|
2020-09-05 15:31:57 +00:00
|
|
|
wxString::Format( "DOCUMENTATION SYMBOL %s, FIGURE %s",
|
|
|
|
docSymDefinition.ReferenceName, fig.ID ),
|
2020-09-08 17:35:06 +00:00
|
|
|
mBoard, 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;
|
2020-09-10 20:58:20 +00:00
|
|
|
drawCadstarText( txt, mBoard, groupID, docSymInstance.LayerID, moveVector,
|
|
|
|
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;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = getZoneFromCadstarShape( csTemplate.Shape,
|
|
|
|
getLineThickness( csTemplate.LineCodeID ), mBoard );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
mBoard->Add( zone, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
zone->SetZoneName( csTemplate.Name );
|
|
|
|
zone->SetLayer( getKiCadLayer( csTemplate.LayerID ) );
|
|
|
|
|
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 )
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "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 ) );
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.BoxIsolatedPins )
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "The CADSTAR template '%s' has the setting 'Box Isolated Pins'"
|
|
|
|
"enabled. This setting has no KiCad equivalent, so it has been ignored." ),
|
|
|
|
csTemplate.Name ) );
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.AutomaticRepour )
|
|
|
|
wxLogWarning( wxString::Format(
|
|
|
|
_( "The CADSTAR template '%s' has the setting 'Automatic Repour'"
|
|
|
|
"enabled. This setting has no KiCad equivalent, so it has been ignored." ),
|
|
|
|
csTemplate.Name ) );
|
|
|
|
|
|
|
|
// 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 )
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "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 ) );
|
|
|
|
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.MinIsolatedCopper != csTemplate.Pouring.MinDisjointCopper )
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "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 ) );
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.MinDisjointCopper < 0 )
|
|
|
|
zone->SetMinIslandArea( -1 );
|
|
|
|
else
|
|
|
|
zone->SetMinIslandArea(
|
|
|
|
(long long) getKiCadLength( csTemplate.Pouring.MinDisjointCopper )
|
|
|
|
* (long long) getKiCadLength( csTemplate.Pouring.MinDisjointCopper ) );
|
|
|
|
|
2020-09-06 15:24:40 +00:00
|
|
|
zone->SetLocalClearance( getKiCadLength( csTemplate.Pouring.AdditionalIsolation ) );
|
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 ) );
|
|
|
|
zone->SetHatchOrientation( getHatchCodeAngleDegrees( csTemplate.Pouring.HatchCodeID ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.ThermalReliefOnPads != csTemplate.Pouring.ThermalReliefOnVias
|
|
|
|
|| csTemplate.Pouring.ThermalReliefPadsAngle
|
|
|
|
!= csTemplate.Pouring.ThermalReliefViasAngle )
|
|
|
|
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 ) );
|
|
|
|
|
|
|
|
if( csTemplate.Pouring.ThermalReliefOnPads )
|
|
|
|
{
|
|
|
|
zone->SetThermalReliefGap( getKiCadLength( csTemplate.Pouring.ClearanceWidth ) );
|
2020-09-17 13:14:45 +00:00
|
|
|
zone->SetThermalReliefSpokeWidth( getKiCadLength(
|
2020-09-19 22:05:02 +00:00
|
|
|
getCopperCode( csTemplate.Pouring.ReliefCopperCodeID ).CopperWidth ) );
|
2020-08-31 22:09:29 +00:00
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::THERMAL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::FULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now create power plane layers:
|
|
|
|
for( LAYER_ID layer : mPowerPlaneLayers )
|
|
|
|
{
|
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() )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "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 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( std::pair<BOARD_ID, BOARD> boardPair : Layout.Boards )
|
|
|
|
{
|
|
|
|
//create a zone in each board shape
|
2020-11-11 23:05:59 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = mBoard->GetDesignSettings();
|
2020-08-31 22:09:29 +00:00
|
|
|
BOARD& board = boardPair.second;
|
2020-11-11 23:05:59 +00:00
|
|
|
int defaultLineThicknesss = bds.GetLineThickness( PCB_LAYER_ID::Edge_Cuts );
|
|
|
|
ZONE* zone = getZoneFromCadstarShape( board.Shape, defaultLineThicknesss, mBoard );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
mBoard->Add( zone, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
zone->SetZoneName( powerPlaneLayerName );
|
|
|
|
zone->SetLayer( getKiCadLayer( layer ) );
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
|
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::FULL );
|
|
|
|
zone->SetMinIslandArea( -1 );
|
|
|
|
zone->SetNet( getKiCadNet( netid ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadCoppers()
|
|
|
|
{
|
|
|
|
for( std::pair<COPPER_ID, COPPER> copPair : Layout.Coppers )
|
|
|
|
{
|
|
|
|
COPPER& csCopper = copPair.second;
|
|
|
|
|
|
|
|
if( !csCopper.PouredTemplateID.IsEmpty() )
|
|
|
|
continue; //ignore copper related to a template as we've already loaded it!
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
if( !mDoneCopperWarning )
|
|
|
|
{
|
|
|
|
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)." ) );
|
|
|
|
mDoneCopperWarning = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( csCopper.Shape.Type == SHAPE_TYPE::OPENSHAPE
|
|
|
|
|| csCopper.Shape.Type == SHAPE_TYPE::OUTLINE )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<PCB_SHAPE*> outlineSegments =
|
2020-08-31 22:09:29 +00:00
|
|
|
getDrawSegmentsFromVertices( csCopper.Shape.Vertices );
|
|
|
|
|
|
|
|
std::vector<TRACK*> outlineTracks = makeTracksFromDrawsegments( outlineSegments, mBoard,
|
2020-09-10 20:58:20 +00:00
|
|
|
getKiCadNet( csCopper.NetRef.NetID ), getKiCadLayer( csCopper.LayerID ),
|
2020-08-31 22:09:29 +00:00
|
|
|
getKiCadLength( getCopperCode( csCopper.CopperCodeID ).CopperWidth ) );
|
|
|
|
|
|
|
|
//cleanup
|
2020-10-04 23:34:59 +00:00
|
|
|
for( PCB_SHAPE* seg : outlineSegments )
|
|
|
|
delete seg;
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
for( CUTOUT cutout : csCopper.Shape.Cutouts )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<PCB_SHAPE*> cutoutSeg =
|
2020-08-31 22:09:29 +00:00
|
|
|
getDrawSegmentsFromVertices( cutout.Vertices );
|
|
|
|
|
|
|
|
std::vector<TRACK*> cutoutTracks = makeTracksFromDrawsegments( cutoutSeg, mBoard,
|
|
|
|
getKiCadNet( csCopper.NetRef.NetID ), getKiCadLayer( csCopper.LayerID ),
|
|
|
|
getKiCadLength( getCopperCode( csCopper.CopperCodeID ).CopperWidth ) );
|
|
|
|
|
|
|
|
//cleanup
|
2020-10-04 23:34:59 +00:00
|
|
|
for( PCB_SHAPE* seg : cutoutSeg )
|
|
|
|
delete seg;
|
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 ),
|
|
|
|
mBoard );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
mBoard->Add( zone, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
zone->SetZoneName( csCopper.ID );
|
|
|
|
zone->SetLayer( getKiCadLayer( csCopper.LayerID ) );
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
zone->SetHatchOrientation( getHatchCodeAngleDegrees( csCopper.Shape.HatchCodeID ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
|
|
|
|
}
|
|
|
|
|
|
|
|
zone->SetPadConnection( ZONE_CONNECTION::FULL );
|
|
|
|
zone->SetNet( getKiCadNet( csCopper.NetRef.NetID ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
if( netnameForErrorReporting.IsEmpty() )
|
2020-09-16 10:27:15 +00:00
|
|
|
netnameForErrorReporting = wxString::Format( "$%ld", net.SignalNum );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
for( NET_PCB::CONNECTION_PCB connection : net.Connections )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
if( !connection.Unrouted )
|
|
|
|
loadNetTracks( net.ID, connection.Route );
|
|
|
|
|
|
|
|
//TODO: all other elements
|
|
|
|
}
|
|
|
|
|
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;
|
2020-08-31 22:09:29 +00:00
|
|
|
loadNetVia( net.ID, via );
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
" '%d' in component '%s'. This has been ignored." ),
|
|
|
|
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
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Pads().at( pin.PadID - (long) 1 )->SetNet( getKiCadNet( net.ID ) );
|
2020-08-31 22:09:29 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::loadNetTracks(
|
2020-09-10 20:58:20 +00:00
|
|
|
const NET_ID& aCadstarNetID, const NET_PCB::ROUTE& aCadstarRoute )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<PCB_SHAPE*> shapes;
|
2020-08-31 22:09:29 +00:00
|
|
|
|
|
|
|
POINT prevEnd = aCadstarRoute.StartPoint;
|
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
for( const NET_PCB::ROUTE_VERTEX& v : aCadstarRoute.RouteVertices )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = getDrawSegmentFromVertex( prevEnd, v.Vertex );
|
|
|
|
shape->SetLayer( getKiCadLayer( aCadstarRoute.LayerID ) );
|
|
|
|
shape->SetWidth( getKiCadLength( v.RouteWidth ) );
|
|
|
|
shapes.push_back( shape );
|
2020-08-31 22:09:29 +00:00
|
|
|
prevEnd = v.Vertex.End;
|
|
|
|
}
|
2020-09-14 08:02:07 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
//Todo add real netcode to the tracks
|
|
|
|
std::vector<TRACK*> tracks =
|
2020-10-04 23:34:59 +00:00
|
|
|
makeTracksFromDrawsegments( shapes, mBoard, getKiCadNet( aCadstarNetID ) );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void 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
|
|
|
{
|
|
|
|
VIA* via = new VIA( mBoard );
|
|
|
|
mBoard->Add( via, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
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 )
|
|
|
|
wxLogError( wxString::Format(
|
|
|
|
_( "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 ) ) );
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText( const TEXT& aCadstarText,
|
2020-09-06 21:20:32 +00:00
|
|
|
BOARD_ITEM_CONTAINER* aContainer, const GROUP_ID& aCadstarGroupID,
|
|
|
|
const LAYER_ID& aCadstarLayerOverride, const wxPoint& aMoveVector,
|
|
|
|
const double& aRotationAngle, const double& aScalingFactor, const wxPoint& 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 );
|
|
|
|
|
|
|
|
wxPoint rotatedTextPos = getKiCadPoint( aCadstarText.Position );
|
|
|
|
RotatePoint( &rotatedTextPos, aTransformCentre, aRotationAngle );
|
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 );
|
|
|
|
|
|
|
|
txt->SetTextAngle( getAngleTenthDegree( aCadstarText.OrientAngle ) + aRotationAngle );
|
2020-10-18 17:26:31 +00:00
|
|
|
|
2020-10-19 17:11:52 +00:00
|
|
|
if( aCadstarText.Mirror != aMirrorInvert ) // If mirroring, invert angle to match CADSTAR
|
2020-10-18 17:26:31 +00:00
|
|
|
txt->SetTextAngle( -txt->GetTextAngle() );
|
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
txt->SetMirrored( aCadstarText.Mirror );
|
2020-09-05 15:31:57 +00:00
|
|
|
|
|
|
|
TEXTCODE tc = getTextCode( aCadstarText.TextCodeID );
|
|
|
|
|
|
|
|
txt->SetTextThickness( getKiCadLength( tc.LineWidth ) );
|
|
|
|
|
|
|
|
wxSize unscaledTextSize;
|
|
|
|
unscaledTextSize.x = getKiCadLength( tc.Width );
|
2020-10-18 17:15:46 +00:00
|
|
|
unscaledTextSize.y = KiROUND( TXT_HEIGHT_RATIO * (double) getKiCadLength( tc.Height ) );
|
2020-09-05 15:31:57 +00:00
|
|
|
txt->SetTextSize( unscaledTextSize );
|
|
|
|
|
|
|
|
switch( aCadstarText.Alignment )
|
|
|
|
{
|
|
|
|
case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
|
|
|
|
case ALIGNMENT::BOTTOMLEFT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMCENTER:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMRIGHT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERLEFT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERCENTER:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERRIGHT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPLEFT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPCENTER:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPRIGHT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-19 17:11:52 +00:00
|
|
|
wxFAIL_MSG( "Unknown Aligment - 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 )
|
|
|
|
{
|
|
|
|
wxSize scaledTextSize;
|
|
|
|
scaledTextSize.x = KiROUND( (double) getKiCadLength( tc.Width ) * aScalingFactor );
|
|
|
|
scaledTextSize.y = KiROUND( (double) getKiCadLength( tc.Height ) * aScalingFactor );
|
|
|
|
txt->SetTextSize( scaledTextSize );
|
|
|
|
txt->SetTextThickness(
|
|
|
|
KiROUND( (double) getKiCadLength( tc.LineWidth ) * aScalingFactor ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
txt->Move( aMoveVector );
|
|
|
|
|
|
|
|
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-10-04 23:34:59 +00:00
|
|
|
newtxt = new PCB_TEXT( *txt );
|
2020-09-05 15:31:57 +00:00
|
|
|
mBoard->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
|
|
|
}
|
|
|
|
|
|
|
|
mBoard->Remove( txt );
|
|
|
|
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,
|
|
|
|
const wxPoint& aMoveVector,
|
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
|
|
|
const wxPoint& aTransformCentre,
|
|
|
|
const bool& 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
|
2020-09-08 17:35:06 +00:00
|
|
|
drawCadstarVerticesAsSegments( aCadstarShape.Vertices, aKiCadLayer, aLineThickness,
|
|
|
|
aContainer, aCadstarGroupID, aMoveVector, aRotationAngle, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert );
|
|
|
|
drawCadstarCutoutsAsSegments( aCadstarShape.Cutouts, aKiCadLayer, aLineThickness,
|
2020-09-06 21:20:32 +00:00
|
|
|
aContainer, aCadstarGroupID, aMoveVector, aRotationAngle, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert );
|
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
|
|
|
{
|
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 ) )
|
|
|
|
{
|
|
|
|
shape = new FP_SHAPE( (FOOTPRINT*) aContainer, S_POLYGON );
|
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
shape = new PCB_SHAPE( aContainer );
|
|
|
|
shape->SetShape( S_POLYGON );
|
2020-11-14 01:16:02 +00:00
|
|
|
shape->SetFilled( true );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetPolyShape( getPolySetFromCadstarShape( aCadstarShape, -1, aContainer, aMoveVector,
|
|
|
|
aRotationAngle, aScalingFactor, aTransformCentre, aMirrorInvert ) );
|
|
|
|
shape->SetWidth( aLineThickness );
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarCutoutsAsSegments( const std::vector<CUTOUT>& aCutouts,
|
2020-11-13 15:15:52 +00:00
|
|
|
const PCB_LAYER_ID& aKiCadLayer,
|
|
|
|
const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID,
|
|
|
|
const wxPoint& aMoveVector,
|
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
|
|
|
const wxPoint& aTransformCentre,
|
|
|
|
const bool& aMirrorInvert )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
|
|
|
for( CUTOUT cutout : aCutouts )
|
|
|
|
{
|
2020-09-05 15:31:57 +00:00
|
|
|
drawCadstarVerticesAsSegments( cutout.Vertices, aKiCadLayer, aLineThickness, aContainer,
|
2020-11-13 15:15:52 +00:00
|
|
|
aCadstarGroupID, aMoveVector, aRotationAngle, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert );
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarVerticesAsSegments(
|
|
|
|
const std::vector<VERTEX>& aCadstarVertices, const PCB_LAYER_ID& aKiCadLayer,
|
2020-09-06 21:20:32 +00:00
|
|
|
const int& aLineThickness, BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID, const wxPoint& aMoveVector, const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor, const wxPoint& aTransformCentre, 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-09-06 21:20:32 +00:00
|
|
|
getDrawSegmentsFromVertices( aCadstarVertices, aContainer, aCadstarGroupID, aMoveVector,
|
|
|
|
aRotationAngle, aScalingFactor, aTransformCentre, aMirrorInvert );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
for( PCB_SHAPE* ds : drawSegments )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
|
|
|
ds->SetWidth( aLineThickness );
|
|
|
|
ds->SetLayer( aKiCadLayer );
|
2020-08-28 20:32:53 +00:00
|
|
|
ds->SetParent( aContainer );
|
|
|
|
aContainer->Add( ds, ADD_MODE::APPEND );
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<PCB_SHAPE*> CADSTAR_PCB_ARCHIVE_LOADER::getDrawSegmentsFromVertices(
|
2020-09-05 15:31:57 +00:00
|
|
|
const std::vector<VERTEX>& aCadstarVertices, BOARD_ITEM_CONTAINER* aContainer,
|
2020-09-06 21:20:32 +00:00
|
|
|
const GROUP_ID& aCadstarGroupID, const wxPoint& aMoveVector, const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor, const wxPoint& aTransformCentre, 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 );
|
2020-09-06 21:20:32 +00:00
|
|
|
drawSegments.push_back(
|
|
|
|
getDrawSegmentFromVertex( 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
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* CADSTAR_PCB_ARCHIVE_LOADER::getDrawSegmentFromVertex( const POINT& aCadstarStartPoint,
|
|
|
|
const VERTEX& aCadstarVertex,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID,
|
|
|
|
const wxPoint& aMoveVector,
|
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
|
|
|
const wxPoint& aTransformCentre,
|
|
|
|
const bool& aMirrorInvert )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* ds = nullptr;
|
|
|
|
bool cw = false;
|
|
|
|
double arcStartAngle, arcEndAngle, arcAngle;
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
wxPoint startPoint = getKiCadPoint( aCadstarStartPoint );
|
|
|
|
wxPoint endPoint = getKiCadPoint( aCadstarVertex.End );
|
|
|
|
wxPoint 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 )
|
|
|
|
centerPoint = ( startPoint + endPoint ) / 2;
|
|
|
|
else
|
|
|
|
centerPoint = getKiCadPoint( aCadstarVertex.Center );
|
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 ) )
|
2020-09-16 10:27:15 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
ds = new FP_SHAPE( static_cast<FOOTPRINT*>( aContainer ), S_SEGMENT );
|
2020-09-16 10:27:15 +00:00
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
ds = new PCB_SHAPE( aContainer );
|
2020-10-04 14:19:33 +00:00
|
|
|
ds->SetShape( S_SEGMENT );
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
ds->SetStart( startPoint );
|
|
|
|
ds->SetEnd( endPoint );
|
|
|
|
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:
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( isFootprint( aContainer ) )
|
2020-09-16 10:27:15 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
ds = new FP_SHAPE((FOOTPRINT*) aContainer, S_ARC );
|
2020-09-16 10:27:15 +00:00
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
ds = new PCB_SHAPE( aContainer );
|
2020-10-04 14:19:33 +00:00
|
|
|
ds->SetShape( S_ARC );
|
2020-08-16 17:12:08 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
ds->SetArcStart( startPoint );
|
|
|
|
ds->SetCenter( centerPoint );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
arcStartAngle = getPolarAngle( startPoint - centerPoint );
|
|
|
|
arcEndAngle = getPolarAngle( endPoint - centerPoint );
|
|
|
|
arcAngle = arcEndAngle - arcStartAngle;
|
|
|
|
//TODO: detect if we are supposed to draw a circle instead (i.e. two SEMICIRCLEs
|
|
|
|
// with opposite start/end points and same centre point)
|
|
|
|
|
|
|
|
if( cw )
|
|
|
|
ds->SetAngle( NormalizeAnglePos( arcAngle ) );
|
|
|
|
else
|
|
|
|
ds->SetAngle( NormalizeAngleNeg( arcAngle ) );
|
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
|
|
|
}
|
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
//Apply transforms
|
|
|
|
if( aMirrorInvert )
|
|
|
|
ds->Flip( aTransformCentre, true );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
if( aScalingFactor != 1.0 )
|
|
|
|
{
|
|
|
|
ds->Move( -aTransformCentre );
|
|
|
|
ds->Scale( aScalingFactor );
|
|
|
|
ds->Move( aTransformCentre );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aRotationAngle != 0.0 )
|
|
|
|
ds->Rotate( aTransformCentre, aRotationAngle );
|
|
|
|
|
|
|
|
if( aMoveVector != wxPoint{ 0, 0 } )
|
|
|
|
ds->Move( aMoveVector );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( isFootprint( aContainer ) && ds != nullptr )
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_SHAPE*>( ds )->SetLocalCoord();
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-09-06 21:20:32 +00:00
|
|
|
if( !aCadstarGroupID.IsEmpty() )
|
|
|
|
addToGroup( aCadstarGroupID, ds );
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
return ds;
|
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,
|
|
|
|
const wxPoint& aMoveVector,
|
|
|
|
const double& aRotationAngle,
|
|
|
|
const double& aScalingFactor,
|
|
|
|
const wxPoint& aTransformCentre,
|
|
|
|
const bool& aMirrorInvert )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2020-09-06 21:20:32 +00:00
|
|
|
GROUP_ID noGroup = wxEmptyString;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
std::vector<PCB_SHAPE*> outlineSegments = getDrawSegmentsFromVertices( aCadstarShape.Vertices,
|
|
|
|
aContainer, noGroup,
|
|
|
|
aMoveVector,
|
|
|
|
aRotationAngle,
|
|
|
|
aScalingFactor,
|
|
|
|
aTransformCentre,
|
|
|
|
aMirrorInvert );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
SHAPE_POLY_SET polySet( getLineChainFromDrawsegments( outlineSegments ) );
|
|
|
|
|
|
|
|
//cleanup
|
2020-10-04 23:34:59 +00:00
|
|
|
for( PCB_SHAPE* seg : outlineSegments )
|
|
|
|
delete seg;
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
for( CUTOUT cutout : aCadstarShape.Cutouts )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
std::vector<PCB_SHAPE*> cutoutSeg = getDrawSegmentsFromVertices( cutout.Vertices,
|
|
|
|
aContainer, noGroup,
|
|
|
|
aMoveVector,
|
|
|
|
aRotationAngle,
|
|
|
|
aScalingFactor,
|
|
|
|
aTransformCentre,
|
|
|
|
aMirrorInvert );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
polySet.AddHole( getLineChainFromDrawsegments( cutoutSeg ) );
|
|
|
|
|
|
|
|
//cleanup
|
2020-10-04 23:34:59 +00:00
|
|
|
for( PCB_SHAPE* seg : cutoutSeg )
|
|
|
|
delete seg;
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aLineThickness > 0 )
|
2020-11-13 15:15:52 +00:00
|
|
|
polySet.Inflate( aLineThickness / 2, 32, SHAPE_POLY_SET::CORNER_STRATEGY::ROUND_ALL_CORNERS );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-08-23 21:54:19 +00:00
|
|
|
//Make a new polyset with no holes
|
|
|
|
//TODO: Using strictly simple to be safe, but need to find out if PM_FAST works okay
|
2020-08-28 20:32:53 +00:00
|
|
|
polySet.Fracture( SHAPE_POLY_SET::POLYGON_MODE::PM_STRICTLY_SIMPLE );
|
2020-08-23 21:54:19 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
SHAPE_LINE_CHAIN CADSTAR_PCB_ARCHIVE_LOADER::getLineChainFromDrawsegments( const std::vector<PCB_SHAPE*> aDrawsegments )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN lineChain;
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
for( PCB_SHAPE* ds : aDrawsegments )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2020-08-28 20:32:53 +00:00
|
|
|
switch( ds->GetShape() )
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case S_ARC:
|
2020-08-23 10:34:27 +00:00
|
|
|
{
|
2020-08-28 20:32:53 +00:00
|
|
|
if( ds->GetClass() == wxT( "MGRAPHIC" ) )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* em = (FP_SHAPE*) ds;
|
|
|
|
SHAPE_ARC arc( em->GetStart0(), em->GetEnd0(), (double) em->GetAngle() / 10.0 );
|
2020-08-28 20:32:53 +00:00
|
|
|
lineChain.Append( arc );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SHAPE_ARC arc( ds->GetCenter(), ds->GetArcStart(), (double) ds->GetAngle() / 10.0 );
|
|
|
|
lineChain.Append( arc );
|
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-10-04 14:19:33 +00:00
|
|
|
case S_SEGMENT:
|
2020-08-28 20:32:53 +00:00
|
|
|
if( ds->GetClass() == wxT( "MGRAPHIC" ) )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* em = (FP_SHAPE*) ds;
|
2020-08-28 20:32:53 +00:00
|
|
|
lineChain.Append( em->GetStart0().x, em->GetStart0().y );
|
|
|
|
lineChain.Append( em->GetEnd0().x, em->GetEnd0().y );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lineChain.Append( ds->GetStartX(), ds->GetStartY() );
|
|
|
|
lineChain.Append( ds->GetEndX(), ds->GetEndY() );
|
|
|
|
}
|
2020-08-23 10:34:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-19 17:11:52 +00:00
|
|
|
wxFAIL_MSG( "Drawsegment type is unexpected. Ignored." );
|
2020-08-23 10:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lineChain.SetClosed( true ); //todo check if it is closed
|
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
wxASSERT( lineChain.PointCount() > 2 );
|
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
return lineChain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
std::vector<TRACK*> CADSTAR_PCB_ARCHIVE_LOADER::makeTracksFromDrawsegments(
|
2020-10-04 23:34:59 +00:00
|
|
|
const std::vector<PCB_SHAPE*> aDrawsegments,
|
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
|
|
|
{
|
|
|
|
std::vector<TRACK*> tracks;
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
for( PCB_SHAPE* ds : aDrawsegments )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
TRACK* track;
|
|
|
|
|
|
|
|
switch( ds->GetShape() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case S_ARC:
|
2020-08-31 22:09:29 +00:00
|
|
|
if( ds->GetClass() == wxT( "MGRAPHIC" ) )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* em = (FP_SHAPE*) ds;
|
|
|
|
SHAPE_ARC arc( em->GetStart0(), em->GetEnd0(), (double) em->GetAngle() / 10.0 );
|
2020-08-31 22:09:29 +00:00
|
|
|
track = new ARC( aParentContainer, &arc );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SHAPE_ARC arc( ds->GetCenter(), ds->GetArcStart(), (double) ds->GetAngle() / 10.0 );
|
|
|
|
track = new ARC( aParentContainer, &arc );
|
|
|
|
}
|
|
|
|
break;
|
2020-10-04 14:19:33 +00:00
|
|
|
case S_SEGMENT:
|
2020-08-31 22:09:29 +00:00
|
|
|
if( ds->GetClass() == wxT( "MGRAPHIC" ) )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* em = (FP_SHAPE*) ds;
|
|
|
|
track = new TRACK( aParentContainer );
|
2020-08-31 22:09:29 +00:00
|
|
|
track->SetStart( em->GetStart0() );
|
|
|
|
track->SetEnd( em->GetEnd0() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
track = new TRACK( aParentContainer );
|
|
|
|
track->SetStart( ds->GetStart() );
|
|
|
|
track->SetEnd( ds->GetEnd() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-19 17:11:52 +00:00
|
|
|
wxFAIL_MSG( "Drawsegment type is unexpected. Ignored." );
|
2020-08-31 22:09:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aWidthOverride == -1 )
|
|
|
|
track->SetWidth( ds->GetWidth() );
|
|
|
|
else
|
|
|
|
track->SetWidth( aWidthOverride );
|
|
|
|
|
|
|
|
if( aLayerOverride == PCB_LAYER_ID::UNDEFINED_LAYER )
|
|
|
|
track->SetLayer( ds->GetLayer() );
|
|
|
|
else
|
|
|
|
track->SetLayer( aLayerOverride );
|
|
|
|
|
|
|
|
if( aNet != nullptr )
|
|
|
|
track->SetNet( aNet );
|
|
|
|
|
|
|
|
tracks.push_back( track );
|
|
|
|
aParentContainer->Add( track, ADD_MODE::APPEND );
|
|
|
|
}
|
|
|
|
|
|
|
|
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-13 01:12:36 +00:00
|
|
|
aFootprint->Add( new FP_TEXT( aFootprint->Value() ) );
|
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
|
|
|
|
}
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
wxPoint 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 );
|
2020-09-10 20:58:20 +00:00
|
|
|
txt->SetTextAngle(
|
2020-11-13 01:12:36 +00:00
|
|
|
getAngleTenthDegree( 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() );
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
TEXTCODE tc = getTextCode( aCadstarAttrLoc.TextCodeID );
|
|
|
|
|
|
|
|
txt->SetTextThickness( getKiCadLength( tc.LineWidth ) );
|
2020-10-18 17:15:46 +00:00
|
|
|
|
|
|
|
wxSize txtSize;
|
|
|
|
txtSize.x = getKiCadLength( tc.Width );
|
|
|
|
txtSize.y = KiROUND( TXT_HEIGHT_RATIO * (double) getKiCadLength( tc.Height ) );
|
|
|
|
txt->SetTextSize( txtSize );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
switch( aCadstarAttrLoc.Alignment )
|
|
|
|
{
|
|
|
|
case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
|
|
|
|
case ALIGNMENT::BOTTOMLEFT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMCENTER:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMRIGHT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERLEFT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERCENTER:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERRIGHT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPLEFT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPCENTER:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPRIGHT:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-19 17:11:52 +00:00
|
|
|
wxFAIL_MSG( "Unknown Aligment - needs review!" );
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO Handle different font types when KiCad can support it.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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(),
|
|
|
|
mBoard->GetDesignSettings().GetLineThickness( PCB_LAYER_ID::Edge_Cuts ) );
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
double CADSTAR_PCB_ARCHIVE_LOADER::getHatchCodeAngleDegrees(
|
|
|
|
const HATCHCODE_ID& aCadstarHatchcodeID )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
checkAndLogHatchCode( aCadstarHatchcodeID );
|
|
|
|
HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
|
|
|
|
|
|
|
|
if( hcode.Hatches.size() < 1 )
|
|
|
|
return mBoard->GetDesignSettings().GetDefaultZoneSettings().m_HatchOrientation;
|
|
|
|
else
|
|
|
|
return getAngleDegrees( hcode.Hatches.at( 0 ).OrientAngle );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CADSTAR_PCB_ARCHIVE_LOADER::getKiCadHatchCodeThickness(
|
|
|
|
const HATCHCODE_ID& aCadstarHatchcodeID )
|
|
|
|
{
|
|
|
|
checkAndLogHatchCode( aCadstarHatchcodeID );
|
|
|
|
HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
|
|
|
|
|
|
|
|
if( hcode.Hatches.size() < 1 )
|
|
|
|
return mBoard->GetDesignSettings().GetDefaultZoneSettings().m_HatchThickness;
|
|
|
|
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 )
|
|
|
|
return mBoard->GetDesignSettings().GetDefaultZoneSettings().m_HatchGap;
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
wxCHECK( mGroupMap.find( aCadstarGroupID ) != mGroupMap.end(), nullptr );
|
|
|
|
|
|
|
|
return mGroupMap.at( aCadstarGroupID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
void CADSTAR_PCB_ARCHIVE_LOADER::checkAndLogHatchCode( const HATCHCODE_ID& aCadstarHatchcodeID )
|
|
|
|
{
|
|
|
|
if( mHatchcodesTested.find( aCadstarHatchcodeID ) != mHatchcodesTested.end() )
|
|
|
|
{
|
|
|
|
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 "
|
|
|
|
"hatch. KiCad only supports one width for the haching. The imported "
|
|
|
|
"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 "
|
|
|
|
"hatch. KiCad only supports one step size for the haching. The imported "
|
|
|
|
"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,
|
|
|
|
getAngleDegrees( abs( hcode.Hatches.at( 0 ).OrientAngle
|
|
|
|
- hcode.Hatches.at( 1 ).OrientAngle ) ),
|
|
|
|
getAngleDegrees( hcode.Hatches.at( 0 ).OrientAngle ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mHatchcodesTested.insert( aCadstarHatchcodeID );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* CADSTAR_PCB_ARCHIVE_LOADER::getFootprintFromCadstarID( const COMPONENT_ID& aCadstarComponentID )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
|
|
|
if( mComponentMap.find( aCadstarComponentID ) == mComponentMap.end() )
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return mComponentMap.at( aCadstarComponentID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
wxPoint CADSTAR_PCB_ARCHIVE_LOADER::getKiCadPoint( wxPoint aCadstarPoint )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
|
|
|
wxPoint retval;
|
|
|
|
|
|
|
|
retval.x = ( aCadstarPoint.x - mDesignCenter.x ) * KiCadUnitMultiplier;
|
|
|
|
retval.y = -( aCadstarPoint.y - mDesignCenter.y ) * KiCadUnitMultiplier;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
double CADSTAR_PCB_ARCHIVE_LOADER::getPolarAngle( wxPoint aPoint )
|
2020-08-16 17:12:08 +00:00
|
|
|
{
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
return NormalizeAnglePos( ArcTangente( aPoint.y, aPoint.x ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
NETINFO_ITEM* CADSTAR_PCB_ARCHIVE_LOADER::getKiCadNet( const NET_ID& aCadstarNetID )
|
|
|
|
{
|
|
|
|
if( aCadstarNetID.IsEmpty() )
|
|
|
|
return nullptr;
|
|
|
|
else if( mNetMap.find( aCadstarNetID ) != mNetMap.end() )
|
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
return mNetMap.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();
|
2020-10-03 02:16:39 +00:00
|
|
|
newName << "-Pad" << wxString::Format( "%ld", firstPin.PadID ) << ")";
|
2020-09-05 15:31:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-19 17:11:52 +00:00
|
|
|
wxFAIL_MSG( "A net with no pins associated?" );
|
2020-09-05 15:31:57 +00:00
|
|
|
newName = wxT( "csNet-" );
|
|
|
|
newName << wxString::Format( "%i", csNet.SignalNum );
|
|
|
|
}
|
2020-09-06 15:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !mDoneNetClassWarning && !csNet.NetClassID.IsEmpty()
|
|
|
|
&& csNet.NetClassID != wxT( "NONE" ) )
|
|
|
|
{
|
2020-09-10 20:58:20 +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)." ) );
|
2020-09-06 15:24:40 +00:00
|
|
|
mDoneNetClassWarning = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !mDoneSpacingClassWarning && !csNet.SpacingClassID.IsEmpty()
|
|
|
|
&& csNet.SpacingClassID != wxT( "NONE" ) )
|
|
|
|
{
|
|
|
|
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." ) );
|
|
|
|
mDoneSpacingClassWarning = true;
|
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
NETINFO_ITEM* netInfo = new NETINFO_ITEM( mBoard, newName, ++mNumNets );
|
2020-08-31 22:09:29 +00:00
|
|
|
mBoard->Add( netInfo, ADD_MODE::APPEND );
|
2020-09-06 15:24:40 +00:00
|
|
|
|
|
|
|
if( mNetClassMap.find( csNet.RouteCodeID ) != mNetClassMap.end() )
|
|
|
|
{
|
|
|
|
NETCLASSPTR netclass = mNetClassMap.at( csNet.RouteCodeID );
|
|
|
|
netInfo->SetClass( netclass );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ROUTECODE rc = getRouteCode( csNet.RouteCodeID );
|
|
|
|
NETCLASSPTR netclass( new ::NETCLASS( rc.Name ) );
|
|
|
|
netclass->SetTrackWidth( getKiCadLength( rc.OptimalWidth ) );
|
|
|
|
netInfo->SetClass( netclass );
|
|
|
|
mNetClassMap.insert( { csNet.RouteCodeID, netclass } );
|
|
|
|
}
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-09-02 21:48:18 +00:00
|
|
|
mNetMap.insert( { aCadstarNetID, netInfo } );
|
2020-08-31 22:09:29 +00:00
|
|
|
return netInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
PCB_LAYER_ID CADSTAR_PCB_ARCHIVE_LOADER::getKiCadCopperLayerID( unsigned int aLayerNum )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-09-10 20:58:20 +00:00
|
|
|
if( aLayerNum == Assignments.Technology.MaxPhysicalLayer )
|
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
|
|
|
|
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
|
|
|
{
|
2020-08-31 22:09:29 +00:00
|
|
|
if( Assignments.Layerdefs.Layers.find( aCadstarLayerID ) != Assignments.Layerdefs.Layers.end() )
|
|
|
|
{
|
|
|
|
if( Assignments.Layerdefs.Layers.at( aCadstarLayerID ).Type == LAYER_TYPE::NOLAYER )
|
|
|
|
//The "no layer" is common for CADSTAR documentation symbols
|
|
|
|
//map it to undefined layer for later processing
|
|
|
|
return PCB_LAYER_ID::UNDEFINED_LAYER;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxCHECK( mLayermap.find( aCadstarLayerID ) != mLayermap.end(), PCB_LAYER_ID::UNDEFINED_LAYER );
|
|
|
|
|
2020-09-10 20:58:20 +00:00
|
|
|
return mLayermap.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
|
|
|
{
|
|
|
|
LAYER& layer = Assignments.Layerdefs.Layers.at( aCadstarLayerID );
|
|
|
|
|
|
|
|
switch( layer.Type )
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
return LSET::AllCuMask();
|
|
|
|
|
|
|
|
case LAYER_TYPE::ALLLAYER:
|
|
|
|
return LSET::AllLayersMask();
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2020-09-06 22:16:02 +00:00
|
|
|
wxCHECK( mGroupMap.find( aCadstarGroupID ) != mGroupMap.end(), );
|
2020-09-06 21:20:32 +00:00
|
|
|
|
|
|
|
PCB_GROUP* parentGroup = mGroupMap.at( aCadstarGroupID );
|
|
|
|
parentGroup->AddItem( aKiCadItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CADSTAR_PCB_ARCHIVE_LOADER::GROUP_ID CADSTAR_PCB_ARCHIVE_LOADER::createUniqueGroupID(
|
|
|
|
const wxString& aName )
|
|
|
|
{
|
|
|
|
wxString groupName = aName;
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
while( mGroupMap.find( groupName ) != mGroupMap.end() )
|
|
|
|
{
|
|
|
|
groupName = aName + wxT( "_" ) + wxString::Format( "%i", ++num );
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_GROUP* docSymGroup = new PCB_GROUP( mBoard );
|
|
|
|
mBoard->Add( docSymGroup );
|
|
|
|
docSymGroup->SetName( groupName );
|
|
|
|
GROUP_ID groupID( groupName );
|
|
|
|
mGroupMap.insert( { groupID, docSymGroup } );
|
|
|
|
|
|
|
|
return groupID;
|
|
|
|
}
|