KiCad PCB EDA Suite
Loading...
Searching...
No Matches
allegro_builder.cpp File Reference
#include "allegro_builder.h"
#include <cmath>
#include <limits>
#include <set>
#include <tuple>
#include <unordered_set>
#include <convert/allegro_pcb_structs.h>
#include <wx/log.h>
#include <core/profile.h>
#include <core/throttle.h>
#include <base_units.h>
#include <board_design_settings.h>
#include <convert_basic_shapes_to_polygon.h>
#include <geometry/shape_utils.h>
#include <project/net_settings.h>
#include <footprint.h>
#include <netclass.h>
#include <pad.h>
#include <pcb_group.h>
#include <pcb_text.h>
#include <pcb_shape.h>
#include <pcb_track.h>
#include <priority_thread_pool_task.h>
#include <zone.h>
#include <zone_utils.h>

Go to the source code of this file.

Classes

class  LL_WALKER
 
class  LL_WALKER::iterator
 
struct  std::hash< LAYER_INFO >
 
class  ALLEGRO::LAYER_MAPPER
 Class to handle the mapping for Allegro CLASS/SUBCLASS idiom to KiCad layers. More...
 
struct  ALLEGRO::LAYER_MAPPER::CUSTOM_LAYER
 Represents the information found in a single entry of a layer list. More...
 
class  ALLEGRO::BOARD_BUILDER::ZONE_FILL_HANDLER
 Filled zones have their own outline and the fill itself comes from a bunch of "related" spaces. More...
 
struct  ALLEGRO::BOARD_BUILDER::ZONE_FILL_HANDLER::FILL_INFO
 This is all the info needed to do the fill of one layer of one zone. More...
 
class  ALLEGRO::BOARD_BUILDER::ZONE_FILL_HANDLER::COMPLEX_FIRST_FILL_TASK
 Priority task dispatcher for zone fills - we want to do the biggest ones first. More...
 

Macros

#define BLK_FIELD(BLK_T, FIELD)
 

Functions

template<typename BLK_T>
const BLK_T & BlockDataAs (const BLOCK_BASE &aBlock)
 
static uint32_t GetPrimaryNext (const BLOCK_BASE &aBlock)
 Gets the next block in the linked list.
 
static uint32_t PadGetNextInFootprint (const BLOCK_BASE &aBlock)
 "Get Next" function for the pad list in a footprint's 0x32 list.
 
static wxString layerInfoDisplayName (const LAYER_INFO &aLayerInfo)
 Build a unique display name for a LAYER_INFO entry from the static maps above, suitable for presentation in the layer mapping dialog.
 
static bool layerIsZone (const LAYER_INFO &aLayerInfo)
 Some layers map to KiCad rule areas (zones) - for example a package keepout on ALL maps to a rule area in KiCad.
 
static std::optional< LAYER_INFOtryLayerFromBlock (const BLOCK_BASE &aBlock)
 Some blocks report layer info - if they do, return it else std::nullopt.
 
LAYER_INFO expectLayerFromBlock (const BLOCK_BASE &aBlock)
 Get a layer from a block that has layer info.
 
static int clampForScale (double aValue)
 
static std::unordered_set< LAYER_INFOScanForLayers (const BRD_DB &aDb)
 Look through some lists for a list of layers used.
 
static LSET getRuleAreaLayers (const LAYER_INFO &aLayerInfo, PCB_LAYER_ID aDefault)
 
template<std::derived_from< BOARD_ITEM > T>
void BulkAddToBoard (BOARD &aBoard, std::vector< std::unique_ptr< T > > &&aItems)
 

Variables

static const wxChar *const traceAllegroBuilder = wxT( "KICAD_ALLEGRO_BUILDER" )
 Flag to enable debug output of Allegro board construction.
 
static const wxChar *const traceAllegroPerf = wxT( "KICAD_ALLEGRO_PERF" )
 
static const std::unordered_map< LAYER_INFO, PCB_LAYER_IDs_LayerKiMap
 Map of the pre-set class:subclass pairs to standard layers.
 
static const std::unordered_map< LAYER_INFO, wxString > s_OptionalFixedMappings
 Names for custom KiCad layers that correspond to pre-defined Allegro layers.
 

Macro Definition Documentation

◆ BLK_FIELD

#define BLK_FIELD ( BLK_T,
FIELD )
Value:
BlockDataAs<BLK_T>( aBlock ).FIELD
const BLK_T & BlockDataAs(const BLOCK_BASE &aBlock)

Definition at line 78 of file allegro_builder.cpp.

Referenced by GetPrimaryNext(), and PadGetNextInFootprint().

Function Documentation

◆ BlockDataAs()

template<typename BLK_T>
const BLK_T & BlockDataAs ( const BLOCK_BASE & aBlock)

◆ BulkAddToBoard()

template<std::derived_from< BOARD_ITEM > T>
void BulkAddToBoard ( BOARD & aBoard,
std::vector< std::unique_ptr< T > > && aItems )

◆ clampForScale()

static int clampForScale ( double aValue)
static

◆ expectLayerFromBlock()

LAYER_INFO expectLayerFromBlock ( const BLOCK_BASE & aBlock)

Get a layer from a block that has layer info.

It's an error to request this from a block that doesn't support it.

Definition at line 571 of file allegro_builder.cpp.

References tryLayerFromBlock().

Referenced by ALLEGRO::BOARD_BUILDER::buildZone().

◆ GetPrimaryNext()

static uint32_t GetPrimaryNext ( const BLOCK_BASE & aBlock)
static

Gets the next block in the linked list.

Exactly which member does this depends on the block type.

It's not yet clear if any blocks can be in multiple linked lists at once - for now just follow the "main" one. This is done as dispatch like this to avoid forcing all the blocks into an inheritance hierarchy.

Parameters
aBlockThe block to get the next block from.
Returns
The next block in the linked list, or 0 if there is no next block.

Definition at line 91 of file allegro_builder.cpp.

References BLK_FIELD, and ALLEGRO::BLOCK_BASE::GetBlockType().

Referenced by ALLEGRO::COMPONENT::COMPONENT(), ALLEGRO::FOOTPRINT_DEF::FOOTPRINT_DEF(), ALLEGRO::FOOTPRINT_INSTANCE::FOOTPRINT_INSTANCE(), LL_WALKER::LL_WALKER(), ALLEGRO::NET::NET(), and ALLEGRO::SHAPE::SHAPE().

◆ getRuleAreaLayers()

◆ layerInfoDisplayName()

static wxString layerInfoDisplayName ( const LAYER_INFO & aLayerInfo)
static

Build a unique display name for a LAYER_INFO entry from the static maps above, suitable for presentation in the layer mapping dialog.

Refer to https://www.artwork.com/all2dxf/alleggeo.htm for layer orders.

Definition at line 328 of file allegro_builder.cpp.

References ALLEGRO::LAYER_INFO::ANALYSIS, ALLEGRO::LAYER_INFO::ANALYSIS_HIGH_ISOCONTOUR, ALLEGRO::LAYER_INFO::ANALYSIS_LOW_ISOCONTOUR, ALLEGRO::LAYER_INFO::ANALYSIS_MEDIUM1_ISOCONTOUR, ALLEGRO::LAYER_INFO::ANALYSIS_MEDIUM2_ISOCONTOUR, ALLEGRO::LAYER_INFO::ANALYSIS_MEDIUM3_ISOCONTOUR, ALLEGRO::LAYER_INFO::ANALYSIS_PCB_TEMPERATURE, ALLEGRO::LAYER_INFO::ANTI_ETCH, ALLEGRO::LAYER_INFO::ASSEMBLY_BOTTOM, ALLEGRO::LAYER_INFO::ASSEMBLY_TOP, ALLEGRO::LAYER_INFO::BGEOM_ASSEMBLY_DETAIL, ALLEGRO::LAYER_INFO::BGEOM_ASSEMBLY_NOTES, ALLEGRO::LAYER_INFO::BGEOM_BOTH_ROOMS, ALLEGRO::LAYER_INFO::BGEOM_BOTTOM_ROOM, ALLEGRO::LAYER_INFO::BGEOM_CONSTRAINT_AREA, ALLEGRO::LAYER_INFO::BGEOM_DESIGN_OUTLINE, ALLEGRO::LAYER_INFO::BGEOM_DIMENSION, ALLEGRO::LAYER_INFO::BGEOM_OFF_GRID_AREA, ALLEGRO::LAYER_INFO::BGEOM_OUTLINE, ALLEGRO::LAYER_INFO::BGEOM_PLACE_GRID_BOTTOM, ALLEGRO::LAYER_INFO::BGEOM_PLACE_GRID_TOP, ALLEGRO::LAYER_INFO::BGEOM_PLATING_BAR, ALLEGRO::LAYER_INFO::BGEOM_SILKSCREEN_BOTTOM, ALLEGRO::LAYER_INFO::BGEOM_SILKSCREEN_TOP, ALLEGRO::LAYER_INFO::BGEOM_SOLDERMASK_BOTTOM, ALLEGRO::LAYER_INFO::BGEOM_SOLDERMASK_TOP, ALLEGRO::LAYER_INFO::BGEOM_SWITCH_AREA_BOTTOM, ALLEGRO::LAYER_INFO::BGEOM_SWITCH_AREA_TOP, ALLEGRO::LAYER_INFO::BGEOM_TOOLING_CORNERS, ALLEGRO::LAYER_INFO::BGEOM_TOP_ROOM, ALLEGRO::LAYER_INFO::BOARD_GEOMETRY, ALLEGRO::LAYER_INFO::BOUNDARY, ALLEGRO::LAYER_INFO::COMPONENT_VALUE, ALLEGRO::LAYER_INFO::CONSTRAINTS_REGION, ALLEGRO::LAYER_INFO::CREG_ALL, ALLEGRO::LAYER_INFO::DEVICE_TYPE, ALLEGRO::LAYER_INFO::DFA_BOUND_BOTTOM, ALLEGRO::LAYER_INFO::DFA_BOUND_TOP, ALLEGRO::LAYER_INFO::DFMT_OUTLINE, ALLEGRO::LAYER_INFO::DFMT_REVISION_BLOCK, ALLEGRO::LAYER_INFO::DFMT_REVISION_DATA, ALLEGRO::LAYER_INFO::DFMT_TITLE_BLOCK, ALLEGRO::LAYER_INFO::DFMT_TITLE_DATA, ALLEGRO::LAYER_INFO::DISPLAY_BOTTOM, ALLEGRO::LAYER_INFO::DISPLAY_TOP, ALLEGRO::LAYER_INFO::DRAWING_FORMAT, ALLEGRO::LAYER_INFO::ETCH, ALLEGRO::LAYER_INFO::KEEPIN_ALL, ALLEGRO::LAYER_INFO::KEEPOUT_ALL, ALLEGRO::LAYER_INFO::KEEPOUT_BOTTOM, ALLEGRO::LAYER_INFO::KEEPOUT_TOP, ALLEGRO::LAYER_INFO::m_Class, ALLEGRO::LAYER_INFO::m_Subclass, ALLEGRO::LAYER_INFO::MANUFACTURING, ALLEGRO::LAYER_INFO::MFR_AUTOSILK_BOTTOM, ALLEGRO::LAYER_INFO::MFR_AUTOSILK_TOP, ALLEGRO::LAYER_INFO::MFR_NCDRILL_FIGURE, ALLEGRO::LAYER_INFO::MFR_NCDRILL_LEGEND, ALLEGRO::LAYER_INFO::MFR_NO_GLOSS_ALL, ALLEGRO::LAYER_INFO::MFR_NO_GLOSS_BOTTOM, ALLEGRO::LAYER_INFO::MFR_NO_GLOSS_INTERNAL, ALLEGRO::LAYER_INFO::MFR_NO_GLOSS_TOP, ALLEGRO::LAYER_INFO::MFR_NO_PROBE_BOTTOM, ALLEGRO::LAYER_INFO::MFR_NO_PROBE_TOP, ALLEGRO::LAYER_INFO::MFR_PHOTOPLOT_OUTLINE, ALLEGRO::LAYER_INFO::MFR_PROBE_BOTTOM, ALLEGRO::LAYER_INFO::MFR_PROBE_TOP, ALLEGRO::LAYER_INFO::MFR_XSECTION_CHART, ALLEGRO::LAYER_INFO::PACKAGE_GEOMETRY, ALLEGRO::LAYER_INFO::PACKAGE_KEEPIN, ALLEGRO::LAYER_INFO::PACKAGE_KEEPOUT, ALLEGRO::LAYER_INFO::PGEOM_ASSEMBLY_BOTTOM, ALLEGRO::LAYER_INFO::PGEOM_ASSEMBLY_TOP, ALLEGRO::LAYER_INFO::PGEOM_BODY_CENTER, ALLEGRO::LAYER_INFO::PGEOM_DISPLAY_BOTTOM, ALLEGRO::LAYER_INFO::PGEOM_DISPLAY_TOP, ALLEGRO::LAYER_INFO::PGEOM_PAD_STACK_NAME, ALLEGRO::LAYER_INFO::PGEOM_PIN_NUMBER, ALLEGRO::LAYER_INFO::PGEOM_PLACE_BOUND_BOTTOM, ALLEGRO::LAYER_INFO::PGEOM_PLACE_BOUND_TOP, ALLEGRO::LAYER_INFO::PGEOM_SILKSCREEN_BOTTOM, ALLEGRO::LAYER_INFO::PGEOM_SILKSCREEN_TOP, ALLEGRO::LAYER_INFO::PGEOM_SOLDERMASK_BOTTOM, ALLEGRO::LAYER_INFO::PGEOM_SOLDERMASK_TOP, ALLEGRO::LAYER_INFO::PIN, ALLEGRO::LAYER_INFO::REF_DES, ALLEGRO::LAYER_INFO::ROUTE_KEEPIN, ALLEGRO::LAYER_INFO::ROUTE_KEEPOUT, ALLEGRO::LAYER_INFO::SILKSCREEN_BOTTOM, ALLEGRO::LAYER_INFO::SILKSCREEN_TOP, ALLEGRO::LAYER_INFO::TOLERANCE, ALLEGRO::LAYER_INFO::USER_PART_NUMBER, ALLEGRO::LAYER_INFO::VIA_CLASS, and ALLEGRO::LAYER_INFO::VIA_KEEPOUT.

Referenced by ALLEGRO::BOARD_BUILDER::createZones(), ALLEGRO::LAYER_MAPPER::FinalizeLayers(), and ALLEGRO::BOARD_BUILDER::setupLayers().

◆ layerIsZone()

static bool layerIsZone ( const LAYER_INFO & aLayerInfo)
static

Some layers map to KiCad rule areas (zones) - for example a package keepout on ALL maps to a rule area in KiCad.

Keepins are bit trickier, but they're still rule areas and might need custom DRC rules.

Definition at line 520 of file allegro_builder.cpp.

References ALLEGRO::LAYER_INFO::m_Class, ALLEGRO::LAYER_INFO::PACKAGE_KEEPIN, ALLEGRO::LAYER_INFO::PACKAGE_KEEPOUT, ALLEGRO::LAYER_INFO::ROUTE_KEEPIN, ALLEGRO::LAYER_INFO::ROUTE_KEEPOUT, and ALLEGRO::LAYER_INFO::VIA_KEEPOUT.

Referenced by ALLEGRO::BOARD_BUILDER::createBoardShapes(), and ALLEGRO::BOARD_BUILDER::createZones().

◆ PadGetNextInFootprint()

static uint32_t PadGetNextInFootprint ( const BLOCK_BASE & aBlock)
static

"Get Next" function for the pad list in a footprint's 0x32 list.

Definition at line 130 of file allegro_builder.cpp.

References BLK_FIELD, ALLEGRO::BLOCK_BASE::GetBlockType(), ALLEGRO::BLOCK_BASE::GetKey(), ALLEGRO::BLOCK_BASE::GetOffset(), and THROW_IO_ERROR.

Referenced by ALLEGRO::BOARD_BUILDER::buildFootprint().

◆ ScanForLayers()

static std::unordered_set< LAYER_INFO > ScanForLayers ( const BRD_DB & aDb)
static

Look through some lists for a list of layers used.

This isn't yet exhaustive, not sure if it needs to be. We could scan every single block if we wanted, but that would be a lot of blocks without layers. So walking lists seems more efficient.

The primary goal is to look for colliding layers like OUTLINE/DESIGN_OUTLINE so that we can remap one of them to something else.

We could also use this to find all the used layers and present them in the mapping dialog rather than auto-creating them layer during buildout.

Definition at line 1679 of file allegro_builder.cpp.

References info, ALLEGRO::BRD_DB::m_Header, and tryLayerFromBlock().

Referenced by ALLEGRO::BOARD_BUILDER::setupLayers().

◆ tryLayerFromBlock()

static std::optional< LAYER_INFO > tryLayerFromBlock ( const BLOCK_BASE & aBlock)
static

Some blocks report layer info - if they do, return it else std::nullopt.

Definition at line 536 of file allegro_builder.cpp.

References BlockDataAs(), and ALLEGRO::BLOCK_BASE::GetBlockType().

Referenced by expectLayerFromBlock(), and ScanForLayers().

Variable Documentation

◆ s_LayerKiMap

const std::unordered_map<LAYER_INFO, PCB_LAYER_ID> s_LayerKiMap
static
Initial value:
= {
{ { LAYER_INFO::CLASS::BOARD_GEOMETRY, LAYER_INFO::SUBCLASS::BGEOM_OUTLINE}, Edge_Cuts},
{ { LAYER_INFO::CLASS::BOARD_GEOMETRY, LAYER_INFO::SUBCLASS::BGEOM_DESIGN_OUTLINE}, Edge_Cuts},
{ { LAYER_INFO::CLASS::BOARD_GEOMETRY, LAYER_INFO::SUBCLASS::BGEOM_SILKSCREEN_TOP}, F_SilkS},
{ { LAYER_INFO::CLASS::BOARD_GEOMETRY, LAYER_INFO::SUBCLASS::BGEOM_SILKSCREEN_BOTTOM}, B_SilkS},
{ { LAYER_INFO::CLASS::BOARD_GEOMETRY, LAYER_INFO::SUBCLASS::BGEOM_SOLDERMASK_TOP}, F_Mask},
{ { LAYER_INFO::CLASS::BOARD_GEOMETRY, LAYER_INFO::SUBCLASS::BGEOM_SOLDERMASK_BOTTOM}, B_Mask},
{ { LAYER_INFO::CLASS::COMPONENT_VALUE, LAYER_INFO::SUBCLASS::ASSEMBLY_BOTTOM}, B_Fab},
{ { LAYER_INFO::CLASS::COMPONENT_VALUE, LAYER_INFO::SUBCLASS::ASSEMBLY_TOP}, F_Fab},
{ { LAYER_INFO::CLASS::DEVICE_TYPE, LAYER_INFO::SUBCLASS::ASSEMBLY_BOTTOM}, B_Fab},
{ { LAYER_INFO::CLASS::DEVICE_TYPE, LAYER_INFO::SUBCLASS::ASSEMBLY_TOP}, F_Fab},
{ { LAYER_INFO::CLASS::PACKAGE_GEOMETRY, LAYER_INFO::SUBCLASS::PGEOM_SILKSCREEN_BOTTOM}, B_SilkS},
{ { LAYER_INFO::CLASS::PACKAGE_GEOMETRY, LAYER_INFO::SUBCLASS::PGEOM_SILKSCREEN_TOP}, F_SilkS},
{ { LAYER_INFO::CLASS::PACKAGE_GEOMETRY, LAYER_INFO::SUBCLASS::PGEOM_ASSEMBLY_BOTTOM}, B_Fab},
{ { LAYER_INFO::CLASS::PACKAGE_GEOMETRY, LAYER_INFO::SUBCLASS::PGEOM_ASSEMBLY_TOP}, F_Fab},
{ { LAYER_INFO::CLASS::PACKAGE_GEOMETRY, LAYER_INFO::SUBCLASS::PGEOM_PLACE_BOUND_BOTTOM}, B_CrtYd},
{ { LAYER_INFO::CLASS::PACKAGE_GEOMETRY, LAYER_INFO::SUBCLASS::PGEOM_PLACE_BOUND_TOP}, F_CrtYd},
{ { LAYER_INFO::CLASS::REF_DES, LAYER_INFO::SUBCLASS::SILKSCREEN_BOTTOM}, B_SilkS},
{ { LAYER_INFO::CLASS::REF_DES, LAYER_INFO::SUBCLASS::SILKSCREEN_TOP}, F_SilkS},
{ { LAYER_INFO::CLASS::REF_DES, LAYER_INFO::SUBCLASS::ASSEMBLY_BOTTOM}, B_Fab},
{ { LAYER_INFO::CLASS::REF_DES, LAYER_INFO::SUBCLASS::ASSEMBLY_TOP}, F_Fab},
{ { LAYER_INFO::CLASS::MANUFACTURING, LAYER_INFO::SUBCLASS::MFR_AUTOSILK_BOTTOM}, B_SilkS},
{ { LAYER_INFO::CLASS::MANUFACTURING, LAYER_INFO::SUBCLASS::MFR_AUTOSILK_TOP}, F_SilkS},
}
@ F_CrtYd
Definition layer_ids.h:116
@ Edge_Cuts
Definition layer_ids.h:112
@ B_Mask
Definition layer_ids.h:98
@ F_Mask
Definition layer_ids.h:97
@ F_Fab
Definition layer_ids.h:119
@ F_SilkS
Definition layer_ids.h:100
@ B_CrtYd
Definition layer_ids.h:115
@ B_SilkS
Definition layer_ids.h:101
@ B_Fab
Definition layer_ids.h:118

Map of the pre-set class:subclass pairs to standard layers.

Allegro doesn't really have a neat mapping onto KiCad layers. In theory, we could use the Films to map things that actually end up on the silkscreen layer (films can pick things out by class:subclass), but that would be quite fiddly and would fail if the films weren't configured right.

Definition at line 248 of file allegro_builder.cpp.

Referenced by ALLEGRO::LAYER_MAPPER::FinalizeLayers(), and ALLEGRO::LAYER_MAPPER::GetLayer().

◆ s_OptionalFixedMappings

const std::unordered_map<LAYER_INFO, wxString> s_OptionalFixedMappings
static

Names for custom KiCad layers that correspond to pre-defined Allegro layers.

Multiple class:subclasses can share a layer name, in which case, they will share a layer.

This is a balance between running out of layers and dumping too much unrelated stuff on the same layer.

Definition at line 286 of file allegro_builder.cpp.

Referenced by ALLEGRO::LAYER_MAPPER::GetLayer().

◆ traceAllegroPerf

const wxChar* const traceAllegroPerf = wxT( "KICAD_ALLEGRO_PERF" )
static

Definition at line 68 of file allegro_builder.cpp.