2016-07-19 17:35:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2023-08-11 17:40:13 +00:00
|
|
|
* Copyright (C) 2023 CERN
|
2024-02-09 10:34:27 +00:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file create_layer_items.cpp
|
|
|
|
* @brief This file implements the creation of the pcb board.
|
2020-12-16 22:10:42 +00:00
|
|
|
*
|
2016-07-19 17:35:25 +00:00
|
|
|
* It is based on the function found in the files:
|
|
|
|
* board_items_to_polygon_shape_transform.cpp
|
|
|
|
* board_items_to_polygon_shape_transform.cpp
|
|
|
|
*/
|
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
#include "board_adapter.h"
|
2021-10-21 13:29:19 +00:00
|
|
|
#include "../3d_rendering/raytracing/shapes2D/filled_circle_2d.h"
|
2023-09-22 17:31:04 +00:00
|
|
|
#include "raytracing/shapes2D/triangle_2d.h"
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
|
|
|
#include <pad.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2022-01-30 10:52:52 +00:00
|
|
|
#include <pcb_textbox.h>
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <vector>
|
2018-09-21 04:23:15 +00:00
|
|
|
#include <thread>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2018-09-21 04:23:15 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <atomic>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
#ifdef PRINT_STATISTICS_3D_VIEWER
|
2023-09-07 11:22:10 +00:00
|
|
|
#include <core/profile.h>
|
2020-06-22 19:35:09 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is used to draw pad outlines on silk layers.
|
|
|
|
*/
|
|
|
|
void buildPadOutlineAsPolygon( const PAD* aPad, SHAPE_POLY_SET& aBuffer, int aWidth, int aMaxError,
|
|
|
|
ERROR_LOC aErrorLoc )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-09-21 12:07:10 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE::CIRCLE ) // Draw a ring
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-09-21 12:07:10 +00:00
|
|
|
TransformRingToPolygon( aBuffer, aPad->ShapePos(), aPad->GetSize().x / 2, aWidth,
|
|
|
|
aMaxError, aErrorLoc );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2023-09-21 12:07:10 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// For other shapes, add outlines as thick segments in polygon buffer
|
2023-10-13 11:25:52 +00:00
|
|
|
const SHAPE_LINE_CHAIN& path = aPad->GetEffectivePolygon( ERROR_INSIDE )->COutline( 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
for( int ii = 0; ii < path.PointCount(); ++ii )
|
|
|
|
{
|
|
|
|
const VECTOR2I& a = path.CPoint( ii );
|
|
|
|
const VECTOR2I& b = path.CPoint( ii + 1 );
|
2020-09-27 09:28:05 +00:00
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
TransformOvalToPolygon( aBuffer, a, b, aWidth, aMaxError, aErrorLoc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
void transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer,
|
|
|
|
SHAPE_POLY_SET& aBuffer, int aMaxError, ERROR_LOC aErrorLoc )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
|
|
|
|
{
|
|
|
|
if( item->Type() == PCB_SHAPE_T || BaseType( item->Type() ) == PCB_DIMENSION_T )
|
|
|
|
{
|
|
|
|
if( item->GetLayer() == aLayer )
|
|
|
|
item->TransformShapeToPolygon( aBuffer, aLayer, 0, aMaxError, aErrorLoc );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2023-09-21 12:07:10 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
void BOARD_ADAPTER::destroyLayers()
|
|
|
|
{
|
|
|
|
#define DELETE_AND_FREE( ptr ) \
|
|
|
|
{ \
|
|
|
|
delete ptr; \
|
|
|
|
ptr = nullptr; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
#define DELETE_AND_FREE_MAP( map ) \
|
|
|
|
{ \
|
|
|
|
for( auto& [ layer, poly ] : map ) \
|
|
|
|
delete poly; \
|
|
|
|
\
|
|
|
|
map.clear(); \
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
DELETE_AND_FREE_MAP( m_layers_poly );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2024-03-28 13:52:31 +00:00
|
|
|
DELETE_AND_FREE( m_frontPlatedPadAndGraphicPolys )
|
|
|
|
DELETE_AND_FREE( m_backPlatedPadAndGraphicPolys )
|
2023-09-22 17:31:04 +00:00
|
|
|
DELETE_AND_FREE( m_frontPlatedCopperPolys )
|
|
|
|
DELETE_AND_FREE( m_backPlatedCopperPolys )
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
DELETE_AND_FREE_MAP( m_layerHoleOdPolys )
|
|
|
|
DELETE_AND_FREE_MAP( m_layerHoleIdPolys )
|
2020-09-27 09:28:05 +00:00
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
m_NPTH_ODPolys.RemoveAllContours();
|
|
|
|
m_TH_ODPolys.RemoveAllContours();
|
|
|
|
m_viaTH_ODPolys.RemoveAllContours();
|
2023-09-22 13:03:15 +00:00
|
|
|
m_viaAnnuliPolys.RemoveAllContours();
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
DELETE_AND_FREE_MAP( m_layerMap )
|
|
|
|
DELETE_AND_FREE_MAP( m_layerHoleMap )
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
DELETE_AND_FREE( m_platedPadsFront )
|
|
|
|
DELETE_AND_FREE( m_platedPadsBack )
|
2023-09-22 19:48:13 +00:00
|
|
|
DELETE_AND_FREE( m_offboardPadsFront )
|
|
|
|
DELETE_AND_FREE( m_offboardPadsBack )
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-20 13:27:57 +00:00
|
|
|
m_TH_ODs.Clear();
|
2023-09-21 12:07:10 +00:00
|
|
|
m_TH_IDs.Clear();
|
2023-09-22 13:03:15 +00:00
|
|
|
m_viaAnnuli.Clear();
|
2023-09-20 13:27:57 +00:00
|
|
|
m_viaTH_ODs.Clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
destroyLayers();
|
|
|
|
|
|
|
|
// Build Copper layers
|
2020-12-16 22:10:42 +00:00
|
|
|
// Based on:
|
|
|
|
// https://github.com/KiCad/kicad-source-mirror/blob/master/3d-viewer/3d_draw.cpp#L692
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
#ifdef PRINT_STATISTICS_3D_VIEWER
|
2024-03-03 18:39:53 +00:00
|
|
|
int64_t stats_startCopperLayersTime = GetRunningMicroSecs();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2024-03-03 18:39:53 +00:00
|
|
|
int64_t start_Time = stats_startCopperLayersTime;
|
2016-07-19 17:35:25 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID cu_seq[MAX_CU_LAYERS];
|
2020-03-24 01:01:23 +00:00
|
|
|
LSET cu_set = LSET::AllCuMask( m_copperLayersCount );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 13:03:15 +00:00
|
|
|
EDA_3D_VIEWER_SETTINGS::RENDER_SETTINGS& cfg = m_Cfg->m_Render;
|
|
|
|
|
2023-08-11 17:40:13 +00:00
|
|
|
std::bitset<LAYER_3D_END> visibilityFlags = GetVisibleLayers();
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_trackCount = 0;
|
|
|
|
m_averageTrackWidth = 0;
|
|
|
|
m_viaCount = 0;
|
|
|
|
m_averageViaHoleDiameter = 0;
|
|
|
|
m_holeCount = 0;
|
|
|
|
m_averageHoleDiameter = 0;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-07-18 15:44:54 +00:00
|
|
|
if( !m_board )
|
|
|
|
return;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Prepare track list, convert in a vector. Calc statistic for the holes
|
2021-06-11 21:07:02 +00:00
|
|
|
std::vector<const PCB_TRACK*> trackList;
|
2016-07-19 17:35:25 +00:00
|
|
|
trackList.clear();
|
2019-05-31 02:30:28 +00:00
|
|
|
trackList.reserve( m_board->Tracks().size() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
int maxError = m_board->GetDesignSettings().m_MaxError;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-08-11 17:40:13 +00:00
|
|
|
if( !Is3dLayerEnabled( track->GetLayer(), visibilityFlags ) ) // Skip non enabled layers
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
// Note: a PCB_TRACK holds normal segment tracks and also vias circles (that have also
|
|
|
|
// drill values)
|
2016-07-19 17:35:25 +00:00
|
|
|
trackList.push_back( track );
|
|
|
|
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_VIA *via = static_cast< const PCB_VIA*>( track );
|
2021-01-05 22:19:00 +00:00
|
|
|
m_viaCount++;
|
2023-09-22 11:12:35 +00:00
|
|
|
m_averageViaHoleDiameter += static_cast<float>( via->GetDrillValue() * m_biuTo3Dunits );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
m_trackCount++;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2023-09-22 11:12:35 +00:00
|
|
|
m_averageTrackWidth += static_cast<float>( track->GetWidth() * m_biuTo3Dunits );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_trackCount )
|
|
|
|
m_averageTrackWidth /= (float)m_trackCount;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_viaCount )
|
|
|
|
m_averageViaHoleDiameter /= (float)m_viaCount;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Prepare copper layers index and containers
|
2022-10-21 12:48:45 +00:00
|
|
|
std::vector<PCB_LAYER_ID> layer_ids;
|
|
|
|
layer_ids.clear();
|
|
|
|
layer_ids.reserve( m_copperLayersCount );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
for( unsigned i = 0; i < arrayDim( cu_seq ); ++i )
|
2016-07-19 17:35:25 +00:00
|
|
|
cu_seq[i] = ToLAYER_ID( B_Cu - i );
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
for( LSEQ cu = cu_set.Seq( cu_seq, arrayDim( cu_seq ) ); cu; ++cu )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
const PCB_LAYER_ID layer = *cu;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-08-11 17:40:13 +00:00
|
|
|
if( !Is3dLayerEnabled( layer, visibilityFlags ) ) // Skip non enabled layers
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
layer_ids.push_back( layer );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
BVH_CONTAINER_2D *layerContainer = new BVH_CONTAINER_2D;
|
2022-10-21 12:48:45 +00:00
|
|
|
m_layerMap[layer] = layerContainer;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.opengl_copper_thickness && cfg.engine == RENDER_ENGINE::OPENGL )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-09-22 13:03:15 +00:00
|
|
|
SHAPE_POLY_SET* layerPoly = new SHAPE_POLY_SET;
|
2022-10-21 12:48:45 +00:00
|
|
|
m_layers_poly[layer] = layerPoly;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
if( cfg.differentiate_plated_copper )
|
2020-09-27 09:28:05 +00:00
|
|
|
{
|
2024-03-28 13:52:31 +00:00
|
|
|
m_frontPlatedPadAndGraphicPolys = new SHAPE_POLY_SET;
|
|
|
|
m_backPlatedPadAndGraphicPolys = new SHAPE_POLY_SET;
|
2023-09-22 17:31:04 +00:00
|
|
|
m_frontPlatedCopperPolys = new SHAPE_POLY_SET;
|
|
|
|
m_backPlatedCopperPolys = new SHAPE_POLY_SET;
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_platedPadsFront = new BVH_CONTAINER_2D;
|
|
|
|
m_platedPadsBack = new BVH_CONTAINER_2D;
|
2020-09-27 09:28:05 +00:00
|
|
|
}
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2023-09-22 19:48:13 +00:00
|
|
|
if( cfg.show_off_board_silk )
|
|
|
|
{
|
|
|
|
m_offboardPadsFront = new BVH_CONTAINER_2D;
|
|
|
|
m_offboardPadsBack = new BVH_CONTAINER_2D;
|
|
|
|
}
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Create tracks and vias" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Create tracks as objects and add it to container
|
2022-10-21 12:48:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : layer_ids )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
wxASSERT( m_layerMap.find( layer ) != m_layerMap.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
BVH_CONTAINER_2D *layerContainer = m_layerMap[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
for( const PCB_TRACK* track : trackList )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// NOTE: Vias can be on multiple layers
|
2022-10-21 12:48:45 +00:00
|
|
|
if( !track->IsOnLayer( layer ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
2023-06-24 17:19:44 +00:00
|
|
|
// Skip vias annulus when not flashed on this layer
|
|
|
|
if( track->Type() == PCB_VIA_T
|
|
|
|
&& !static_cast<const PCB_VIA*>( track )->FlashLayer( layer ) )
|
|
|
|
{
|
2020-08-11 09:26:00 +00:00
|
|
|
continue;
|
2023-06-24 17:19:44 +00:00
|
|
|
}
|
2020-08-11 09:26:00 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Add object item to layer container
|
2022-01-10 14:03:53 +00:00
|
|
|
createTrack( track, layerContainer );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create VIAS and THTs objects and add it to holes containers
|
2022-10-21 12:48:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : layer_ids )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// ADD TRACKS
|
|
|
|
unsigned int nTracks = trackList.size();
|
|
|
|
|
|
|
|
for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_TRACK *track = trackList[trackIdx];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
if( !track->IsOnLayer( layer ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// ADD VIAS and THT
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
|
|
|
|
const VIATYPE viatype = via->GetViaType();
|
2023-09-22 11:12:35 +00:00
|
|
|
const double holediameter = via->GetDrillValue() * BiuTo3dUnits();
|
|
|
|
const double viasize = via->GetWidth() * BiuTo3dUnits();
|
|
|
|
const double plating = GetHolePlatingThickness() * BiuTo3dUnits();
|
2021-04-18 20:17:31 +00:00
|
|
|
|
|
|
|
// holes and layer copper extend half info cylinder wall to hide transition
|
2023-09-22 11:12:35 +00:00
|
|
|
const float thickness = static_cast<float>( plating / 2.0f );
|
|
|
|
const float hole_inner_radius = static_cast<float>( holediameter / 2.0f );
|
|
|
|
const float ring_radius = static_cast<float>( viasize / 2.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
const SFVEC2F via_center( via->GetStart().x * m_biuTo3Dunits,
|
|
|
|
-via->GetStart().y * m_biuTo3Dunits );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( viatype != VIATYPE::THROUGH )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Add hole objects
|
2021-01-02 21:05:29 +00:00
|
|
|
BVH_CONTAINER_2D *layerHoleContainer = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Check if the layer is already created
|
2022-10-21 12:48:45 +00:00
|
|
|
if( m_layerHoleMap.find( layer ) == m_layerHoleMap.end() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// not found, create a new container
|
2021-01-02 21:05:29 +00:00
|
|
|
layerHoleContainer = new BVH_CONTAINER_2D;
|
2022-10-21 12:48:45 +00:00
|
|
|
m_layerHoleMap[layer] = layerHoleContainer;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// found
|
2022-10-21 12:48:45 +00:00
|
|
|
layerHoleContainer = m_layerHoleMap[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a hole for this layer
|
2021-01-02 21:05:29 +00:00
|
|
|
layerHoleContainer->Add( new FILLED_CIRCLE_2D( via_center,
|
|
|
|
hole_inner_radius + thickness,
|
|
|
|
*track ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2022-10-21 12:48:45 +00:00
|
|
|
else if( layer == layer_ids[0] ) // it only adds once the THT holes
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Add through hole object
|
2023-09-20 13:27:57 +00:00
|
|
|
m_TH_ODs.Add( new FILLED_CIRCLE_2D( via_center, hole_inner_radius + thickness,
|
|
|
|
*track ) );
|
|
|
|
m_viaTH_ODs.Add( new FILLED_CIRCLE_2D( via_center, hole_inner_radius + thickness,
|
|
|
|
*track ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.clip_silk_on_via_annuli && ring_radius > 0.0 )
|
|
|
|
m_viaAnnuli.Add( new FILLED_CIRCLE_2D( via_center, ring_radius, *track ) );
|
2020-07-16 22:36:06 +00:00
|
|
|
|
2023-01-29 22:39:29 +00:00
|
|
|
if( hole_inner_radius > 0.0 )
|
2023-09-20 13:27:57 +00:00
|
|
|
m_TH_IDs.Add( new FILLED_CIRCLE_2D( via_center, hole_inner_radius, *track ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-22 17:31:04 +00:00
|
|
|
|
|
|
|
if( cfg.differentiate_plated_copper && layer == F_Cu )
|
|
|
|
{
|
|
|
|
track->TransformShapeToPolygon( *m_frontPlatedCopperPolys, F_Cu, 0, maxError,
|
|
|
|
ERROR_INSIDE );
|
|
|
|
}
|
|
|
|
else if( cfg.differentiate_plated_copper && layer == B_Cu )
|
|
|
|
{
|
|
|
|
track->TransformShapeToPolygon( *m_backPlatedCopperPolys, B_Cu, 0, maxError,
|
|
|
|
ERROR_INSIDE );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create VIAS and THTs objects and add it to holes containers
|
2022-10-21 12:48:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : layer_ids )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// ADD TRACKS
|
|
|
|
const unsigned int nTracks = trackList.size();
|
|
|
|
|
|
|
|
for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_TRACK *track = trackList[trackIdx];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
if( !track->IsOnLayer( layer ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// ADD VIAS and THT
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
|
|
|
|
const VIATYPE viatype = via->GetViaType();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( viatype != VIATYPE::THROUGH )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
// Add PCB_VIA hole contours
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-08-20 17:02:28 +00:00
|
|
|
// Add outer holes of VIAs
|
2021-01-02 21:05:29 +00:00
|
|
|
SHAPE_POLY_SET *layerOuterHolesPoly = nullptr;
|
|
|
|
SHAPE_POLY_SET *layerInnerHolesPoly = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Check if the layer is already created
|
2022-10-21 12:48:45 +00:00
|
|
|
if( m_layerHoleOdPolys.find( layer ) == m_layerHoleOdPolys.end() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// not found, create a new container
|
|
|
|
layerOuterHolesPoly = new SHAPE_POLY_SET;
|
2022-10-21 12:48:45 +00:00
|
|
|
m_layerHoleOdPolys[layer] = layerOuterHolesPoly;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
wxASSERT( m_layerHoleIdPolys.find( layer ) == m_layerHoleIdPolys.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
layerInnerHolesPoly = new SHAPE_POLY_SET;
|
2022-10-21 12:48:45 +00:00
|
|
|
m_layerHoleIdPolys[layer] = layerInnerHolesPoly;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// found
|
2022-10-21 12:48:45 +00:00
|
|
|
layerOuterHolesPoly = m_layerHoleOdPolys[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
wxASSERT( m_layerHoleIdPolys.find( layer ) != m_layerHoleIdPolys.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
layerInnerHolesPoly = m_layerHoleIdPolys[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const int holediameter = via->GetDrillValue();
|
2021-01-05 22:19:00 +00:00
|
|
|
const int hole_outer_radius = (holediameter / 2) + GetHolePlatingThickness();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-05-22 13:33:48 +00:00
|
|
|
TransformCircleToPolygon( *layerOuterHolesPoly, via->GetStart(),
|
2022-10-21 12:48:45 +00:00
|
|
|
hole_outer_radius, maxError, ERROR_INSIDE );
|
2019-05-22 13:33:48 +00:00
|
|
|
|
|
|
|
TransformCircleToPolygon( *layerInnerHolesPoly, via->GetStart(),
|
2022-10-21 12:48:45 +00:00
|
|
|
holediameter / 2, maxError, ERROR_INSIDE );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2022-10-21 12:48:45 +00:00
|
|
|
else if( layer == layer_ids[0] ) // it only adds once the THT holes
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
const int holediameter = via->GetDrillValue();
|
2021-01-05 22:19:00 +00:00
|
|
|
const int hole_outer_radius = (holediameter / 2) + GetHolePlatingThickness();
|
2023-09-22 11:12:35 +00:00
|
|
|
const int hole_outer_ring_radius = KiROUND( via->GetWidth() / 2.0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
// Add through hole contours
|
2023-09-20 13:27:57 +00:00
|
|
|
TransformCircleToPolygon( m_TH_ODPolys, via->GetStart(), hole_outer_radius,
|
|
|
|
maxError, ERROR_INSIDE );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Add same thing for vias only
|
2023-09-20 13:27:57 +00:00
|
|
|
TransformCircleToPolygon( m_viaTH_ODPolys, via->GetStart(), hole_outer_radius,
|
|
|
|
maxError, ERROR_INSIDE );
|
2020-08-11 09:26:00 +00:00
|
|
|
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.clip_silk_on_via_annuli )
|
2020-07-16 22:36:06 +00:00
|
|
|
{
|
2023-09-22 13:03:15 +00:00
|
|
|
TransformCircleToPolygon( m_viaAnnuliPolys, via->GetStart(),
|
2022-10-21 12:48:45 +00:00
|
|
|
hole_outer_ring_radius, maxError, ERROR_INSIDE );
|
2020-07-16 22:36:06 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Creates vertical outline contours of the tracks and add it to the poly of the layer
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.opengl_copper_thickness && cfg.engine == RENDER_ENGINE::OPENGL )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : layer_ids )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
wxASSERT( m_layers_poly.find( layer ) != m_layers_poly.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
SHAPE_POLY_SET *layerPoly = m_layers_poly[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// ADD TRACKS
|
|
|
|
unsigned int nTracks = trackList.size();
|
|
|
|
|
|
|
|
for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_TRACK *track = trackList[trackIdx];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
if( !track->IsOnLayer( layer ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
2023-06-24 17:19:44 +00:00
|
|
|
// Skip vias annulus when not flashed on this layer
|
|
|
|
if( track->Type() == PCB_VIA_T
|
2023-09-22 13:03:15 +00:00
|
|
|
&& !static_cast<const PCB_VIA*>( track )->FlashLayer( layer ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
{
|
2020-08-11 09:26:00 +00:00
|
|
|
continue;
|
2023-06-24 17:19:44 +00:00
|
|
|
}
|
2020-08-11 09:26:00 +00:00
|
|
|
|
|
|
|
// Add the track/via contour
|
2022-10-21 12:48:45 +00:00
|
|
|
track->TransformShapeToPolygon( *layerPoly, layer, 0, maxError, ERROR_INSIDE );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Add holes of footprints
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-12-29 19:19:08 +00:00
|
|
|
const VECTOR2I padHole = pad->GetDrillSize();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( !padHole.x ) // Not drilled pad like SMD pad
|
|
|
|
continue;
|
|
|
|
|
2020-10-01 00:13:04 +00:00
|
|
|
// The hole in the body is inflated by copper thickness, if not plated, no copper
|
2023-09-22 11:12:35 +00:00
|
|
|
int inflate = 0;
|
|
|
|
|
|
|
|
if( pad->GetAttribute () != PAD_ATTRIB::NPTH )
|
|
|
|
inflate = KiROUND( GetHolePlatingThickness() / 2.0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_holeCount++;
|
2023-09-22 11:12:35 +00:00
|
|
|
double holeDiameter = ( pad->GetDrillSize().x + pad->GetDrillSize().y ) / 2.0;
|
|
|
|
m_averageHoleDiameter += static_cast<float>( holeDiameter * m_biuTo3Dunits );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-20 13:27:57 +00:00
|
|
|
createPadWithHole( pad, &m_TH_ODs, inflate );
|
2020-08-11 09:26:00 +00:00
|
|
|
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.clip_silk_on_via_annuli )
|
|
|
|
createPadWithHole( pad, &m_viaAnnuli, inflate );
|
2020-08-11 09:26:00 +00:00
|
|
|
|
2023-09-20 13:27:57 +00:00
|
|
|
createPadWithHole( pad, &m_TH_IDs, 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-06 10:20:03 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_holeCount )
|
|
|
|
m_averageHoleDiameter /= (float)m_holeCount;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Add contours of the pad holes (pads can be Circle or Segment holes)
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-12-29 19:19:08 +00:00
|
|
|
const VECTOR2I padHole = pad->GetDrillSize();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( !padHole.x ) // Not drilled pad like SMD pad
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// The hole in the body is inflated by copper thickness.
|
2021-01-05 22:19:00 +00:00
|
|
|
const int inflate = GetHolePlatingThickness();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-05-01 14:46:50 +00:00
|
|
|
if( pad->GetAttribute () != PAD_ATTRIB::NPTH )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.clip_silk_on_via_annuli )
|
|
|
|
pad->TransformHoleToPolygon( m_viaAnnuliPolys, inflate, maxError, ERROR_INSIDE );
|
2020-10-01 00:13:04 +00:00
|
|
|
|
2023-09-20 13:27:57 +00:00
|
|
|
pad->TransformHoleToPolygon( m_TH_ODPolys, inflate, maxError, ERROR_INSIDE );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If not plated, no copper.
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.clip_silk_on_via_annuli )
|
|
|
|
pad->TransformHoleToPolygon( m_viaAnnuliPolys, 0, maxError, ERROR_INSIDE );
|
2020-10-01 00:13:04 +00:00
|
|
|
|
2023-09-20 13:27:57 +00:00
|
|
|
pad->TransformHoleToPolygon( m_NPTH_ODPolys, 0, maxError, ERROR_INSIDE );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Add footprints PADs objects to containers
|
2022-10-21 12:48:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : layer_ids )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
wxASSERT( m_layerMap.find( layer ) != m_layerMap.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
BVH_CONTAINER_2D *layerContainer = m_layerMap[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// ADD PADS
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-09-22 17:31:04 +00:00
|
|
|
addPads( footprint, layerContainer, layer, cfg.differentiate_plated_copper, false );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Micro-wave footprints may have items on copper layers
|
2023-08-11 17:40:13 +00:00
|
|
|
addFootprintShapes( footprint, layerContainer, layer, visibilityFlags );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
// Add footprints PADs poly contours (vertical outlines)
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.opengl_copper_thickness && cfg.engine == RENDER_ENGINE::OPENGL )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : layer_ids )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
wxASSERT( m_layers_poly.find( layer ) != m_layers_poly.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
SHAPE_POLY_SET *layerPoly = m_layers_poly[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Add pads to polygon list
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-03-06 13:35:46 +00:00
|
|
|
// Note: NPTH pads are not drawn on copper layers when the pad has same shape as
|
|
|
|
// its hole
|
2022-10-21 12:48:45 +00:00
|
|
|
footprint->TransformPadsToPolySet( *layerPoly, layer, 0, maxError, ERROR_INSIDE,
|
2023-09-22 17:31:04 +00:00
|
|
|
true, cfg.differentiate_plated_copper, false );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-21 12:07:10 +00:00
|
|
|
transformFPShapesToPolySet( footprint, layer, *layerPoly, maxError, ERROR_INSIDE );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
if( cfg.differentiate_plated_copper )
|
2020-09-06 19:09:43 +00:00
|
|
|
{
|
2020-12-16 22:10:42 +00:00
|
|
|
// ADD PLATED PADS contours
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-09-27 09:28:05 +00:00
|
|
|
{
|
2024-03-28 13:52:31 +00:00
|
|
|
footprint->TransformPadsToPolySet( *m_frontPlatedPadAndGraphicPolys, F_Cu, 0, maxError,
|
2022-10-21 12:48:45 +00:00
|
|
|
ERROR_INSIDE, true, false, true );
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2024-03-28 13:52:31 +00:00
|
|
|
footprint->TransformPadsToPolySet( *m_backPlatedPadAndGraphicPolys, B_Cu, 0, maxError,
|
2022-10-21 12:48:45 +00:00
|
|
|
ERROR_INSIDE, true, false, true );
|
2020-09-27 09:28:05 +00:00
|
|
|
}
|
2020-09-06 19:09:43 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add graphic item on copper layers to object containers
|
2022-10-21 12:48:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : layer_ids )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
wxASSERT( m_layerMap.find( layer ) != m_layerMap.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
BVH_CONTAINER_2D *layerContainer = m_layerMap[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-08-12 10:46:46 +00:00
|
|
|
// Add graphic items on copper layers (texts and other graphics)
|
2020-11-29 14:00:39 +00:00
|
|
|
for( BOARD_ITEM* item : m_board->Drawings() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
if( !item->IsOnLayer( layer ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2022-01-30 10:52:52 +00:00
|
|
|
addShape( static_cast<PCB_SHAPE*>( item ), layerContainer, item );
|
2022-01-10 14:03:53 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
2022-01-30 10:52:52 +00:00
|
|
|
addText( static_cast<PCB_TEXT*>( item ), layerContainer, item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXTBOX_T:
|
2023-11-11 17:11:50 +00:00
|
|
|
addShape( static_cast<PCB_TEXTBOX*>( item ), layerContainer, item );
|
2022-01-10 14:03:53 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_ALIGNED_T:
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_CENTER_T:
|
2021-07-13 18:46:33 +00:00
|
|
|
case PCB_DIM_RADIAL_T:
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_LEADER_T:
|
2022-01-30 10:52:52 +00:00
|
|
|
addShape( static_cast<PCB_DIMENSION_BASE*>( item ), layerContainer, item );
|
2022-01-10 14:03:53 +00:00
|
|
|
break;
|
2017-02-01 13:52:17 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
default:
|
2020-11-13 00:43:45 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "createLayers: item type: %d not implemented" ),
|
2016-07-19 17:35:25 +00:00
|
|
|
item->Type() );
|
2022-01-10 14:03:53 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2024-02-09 10:34:27 +00:00
|
|
|
|
|
|
|
// add also this shape to the plated copper polygon list if required
|
|
|
|
if( cfg.differentiate_plated_copper )
|
|
|
|
{
|
|
|
|
if( layer == F_Cu )
|
|
|
|
item->TransformShapeToPolygon( *m_frontPlatedCopperPolys, F_Cu,
|
|
|
|
0, maxError, ERROR_INSIDE );
|
|
|
|
else if( layer == B_Cu )
|
|
|
|
item->TransformShapeToPolygon( *m_backPlatedCopperPolys, B_Cu,
|
|
|
|
0, maxError, ERROR_INSIDE );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
// Add graphic item on copper layers to poly contours (vertical outlines)
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.opengl_copper_thickness && cfg.engine == RENDER_ENGINE::OPENGL )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : layer_ids )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
wxASSERT( m_layers_poly.find( layer ) != m_layers_poly.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
SHAPE_POLY_SET *layerPoly = m_layers_poly[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-08-12 10:46:46 +00:00
|
|
|
// Add graphic items on copper layers (texts and other )
|
2020-03-24 01:01:23 +00:00
|
|
|
for( BOARD_ITEM* item : m_board->Drawings() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
if( !item->IsOnLayer( layer ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2022-10-21 12:48:45 +00:00
|
|
|
item->TransformShapeToPolygon( *layerPoly, layer, 0, maxError, ERROR_INSIDE );
|
2019-05-14 12:39:34 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
case PCB_TEXT_T:
|
|
|
|
{
|
|
|
|
PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
|
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
text->TransformTextToPolySet( *layerPoly, 0, maxError, ERROR_INSIDE );
|
2022-01-30 10:52:52 +00:00
|
|
|
break;
|
2020-11-29 14:00:39 +00:00
|
|
|
}
|
2022-01-30 10:52:52 +00:00
|
|
|
|
|
|
|
case PCB_TEXTBOX_T:
|
|
|
|
{
|
|
|
|
PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( item );
|
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
textbox->TransformTextToPolySet( *layerPoly, 0, maxError, ERROR_INSIDE );
|
2020-11-29 14:00:39 +00:00
|
|
|
break;
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2020-11-29 14:00:39 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
default:
|
2019-05-14 12:39:34 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "createLayers: item type: %d not implemented" ),
|
2020-03-24 01:01:23 +00:00
|
|
|
item->Type() );
|
2019-05-14 12:39:34 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.show_zones )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Create zones" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-07-20 20:20:34 +00:00
|
|
|
std::vector<std::pair<ZONE*, PCB_LAYER_ID>> zones;
|
|
|
|
std::unordered_map<PCB_LAYER_ID, std::unique_ptr<std::mutex>> layer_lock;
|
2020-06-24 02:19:08 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_board->Zones() )
|
2020-06-24 02:19:08 +00:00
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
2021-07-20 20:20:34 +00:00
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
zones.emplace_back( std::make_pair( zone, layer ) );
|
2021-07-20 20:20:34 +00:00
|
|
|
layer_lock.emplace( layer, std::make_unique<std::mutex>() );
|
2023-09-22 17:31:04 +00:00
|
|
|
|
|
|
|
if( cfg.differentiate_plated_copper && layer == F_Cu )
|
|
|
|
{
|
|
|
|
zone->TransformShapeToPolygon( *m_frontPlatedCopperPolys, F_Cu, 0, maxError,
|
|
|
|
ERROR_INSIDE );
|
|
|
|
}
|
|
|
|
else if( cfg.differentiate_plated_copper && layer == B_Cu )
|
|
|
|
{
|
|
|
|
zone->TransformShapeToPolygon( *m_backPlatedCopperPolys, B_Cu, 0, maxError,
|
|
|
|
ERROR_INSIDE );
|
|
|
|
}
|
2021-07-20 20:20:34 +00:00
|
|
|
}
|
2020-06-24 02:19:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Add zones objects
|
2018-09-21 04:23:15 +00:00
|
|
|
std::atomic<size_t> nextZone( 0 );
|
|
|
|
std::atomic<size_t> threadsFinished( 0 );
|
|
|
|
|
2021-07-20 20:20:34 +00:00
|
|
|
size_t parallelThreadCount = std::min<size_t>( zones.size(),
|
|
|
|
std::max<size_t>( std::thread::hardware_concurrency(), 2 ) );
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2018-09-21 04:23:15 +00:00
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2018-09-21 04:23:15 +00:00
|
|
|
std::thread t = std::thread( [&]()
|
|
|
|
{
|
|
|
|
for( size_t areaId = nextZone.fetch_add( 1 );
|
2020-06-24 02:19:08 +00:00
|
|
|
areaId < zones.size();
|
2018-09-21 04:23:15 +00:00
|
|
|
areaId = nextZone.fetch_add( 1 ) )
|
|
|
|
{
|
2021-07-20 20:20:34 +00:00
|
|
|
ZONE* zone = zones[areaId].first;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-09-21 04:23:15 +00:00
|
|
|
if( zone == nullptr )
|
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
PCB_LAYER_ID layer = zones[areaId].second;
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
auto layerContainer = m_layerMap.find( layer );
|
2021-07-20 20:20:34 +00:00
|
|
|
auto layerPolyContainer = m_layers_poly.find( layer );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( layerContainer != m_layerMap.end() )
|
|
|
|
addSolidAreasShapes( zone, layerContainer->second, layer );
|
2021-07-20 20:20:34 +00:00
|
|
|
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.opengl_copper_thickness && cfg.engine == RENDER_ENGINE::OPENGL
|
|
|
|
&& layerPolyContainer != m_layers_poly.end() )
|
2021-07-20 20:20:34 +00:00
|
|
|
{
|
|
|
|
auto mut_it = layer_lock.find( layer );
|
|
|
|
|
|
|
|
std::lock_guard< std::mutex > lock( *( mut_it->second ) );
|
|
|
|
zone->TransformSolidAreasShapesToPolygon( layer, *layerPolyContainer->second );
|
|
|
|
}
|
2018-09-21 04:23:15 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-09-21 04:23:15 +00:00
|
|
|
threadsFinished++;
|
|
|
|
} );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-09-21 04:23:15 +00:00
|
|
|
t.detach();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2018-09-21 04:23:15 +00:00
|
|
|
|
|
|
|
while( threadsFinished < parallelThreadCount )
|
|
|
|
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
// End Build Copper layers
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
// This will make a union of all added contours
|
2023-09-20 13:27:57 +00:00
|
|
|
m_TH_ODPolys.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
m_NPTH_ODPolys.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
m_viaTH_ODPolys.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2023-09-22 13:03:15 +00:00
|
|
|
m_viaAnnuliPolys.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Build Tech layers
|
2020-12-16 22:10:42 +00:00
|
|
|
// Based on:
|
|
|
|
// https://github.com/KiCad/kicad-source-mirror/blob/master/3d-viewer/3d_draw.cpp#L1059
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Build Tech layers" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// draw graphic items, on technical layers
|
2022-03-01 10:29:35 +00:00
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
static const PCB_LAYER_ID techLayerList[] = {
|
2016-07-19 17:35:25 +00:00
|
|
|
B_Adhes,
|
|
|
|
F_Adhes,
|
|
|
|
B_Paste,
|
|
|
|
F_Paste,
|
|
|
|
B_SilkS,
|
|
|
|
F_SilkS,
|
|
|
|
B_Mask,
|
|
|
|
F_Mask,
|
|
|
|
|
|
|
|
// Aux Layers
|
|
|
|
Dwgs_User,
|
|
|
|
Cmts_User,
|
|
|
|
Eco1_User,
|
2023-08-23 13:04:31 +00:00
|
|
|
Eco2_User
|
2016-07-19 17:35:25 +00:00
|
|
|
};
|
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
std::bitset<LAYER_3D_END> enabledFlags = visibilityFlags;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
if( cfg.subtract_mask_from_silk || cfg.differentiate_plated_copper )
|
|
|
|
{
|
|
|
|
enabledFlags.set( LAYER_3D_SOLDERMASK_TOP );
|
|
|
|
enabledFlags.set( LAYER_3D_SOLDERMASK_BOTTOM );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
for( PCB_LAYER_ID layer : LSET::AllNonCuMask().Seq( techLayerList, arrayDim( techLayerList ) ) )
|
|
|
|
{
|
2021-07-22 14:13:27 +00:00
|
|
|
if( aStatusReporter )
|
2022-10-21 12:48:45 +00:00
|
|
|
aStatusReporter->Report( wxString::Format( _( "Build Tech layer %d" ), (int) layer ) );
|
2021-07-22 14:13:27 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
if( !Is3dLayerEnabled( layer, enabledFlags ) )
|
|
|
|
continue;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
BVH_CONTAINER_2D *layerContainer = new BVH_CONTAINER_2D;
|
2022-10-21 12:48:45 +00:00
|
|
|
m_layerMap[layer] = layerContainer;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
SHAPE_POLY_SET *layerPoly = new SHAPE_POLY_SET;
|
2022-10-21 12:48:45 +00:00
|
|
|
m_layers_poly[layer] = layerPoly;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
if( Is3dLayerEnabled( layer, visibilityFlags ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-09-22 17:31:04 +00:00
|
|
|
// Add drawing objects
|
|
|
|
for( BOARD_ITEM* item : m_board->Drawings() )
|
|
|
|
{
|
|
|
|
if( !item->IsOnLayer( layer ) )
|
|
|
|
continue;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_SHAPE_T:
|
|
|
|
addShape( static_cast<PCB_SHAPE*>( item ), layerContainer, item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
addText( static_cast<PCB_TEXT*>( item ), layerContainer, item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXTBOX_T:
|
2023-11-11 17:11:50 +00:00
|
|
|
addShape( static_cast<PCB_TEXTBOX*>( item ), layerContainer, item );
|
2023-09-22 17:31:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_DIM_ALIGNED_T:
|
|
|
|
case PCB_DIM_CENTER_T:
|
|
|
|
case PCB_DIM_RADIAL_T:
|
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
|
|
|
case PCB_DIM_LEADER_T:
|
|
|
|
addShape( static_cast<PCB_DIMENSION_BASE*>( item ), layerContainer, item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add via tech layers
|
|
|
|
if( ( layer == F_Mask || layer == B_Mask ) && !m_board->GetTentVias() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-09-22 17:31:04 +00:00
|
|
|
int maskExpansion = GetBoard()->GetDesignSettings().m_SolderMaskExpansion;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T
|
|
|
|
&& static_cast<const PCB_VIA*>( track )->FlashLayer( layer ) )
|
|
|
|
{
|
|
|
|
createViaWithMargin( track, layerContainer, maskExpansion );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
// Add footprints tech layers - objects
|
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
|
|
|
{
|
|
|
|
if( layer == F_SilkS || layer == B_SilkS )
|
|
|
|
{
|
|
|
|
int linewidth = m_board->GetDesignSettings().m_LineThickness[ LAYER_CLASS_SILK ];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
{
|
|
|
|
if( !pad->IsOnLayer( layer ) )
|
|
|
|
continue;
|
2017-02-01 13:52:17 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
buildPadOutlineAsSegments( pad, layerContainer, linewidth );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addPads( footprint, layerContainer, layer, false, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
addFootprintShapes( footprint, layerContainer, layer, visibilityFlags );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw non copper zones
|
|
|
|
if( cfg.show_zones )
|
|
|
|
{
|
|
|
|
for( ZONE* zone : m_board->Zones() )
|
|
|
|
{
|
|
|
|
if( zone->IsOnLayer( layer ) )
|
|
|
|
addSolidAreasShapes( zone, layerContainer, layer );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
// Add item contours. We need these if we're building vertical walls or if this is a
|
|
|
|
// mask layer and we're differentiating copper from plated copper.
|
|
|
|
if( ( cfg.engine == RENDER_ENGINE::OPENGL && cfg.opengl_copper_thickness )
|
|
|
|
|| ( cfg.differentiate_plated_copper && ( layer == F_Mask || layer == B_Mask ) ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-09-22 17:31:04 +00:00
|
|
|
// DRAWINGS
|
2022-03-01 10:29:35 +00:00
|
|
|
for( BOARD_ITEM* item : m_board->Drawings() )
|
2020-11-29 14:00:39 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
if( !item->IsOnLayer( layer ) )
|
2022-03-01 10:29:35 +00:00
|
|
|
continue;
|
2020-11-29 14:00:39 +00:00
|
|
|
|
2022-03-01 10:29:35 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_SHAPE_T:
|
2022-10-21 12:48:45 +00:00
|
|
|
item->TransformShapeToPolygon( *layerPoly, layer, 0, maxError, ERROR_INSIDE );
|
2022-03-01 10:29:35 +00:00
|
|
|
break;
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2022-03-01 10:29:35 +00:00
|
|
|
case PCB_TEXT_T:
|
|
|
|
{
|
|
|
|
PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
text->TransformTextToPolySet( *layerPoly, 0, maxError, ERROR_INSIDE );
|
2022-03-01 10:29:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-11-29 14:00:39 +00:00
|
|
|
|
2022-03-01 10:29:35 +00:00
|
|
|
case PCB_TEXTBOX_T:
|
|
|
|
{
|
|
|
|
PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( item );
|
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
textbox->TransformTextToPolySet( *layerPoly, 0, maxError, ERROR_INSIDE );
|
2022-03-01 10:29:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2023-07-12 17:27:11 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
// NON-TENTED VIAS
|
|
|
|
if( ( layer == F_Mask || layer == B_Mask ) && !m_board->GetTentVias() )
|
2023-07-12 17:27:11 +00:00
|
|
|
{
|
2023-09-22 17:31:04 +00:00
|
|
|
int maskExpansion = GetBoard()->GetDesignSettings().m_SolderMaskExpansion;
|
2023-07-12 17:27:11 +00:00
|
|
|
|
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T
|
|
|
|
&& static_cast<const PCB_VIA*>( track )->FlashLayer( layer ) )
|
|
|
|
{
|
|
|
|
track->TransformShapeToPolygon( *layerPoly, layer, maskExpansion, maxError,
|
|
|
|
ERROR_INSIDE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
// FOOTPRINT CHILDREN
|
2022-03-01 10:29:35 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
if( layer == F_SilkS || layer == B_SilkS )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-03-01 10:29:35 +00:00
|
|
|
int linewidth = m_board->GetDesignSettings().m_LineThickness[ LAYER_CLASS_SILK ];
|
|
|
|
|
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
{
|
2023-09-21 12:07:10 +00:00
|
|
|
if( pad->IsOnLayer( layer ) )
|
|
|
|
{
|
|
|
|
buildPadOutlineAsPolygon( pad, *layerPoly, linewidth, maxError,
|
|
|
|
ERROR_INSIDE );
|
|
|
|
}
|
2022-03-01 10:29:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
footprint->TransformPadsToPolySet( *layerPoly, layer, 0, maxError, ERROR_INSIDE );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 10:29:35 +00:00
|
|
|
// On tech layers, use a poor circle approximation, only for texts (stroke font)
|
2022-10-21 12:48:45 +00:00
|
|
|
footprint->TransformFPTextToPolySet( *layerPoly, layer, 0, maxError, ERROR_INSIDE );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-03-01 10:29:35 +00:00
|
|
|
// Add the remaining things with dynamic seg count for circles
|
2023-09-21 12:07:10 +00:00
|
|
|
transformFPShapesToPolySet( footprint, layer, *layerPoly, maxError, ERROR_INSIDE );
|
2022-03-01 10:29:35 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
if( cfg.show_zones || layer == F_Mask || layer == B_Mask )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-03-01 10:29:35 +00:00
|
|
|
for( ZONE* zone : m_board->Zones() )
|
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
if( zone->IsOnLayer( layer ) )
|
|
|
|
zone->TransformSolidAreasShapesToPolygon( layer, *layerPoly );
|
2022-03-01 10:29:35 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
// This will make a union of all added contours
|
|
|
|
layerPoly->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
// End Build Tech layers
|
|
|
|
|
2023-09-22 19:48:13 +00:00
|
|
|
// If we're rendering off-board silk, also render pads of footprints which are entirely
|
|
|
|
// outside the board outline. This makes off-board footprints more visually recognizable.
|
2023-09-22 13:03:15 +00:00
|
|
|
if( cfg.show_off_board_silk )
|
2023-09-20 22:28:30 +00:00
|
|
|
{
|
|
|
|
BOX2I boardBBox = m_board_poly.BBox();
|
|
|
|
|
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
|
|
|
{
|
|
|
|
if( !footprint->GetBoundingBox().Intersects( boardBBox ) )
|
|
|
|
{
|
|
|
|
if( footprint->IsFlipped() )
|
2023-09-22 19:48:13 +00:00
|
|
|
addPads( footprint, m_offboardPadsBack, B_Cu, false, false );
|
2023-09-20 22:28:30 +00:00
|
|
|
else
|
2023-09-22 19:48:13 +00:00
|
|
|
addPads( footprint, m_offboardPadsFront, F_Cu, false, false );
|
2023-09-20 22:28:30 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-22 19:48:13 +00:00
|
|
|
|
|
|
|
m_offboardPadsFront->BuildBVH();
|
|
|
|
m_offboardPadsBack->BuildBVH();
|
2023-09-20 22:28:30 +00:00
|
|
|
}
|
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
// Simplify layer polygons
|
|
|
|
|
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Simplifying copper layer polygons" ) );
|
|
|
|
|
|
|
|
if( cfg.differentiate_plated_copper )
|
|
|
|
{
|
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Calculating plated copper" ) );
|
|
|
|
|
|
|
|
// TRIM PLATED COPPER TO SOLDERMASK
|
|
|
|
if( m_layers_poly.find( F_Mask ) != m_layers_poly.end() )
|
|
|
|
{
|
|
|
|
m_frontPlatedCopperPolys->BooleanIntersection( *m_layers_poly.at( F_Mask ),
|
|
|
|
SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_layers_poly.find( B_Mask ) != m_layers_poly.end() )
|
|
|
|
{
|
|
|
|
m_backPlatedCopperPolys->BooleanIntersection( *m_layers_poly.at( B_Mask ),
|
|
|
|
SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
|
|
|
|
2024-03-28 13:52:31 +00:00
|
|
|
// Subtract plated copper from unplated copper
|
|
|
|
bool hasF_Cu = false;
|
|
|
|
bool hasB_Cu = false;
|
|
|
|
|
2023-09-22 17:31:04 +00:00
|
|
|
if( m_layers_poly.find( F_Cu ) != m_layers_poly.end() )
|
|
|
|
{
|
2024-03-28 13:52:31 +00:00
|
|
|
m_layers_poly[F_Cu]->BooleanSubtract( *m_frontPlatedPadAndGraphicPolys, SHAPE_POLY_SET::PM_FAST );
|
2023-09-22 17:31:04 +00:00
|
|
|
m_layers_poly[F_Cu]->BooleanSubtract( *m_frontPlatedCopperPolys, SHAPE_POLY_SET::PM_FAST );
|
2024-03-28 13:52:31 +00:00
|
|
|
hasF_Cu = true;
|
2023-09-22 17:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_layers_poly.find( B_Cu ) != m_layers_poly.end() )
|
|
|
|
{
|
2024-03-28 13:52:31 +00:00
|
|
|
m_layers_poly[B_Cu]->BooleanSubtract( *m_backPlatedPadAndGraphicPolys, SHAPE_POLY_SET::PM_FAST );
|
2023-09-22 17:31:04 +00:00
|
|
|
m_layers_poly[B_Cu]->BooleanSubtract( *m_backPlatedCopperPolys, SHAPE_POLY_SET::PM_FAST );
|
2024-03-28 13:52:31 +00:00
|
|
|
hasB_Cu = true;
|
2023-09-22 17:31:04 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 13:52:31 +00:00
|
|
|
// Add plated graphic items to build vertical walls
|
|
|
|
if( hasF_Cu && m_frontPlatedCopperPolys->OutlineCount() )
|
|
|
|
m_frontPlatedPadAndGraphicPolys->Append( *m_frontPlatedCopperPolys );
|
|
|
|
|
|
|
|
if( hasB_Cu && m_backPlatedCopperPolys->OutlineCount() )
|
|
|
|
m_backPlatedPadAndGraphicPolys->Append( *m_backPlatedCopperPolys );
|
|
|
|
|
|
|
|
m_frontPlatedPadAndGraphicPolys->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
m_backPlatedPadAndGraphicPolys->Simplify( SHAPE_POLY_SET::PM_FAST );
|
2023-09-22 17:31:04 +00:00
|
|
|
m_frontPlatedCopperPolys->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
m_backPlatedCopperPolys->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
// ADD PLATED PADS
|
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
|
|
|
{
|
|
|
|
addPads( footprint, m_platedPadsFront, F_Cu, false, true );
|
|
|
|
addPads( footprint, m_platedPadsBack, B_Cu, false, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
// ADD PLATED COPPER
|
|
|
|
ConvertPolygonToTriangles( *m_frontPlatedCopperPolys, *m_platedPadsFront, m_biuTo3Dunits,
|
|
|
|
*m_board->GetItem( niluuid ) );
|
|
|
|
|
|
|
|
ConvertPolygonToTriangles( *m_backPlatedCopperPolys, *m_platedPadsBack, m_biuTo3Dunits,
|
|
|
|
*m_board->GetItem( niluuid ) );
|
|
|
|
|
|
|
|
m_platedPadsFront->BuildBVH();
|
|
|
|
m_platedPadsBack->BuildBVH();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( cfg.opengl_copper_thickness && cfg.engine == RENDER_ENGINE::OPENGL )
|
|
|
|
{
|
|
|
|
std::vector<PCB_LAYER_ID> &selected_layer_id = layer_ids;
|
|
|
|
std::vector<PCB_LAYER_ID> layer_id_without_F_and_B;
|
|
|
|
|
|
|
|
if( cfg.differentiate_plated_copper )
|
|
|
|
{
|
|
|
|
layer_id_without_F_and_B.clear();
|
|
|
|
layer_id_without_F_and_B.reserve( layer_ids.size() );
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer: layer_ids )
|
|
|
|
{
|
|
|
|
if( layer != F_Cu && layer != B_Cu )
|
|
|
|
layer_id_without_F_and_B.push_back( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
selected_layer_id = layer_id_without_F_and_B;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( selected_layer_id.size() > 0 )
|
|
|
|
{
|
|
|
|
if( aStatusReporter )
|
|
|
|
{
|
|
|
|
aStatusReporter->Report( wxString::Format( _( "Simplifying %d copper layers" ),
|
|
|
|
(int) selected_layer_id.size() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::atomic<size_t> nextItem( 0 );
|
|
|
|
std::atomic<size_t> threadsFinished( 0 );
|
|
|
|
|
|
|
|
size_t parallelThreadCount = std::min<size_t>(
|
|
|
|
std::max<size_t>( std::thread::hardware_concurrency(), 2 ),
|
|
|
|
selected_layer_id.size() );
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
|
|
|
{
|
|
|
|
std::thread t = std::thread(
|
|
|
|
[&nextItem, &threadsFinished, &selected_layer_id, this]()
|
|
|
|
{
|
|
|
|
for( size_t i = nextItem.fetch_add( 1 );
|
|
|
|
i < selected_layer_id.size();
|
|
|
|
i = nextItem.fetch_add( 1 ) )
|
|
|
|
{
|
|
|
|
auto layerPoly = m_layers_poly.find( selected_layer_id[i] );
|
|
|
|
|
|
|
|
if( layerPoly != m_layers_poly.end() )
|
|
|
|
{
|
|
|
|
// This will make a union of all added contours
|
2024-03-04 12:00:21 +00:00
|
|
|
layerPoly->second->ClearArcs();
|
2023-09-22 17:31:04 +00:00
|
|
|
layerPoly->second->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
threadsFinished++;
|
|
|
|
} );
|
|
|
|
|
|
|
|
t.detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
while( threadsFinished < parallelThreadCount )
|
|
|
|
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simplify holes polygon contours
|
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Simplify holes contours" ) );
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : layer_ids )
|
|
|
|
{
|
|
|
|
if( m_layerHoleOdPolys.find( layer ) != m_layerHoleOdPolys.end() )
|
|
|
|
{
|
|
|
|
// found
|
|
|
|
SHAPE_POLY_SET *polyLayer = m_layerHoleOdPolys[layer];
|
|
|
|
polyLayer->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
wxASSERT( m_layerHoleIdPolys.find( layer ) != m_layerHoleIdPolys.end() );
|
|
|
|
|
|
|
|
polyLayer = m_layerHoleIdPolys[layer];
|
|
|
|
polyLayer->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 10:46:46 +00:00
|
|
|
// Build BVH (Bounding volume hierarchy) for holes and vias
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Build BVH for holes and vias" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-20 13:27:57 +00:00
|
|
|
m_TH_IDs.BuildBVH();
|
|
|
|
m_TH_ODs.BuildBVH();
|
2023-09-22 13:03:15 +00:00
|
|
|
m_viaAnnuli.BuildBVH();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( !m_layerHoleMap.empty() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-07-29 21:02:35 +00:00
|
|
|
for( std::pair<const PCB_LAYER_ID, BVH_CONTAINER_2D*>& hole : m_layerHoleMap )
|
2020-03-24 01:01:23 +00:00
|
|
|
hole.second->BuildBVH();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We only need the Solder mask to initialize the BVH
|
|
|
|
// because..?
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_layerMap[B_Mask] )
|
|
|
|
m_layerMap[B_Mask]->BuildBVH();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_layerMap[F_Mask] )
|
|
|
|
m_layerMap[F_Mask]->BuildBVH();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|