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>
|
2020-08-12 10:46:46 +00:00
|
|
|
* Copyright (C) 1992-2020 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.
|
|
|
|
* 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"
|
2016-07-19 17:35:25 +00:00
|
|
|
#include "../3d_rendering/3d_render_raytracing/shapes2D/cring2d.h"
|
|
|
|
#include "../3d_rendering/3d_render_raytracing/shapes2D/cfilledcircle2d.h"
|
|
|
|
#include "../3d_rendering/3d_render_raytracing/shapes3D/ccylinder.h"
|
2018-09-21 04:23:15 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_pad.h>
|
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <class_edge_mod.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <vector>
|
2018-09-21 04:23:15 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <atomic>
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
#ifdef PRINT_STATISTICS_3D_VIEWER
|
2018-01-28 13:05:17 +00:00
|
|
|
#include <profile.h>
|
2020-06-22 19:35:09 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
void BOARD_ADAPTER::destroyLayers()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( !m_layers_poly.empty() )
|
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( auto& poly : m_layers_poly )
|
|
|
|
delete poly.second;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_layers_poly.clear();
|
|
|
|
}
|
|
|
|
|
2020-09-06 19:09:43 +00:00
|
|
|
delete m_F_Cu_PlatedPads_poly;
|
|
|
|
delete m_B_Cu_PlatedPads_poly;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( !m_layers_inner_holes_poly.empty() )
|
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( auto& poly : m_layers_inner_holes_poly )
|
|
|
|
delete poly.second;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_layers_inner_holes_poly.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_layers_outer_holes_poly.empty() )
|
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( auto& poly : m_layers_outer_holes_poly )
|
|
|
|
delete poly.second;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_layers_outer_holes_poly.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_layers_container2D.empty() )
|
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( auto& poly : m_layers_container2D )
|
|
|
|
delete poly.second;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_layers_container2D.clear();
|
|
|
|
}
|
|
|
|
|
2020-09-06 19:09:43 +00:00
|
|
|
delete m_platedpads_container2D_F_Cu;
|
|
|
|
delete m_platedpads_container2D_B_Cu;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( !m_layers_holes2D.empty() )
|
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( auto& poly : m_layers_holes2D )
|
|
|
|
delete poly.second;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_layers_holes2D.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_through_holes_inner.Clear();
|
|
|
|
m_through_holes_outer.Clear();
|
2020-07-16 22:36:06 +00:00
|
|
|
m_through_holes_outer_ring.Clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
m_through_holes_vias_outer.Clear();
|
2020-07-16 22:36:06 +00:00
|
|
|
m_through_holes_vias_outer_ring.Clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
m_through_holes_vias_inner.Clear();
|
|
|
|
m_through_outer_holes_poly_NPTH.RemoveAllContours();
|
|
|
|
m_through_outer_holes_poly.RemoveAllContours();
|
|
|
|
|
|
|
|
m_through_outer_holes_vias_poly.RemoveAllContours();
|
2020-07-16 22:36:06 +00:00
|
|
|
m_through_outer_ring_holes_vias_poly.RemoveAllContours();
|
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
|
|
|
|
// Based on: https://github.com/KiCad/kicad-source-mirror/blob/master/3d-viewer/3d_draw.cpp#L692
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
#ifdef PRINT_STATISTICS_3D_VIEWER
|
2016-07-19 17:35:25 +00:00
|
|
|
unsigned stats_startCopperLayersTime = GetRunningMicroSecs();
|
|
|
|
|
|
|
|
unsigned start_Time = stats_startCopperLayersTime;
|
|
|
|
#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
|
|
|
|
|
|
|
m_stats_nr_tracks = 0;
|
|
|
|
m_stats_track_med_width = 0;
|
|
|
|
m_stats_nr_vias = 0;
|
|
|
|
m_stats_via_med_hole_diameter = 0;
|
|
|
|
m_stats_nr_holes = 0;
|
|
|
|
m_stats_hole_med_diameter = 0;
|
|
|
|
|
|
|
|
// Prepare track list, convert in a vector. Calc statistic for the holes
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
|
|
|
std::vector< const TRACK *> trackList;
|
|
|
|
trackList.clear();
|
2019-05-31 02:30:28 +00:00
|
|
|
trackList.reserve( m_board->Tracks().size() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
for( TRACK* track : m_board->Tracks() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( !Is3DLayerEnabled( track->GetLayer() ) ) // Skip non enabled layers
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Note: a TRACK holds normal segment tracks and
|
|
|
|
// also vias circles (that have also drill values)
|
|
|
|
trackList.push_back( track );
|
|
|
|
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
const VIA *via = static_cast< const VIA*>( track );
|
|
|
|
m_stats_nr_vias++;
|
|
|
|
m_stats_via_med_hole_diameter += via->GetDrillValue() * m_biuTo3Dunits;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_stats_nr_tracks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_stats_track_med_width += track->GetWidth() * m_biuTo3Dunits;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_stats_nr_tracks )
|
|
|
|
m_stats_track_med_width /= (float)m_stats_nr_tracks;
|
|
|
|
|
|
|
|
if( m_stats_nr_vias )
|
|
|
|
m_stats_via_med_hole_diameter /= (float)m_stats_nr_vias;
|
|
|
|
|
|
|
|
// Prepare copper layers index and containers
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2017-03-13 03:19:33 +00:00
|
|
|
std::vector< PCB_LAYER_ID > layer_id;
|
2016-07-19 17:35:25 +00:00
|
|
|
layer_id.clear();
|
|
|
|
layer_id.reserve( m_copperLayersCount );
|
|
|
|
|
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
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
const PCB_LAYER_ID curr_layer_id = *cu;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( !Is3DLayerEnabled( curr_layer_id ) ) // Skip non enabled layers
|
|
|
|
continue;
|
|
|
|
|
|
|
|
layer_id.push_back( curr_layer_id );
|
|
|
|
|
|
|
|
CBVHCONTAINER2D *layerContainer = new CBVHCONTAINER2D;
|
|
|
|
m_layers_container2D[curr_layer_id] = layerContainer;
|
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
|
|
|
|
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2019-12-30 13:01:06 +00:00
|
|
|
SHAPE_POLY_SET* layerPoly = new SHAPE_POLY_SET;
|
2016-07-19 17:35:25 +00:00
|
|
|
m_layers_poly[curr_layer_id] = layerPoly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 19:09:43 +00:00
|
|
|
m_F_Cu_PlatedPads_poly = new SHAPE_POLY_SET;
|
|
|
|
m_B_Cu_PlatedPads_poly = new SHAPE_POLY_SET;
|
|
|
|
|
|
|
|
m_platedpads_container2D_F_Cu = new CBVHCONTAINER2D;
|
|
|
|
m_platedpads_container2D_B_Cu = new CBVHCONTAINER2D;
|
|
|
|
|
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
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2020-03-24 01:01:23 +00:00
|
|
|
for( PCB_LAYER_ID curr_layer_id : layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
|
|
|
|
|
|
|
|
CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id];
|
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Add track segments shapes and via annulus shapes
|
2016-07-19 17:35:25 +00:00
|
|
|
unsigned int nTracks = trackList.size();
|
|
|
|
|
|
|
|
for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
|
|
|
|
{
|
|
|
|
const TRACK *track = trackList[trackIdx];
|
|
|
|
|
|
|
|
// NOTE: Vias can be on multiple layers
|
|
|
|
if( !track->IsOnLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Skip vias annulus when not connected on this layer (if removing is enabled)
|
|
|
|
const VIA *via = dyn_cast< const VIA*>( track );
|
|
|
|
|
|
|
|
if( via && !via->IsPadOnLayer( curr_layer_id ) && IsCopperLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Add object item to layer container
|
2020-04-09 08:37:17 +00:00
|
|
|
createNewTrack( track, layerContainer, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create VIAS and THTs objects and add it to holes containers
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2020-03-24 01:01:23 +00:00
|
|
|
for( PCB_LAYER_ID curr_layer_id : layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// ADD TRACKS
|
|
|
|
unsigned int nTracks = trackList.size();
|
|
|
|
|
|
|
|
for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
|
|
|
|
{
|
|
|
|
const TRACK *track = trackList[trackIdx];
|
|
|
|
|
|
|
|
if( !track->IsOnLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// ADD VIAS and THT
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
const VIA* via = static_cast<const VIA*>( track );
|
|
|
|
const VIATYPE viatype = via->GetViaType();
|
|
|
|
const float holediameter = via->GetDrillValue() * BiuTo3Dunits();
|
|
|
|
const float thickness = GetCopperThickness3DU();
|
|
|
|
const float hole_inner_radius = ( holediameter / 2.0f );
|
2020-07-16 22:36:06 +00:00
|
|
|
const float ring_radius = via->GetWidth() * BiuTo3Dunits() / 2.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-12-28 00:55:11 +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
|
|
|
|
// /////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CBVHCONTAINER2D *layerHoleContainer = NULL;
|
|
|
|
|
|
|
|
// Check if the layer is already created
|
|
|
|
if( m_layers_holes2D.find( curr_layer_id ) == m_layers_holes2D.end() )
|
|
|
|
{
|
|
|
|
// not found, create a new container
|
|
|
|
layerHoleContainer = new CBVHCONTAINER2D;
|
|
|
|
m_layers_holes2D[curr_layer_id] = layerHoleContainer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// found
|
|
|
|
layerHoleContainer = m_layers_holes2D[curr_layer_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a hole for this layer
|
|
|
|
layerHoleContainer->Add( new CFILLEDCIRCLE2D( via_center,
|
|
|
|
hole_inner_radius + thickness,
|
|
|
|
*track ) );
|
|
|
|
}
|
2020-03-24 01:01:23 +00:00
|
|
|
else if( curr_layer_id == layer_id[0] ) // it only adds once the THT holes
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Add through hole object
|
|
|
|
// /////////////////////////////////////////////////////////
|
|
|
|
m_through_holes_outer.Add( new CFILLEDCIRCLE2D( via_center,
|
|
|
|
hole_inner_radius + thickness,
|
|
|
|
*track ) );
|
|
|
|
m_through_holes_vias_outer.Add(
|
|
|
|
new CFILLEDCIRCLE2D( via_center,
|
|
|
|
hole_inner_radius + thickness,
|
|
|
|
*track ) );
|
|
|
|
|
2020-07-16 22:36:06 +00:00
|
|
|
if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) )
|
|
|
|
{
|
|
|
|
m_through_holes_outer_ring.Add(
|
|
|
|
new CFILLEDCIRCLE2D( via_center, ring_radius, *track ) );
|
|
|
|
m_through_holes_vias_outer_ring.Add(
|
|
|
|
new CFILLEDCIRCLE2D( via_center, ring_radius, *track ) );
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_through_holes_inner.Add( new CFILLEDCIRCLE2D( via_center,
|
|
|
|
hole_inner_radius,
|
|
|
|
*track ) );
|
|
|
|
|
|
|
|
//m_through_holes_vias_inner.Add( new CFILLEDCIRCLE2D( via_center,
|
|
|
|
// hole_inner_radius,
|
|
|
|
// *track ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create VIAS and THTs objects and add it to holes containers
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2020-03-24 01:01:23 +00:00
|
|
|
for( PCB_LAYER_ID curr_layer_id : layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// ADD TRACKS
|
|
|
|
const unsigned int nTracks = trackList.size();
|
|
|
|
|
|
|
|
for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
|
|
|
|
{
|
|
|
|
const TRACK *track = trackList[trackIdx];
|
|
|
|
|
|
|
|
if( !track->IsOnLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// ADD VIAS and THT
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
const VIA *via = static_cast< const VIA*>( track );
|
2019-12-28 00:55:11 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
// Add VIA hole contourns
|
|
|
|
|
2019-08-20 17:02:28 +00:00
|
|
|
// Add outer holes of VIAs
|
2016-07-19 17:35:25 +00:00
|
|
|
SHAPE_POLY_SET *layerOuterHolesPoly = NULL;
|
|
|
|
SHAPE_POLY_SET *layerInnerHolesPoly = NULL;
|
|
|
|
|
|
|
|
// Check if the layer is already created
|
|
|
|
if( m_layers_outer_holes_poly.find( curr_layer_id ) ==
|
|
|
|
m_layers_outer_holes_poly.end() )
|
|
|
|
{
|
|
|
|
// not found, create a new container
|
|
|
|
layerOuterHolesPoly = new SHAPE_POLY_SET;
|
|
|
|
m_layers_outer_holes_poly[curr_layer_id] = layerOuterHolesPoly;
|
|
|
|
|
|
|
|
wxASSERT( m_layers_inner_holes_poly.find( curr_layer_id ) ==
|
|
|
|
m_layers_inner_holes_poly.end() );
|
|
|
|
|
|
|
|
layerInnerHolesPoly = new SHAPE_POLY_SET;
|
|
|
|
m_layers_inner_holes_poly[curr_layer_id] = layerInnerHolesPoly;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// found
|
|
|
|
layerOuterHolesPoly = m_layers_outer_holes_poly[curr_layer_id];
|
|
|
|
|
|
|
|
wxASSERT( m_layers_inner_holes_poly.find( curr_layer_id ) !=
|
|
|
|
m_layers_inner_holes_poly.end() );
|
|
|
|
|
|
|
|
layerInnerHolesPoly = m_layers_inner_holes_poly[curr_layer_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
const int holediameter = via->GetDrillValue();
|
|
|
|
const int hole_outer_radius = (holediameter / 2) + GetCopperThicknessBIU();
|
|
|
|
|
2019-05-22 13:33:48 +00:00
|
|
|
TransformCircleToPolygon( *layerOuterHolesPoly, via->GetStart(),
|
|
|
|
hole_outer_radius, ARC_HIGH_DEF );
|
|
|
|
|
|
|
|
TransformCircleToPolygon( *layerInnerHolesPoly, via->GetStart(),
|
|
|
|
holediameter / 2, ARC_HIGH_DEF );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2020-03-24 01:01:23 +00:00
|
|
|
else if( curr_layer_id == layer_id[0] ) // it only adds once the THT holes
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
const int holediameter = via->GetDrillValue();
|
|
|
|
const int hole_outer_radius = (holediameter / 2)+ GetCopperThicknessBIU();
|
2020-07-16 22:36:06 +00:00
|
|
|
const int hole_outer_ring_radius = via->GetWidth() / 2.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Add through hole contourns
|
|
|
|
// /////////////////////////////////////////////////////////
|
2019-05-22 13:33:48 +00:00
|
|
|
TransformCircleToPolygon( m_through_outer_holes_poly, via->GetStart(),
|
|
|
|
hole_outer_radius, ARC_HIGH_DEF );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Add same thing for vias only
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-16 22:36:06 +00:00
|
|
|
TransformCircleToPolygon( m_through_outer_holes_vias_poly,
|
|
|
|
via->GetStart(), hole_outer_radius, ARC_HIGH_DEF );
|
2020-08-11 09:26:00 +00:00
|
|
|
|
2020-07-16 22:36:06 +00:00
|
|
|
if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) )
|
|
|
|
{
|
|
|
|
TransformCircleToPolygon( m_through_outer_ring_holes_vias_poly,
|
|
|
|
via->GetStart(), hole_outer_ring_radius, ARC_HIGH_DEF );
|
|
|
|
}
|
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
|
2016-07-19 17:35:25 +00:00
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2019-12-30 13:01:06 +00:00
|
|
|
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
|
|
|
|
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( PCB_LAYER_ID curr_layer_id : layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET *layerPoly = m_layers_poly[curr_layer_id];
|
|
|
|
|
|
|
|
// ADD TRACKS
|
|
|
|
unsigned int nTracks = trackList.size();
|
|
|
|
|
|
|
|
for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
|
|
|
|
{
|
|
|
|
const TRACK *track = trackList[trackIdx];
|
|
|
|
|
|
|
|
if( !track->IsOnLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Skip vias annulus when not connected on this layer (if removing is enabled)
|
|
|
|
const VIA *via = dyn_cast< const VIA*>( track );
|
|
|
|
|
|
|
|
if( via && !via->IsPadOnLayer( curr_layer_id ) && IsCopperLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Add the track/via contour
|
2020-08-12 21:18:13 +00:00
|
|
|
track->TransformShapeWithClearanceToPolygon( *layerPoly, curr_layer_id, 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add holes of modules
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2020-03-24 01:01:23 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( D_PAD* pad : module->Pads() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
const wxSize padHole = pad->GetDrillSize();
|
|
|
|
|
|
|
|
if( !padHole.x ) // Not drilled pad like SMD pad
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// The hole in the body is inflated by copper thickness,
|
|
|
|
// if not plated, no copper
|
|
|
|
const int inflate = (pad->GetAttribute () != PAD_ATTRIB_HOLE_NOT_PLATED) ?
|
|
|
|
GetCopperThicknessBIU() : 0;
|
|
|
|
|
|
|
|
m_stats_nr_holes++;
|
|
|
|
m_stats_hole_med_diameter += ( ( pad->GetDrillSize().x +
|
|
|
|
pad->GetDrillSize().y ) / 2.0f ) * m_biuTo3Dunits;
|
|
|
|
|
|
|
|
m_through_holes_outer.Add( createNewPadDrill( pad, inflate ) );
|
2020-08-11 09:26:00 +00:00
|
|
|
|
2020-07-16 22:36:06 +00:00
|
|
|
if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) )
|
|
|
|
{
|
|
|
|
m_through_holes_outer_ring.Add( createNewPadDrill( pad, inflate ) );
|
|
|
|
}
|
2020-08-11 09:26:00 +00:00
|
|
|
|
2020-09-06 10:20:03 +00:00
|
|
|
m_through_holes_inner.Add( createNewPadDrill( pad, 0 ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-06 10:20:03 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_stats_nr_holes )
|
|
|
|
m_stats_hole_med_diameter /= (float)m_stats_nr_holes;
|
|
|
|
|
|
|
|
// Add contours of the pad holes (pads can be Circle or Segment holes)
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2020-03-24 01:01:23 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( D_PAD* pad : module->Pads() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
const wxSize padHole = pad->GetDrillSize();
|
|
|
|
|
|
|
|
if( !padHole.x ) // Not drilled pad like SMD pad
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// The hole in the body is inflated by copper thickness.
|
|
|
|
const int inflate = GetCopperThicknessBIU();
|
|
|
|
|
|
|
|
if( pad->GetAttribute () != PAD_ATTRIB_HOLE_NOT_PLATED )
|
|
|
|
{
|
2020-06-22 19:35:09 +00:00
|
|
|
pad->TransformHoleWithClearanceToPolygon( m_through_outer_holes_poly, inflate );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If not plated, no copper.
|
2020-06-22 19:35:09 +00:00
|
|
|
pad->TransformHoleWithClearanceToPolygon( m_through_outer_holes_poly_NPTH, inflate );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add modules PADs objects to containers
|
2020-03-24 01:01:23 +00:00
|
|
|
for( PCB_LAYER_ID curr_layer_id : layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
|
|
|
|
|
|
|
|
CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id];
|
|
|
|
|
|
|
|
// ADD PADS
|
2020-03-24 01:01:23 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Note: NPTH pads are not drawn on copper layers when the pad
|
|
|
|
// has same shape as its hole
|
|
|
|
AddPadsShapesWithClearanceToContainer( module,
|
|
|
|
layerContainer,
|
|
|
|
curr_layer_id,
|
|
|
|
0,
|
2020-09-06 19:09:43 +00:00
|
|
|
true,
|
|
|
|
true,
|
|
|
|
false );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Micro-wave modules may have items on copper layers
|
|
|
|
AddGraphicsShapesWithClearanceToContainer( module,
|
|
|
|
layerContainer,
|
|
|
|
curr_layer_id,
|
|
|
|
0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 19:09:43 +00:00
|
|
|
// ADD PLATED PADS
|
|
|
|
for( MODULE* module : m_board->Modules() )
|
|
|
|
{
|
|
|
|
AddPadsShapesWithClearanceToContainer( module,
|
|
|
|
m_platedpads_container2D_F_Cu,
|
|
|
|
F_Cu,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true );
|
|
|
|
|
|
|
|
AddPadsShapesWithClearanceToContainer( module,
|
|
|
|
m_platedpads_container2D_B_Cu,
|
|
|
|
B_Cu,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true );
|
|
|
|
}
|
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Add modules PADs poly contourns (vertical outlines)
|
2019-12-30 13:01:06 +00:00
|
|
|
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
|
|
|
|
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( PCB_LAYER_ID curr_layer_id : layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET *layerPoly = m_layers_poly[curr_layer_id];
|
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Add pads to polygon list
|
2019-05-31 00:15:57 +00:00
|
|
|
for( auto module : m_board->Modules() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Note: NPTH pads are not drawn on copper layers when the pad
|
|
|
|
// has same shape as its hole
|
2020-08-28 14:17:19 +00:00
|
|
|
module->TransformPadsShapesWithClearanceToPolygon( curr_layer_id, *layerPoly,
|
2020-09-06 19:09:43 +00:00
|
|
|
0, ARC_HIGH_DEF, true,
|
|
|
|
true, false );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
transformGraphicModuleEdgeToPolygonSet( module, curr_layer_id, *layerPoly );
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 19:09:43 +00:00
|
|
|
|
|
|
|
// ADD PLATED PADS contourns
|
|
|
|
for( auto module : m_board->Modules() )
|
|
|
|
{
|
|
|
|
module->TransformPadsShapesWithClearanceToPolygon( F_Cu, *m_F_Cu_PlatedPads_poly,
|
|
|
|
0, ARC_HIGH_DEF, true,
|
|
|
|
false, true );
|
|
|
|
|
|
|
|
//transformGraphicModuleEdgeToPolygonSet( module, F_Cu, *m_F_Cu_PlatedPads_poly );
|
|
|
|
|
|
|
|
module->TransformPadsShapesWithClearanceToPolygon( B_Cu, *m_B_Cu_PlatedPads_poly,
|
|
|
|
0, ARC_HIGH_DEF, true,
|
|
|
|
false, true );
|
|
|
|
|
|
|
|
//transformGraphicModuleEdgeToPolygonSet( module, B_Cu, *m_B_Cu_PlatedPads_poly );
|
|
|
|
}
|
2016-07-19 17:35:25 +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
|
2020-03-24 01:01:23 +00:00
|
|
|
for( PCB_LAYER_ID curr_layer_id : layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
|
|
|
|
|
|
|
|
CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id];
|
|
|
|
|
2020-08-12 10:46:46 +00:00
|
|
|
// Add graphic items on copper layers (texts and other graphics)
|
2017-03-22 13:11:08 +00:00
|
|
|
for( auto item : m_board->Drawings() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( !item->IsOnLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2019-04-05 16:10:59 +00:00
|
|
|
case PCB_LINE_T:
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
AddShapeWithClearanceToContainer( (DRAWSEGMENT*)item,
|
|
|
|
layerContainer,
|
|
|
|
curr_layer_id,
|
|
|
|
0 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
AddShapeWithClearanceToContainer( (TEXTE_PCB*) item,
|
|
|
|
layerContainer,
|
|
|
|
curr_layer_id,
|
|
|
|
0 );
|
|
|
|
break;
|
|
|
|
|
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:
|
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_LEADER_T:
|
2017-02-01 13:52:17 +00:00
|
|
|
AddShapeWithClearanceToContainer( (DIMENSION*) item,
|
|
|
|
layerContainer,
|
|
|
|
curr_layer_id,
|
|
|
|
0 );
|
|
|
|
break;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
default:
|
|
|
|
wxLogTrace( m_logTrace,
|
|
|
|
wxT( "createLayers: item type: %d not implemented" ),
|
|
|
|
item->Type() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 10:46:46 +00:00
|
|
|
// Add graphic item on copper layers to poly contourns (vertical outlines)
|
2019-12-30 13:01:06 +00:00
|
|
|
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
|
|
|
|
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( PCB_LAYER_ID cur_layer_id : layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
wxASSERT( m_layers_poly.find( cur_layer_id ) != m_layers_poly.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
SHAPE_POLY_SET *layerPoly = m_layers_poly[cur_layer_id];
|
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
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
if( !item->IsOnLayer( cur_layer_id ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2018-11-14 23:34:32 +00:00
|
|
|
case PCB_LINE_T:
|
2020-08-12 21:18:13 +00:00
|
|
|
( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon( *layerPoly,
|
|
|
|
cur_layer_id, 0 );
|
2019-05-14 12:39:34 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
2019-05-14 12:39:34 +00:00
|
|
|
( (TEXTE_PCB*) item )->TransformShapeWithClearanceToPolygonSet( *layerPoly, 0 );
|
|
|
|
break;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( GetFlag( FL_ZONE ) )
|
|
|
|
{
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Create zones" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
std::vector<std::pair<const ZONE_CONTAINER*, PCB_LAYER_ID>> zones;
|
|
|
|
|
2020-08-26 23:52:12 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
2020-06-24 02:19:08 +00:00
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
zones.emplace_back( std::make_pair( zone, layer ) );
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency(), 2 );
|
|
|
|
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 ) )
|
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
const ZONE_CONTAINER* 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;
|
|
|
|
|
|
|
|
auto layerContainer = m_layers_container2D.find( layer );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-09-21 04:23:15 +00:00
|
|
|
if( layerContainer != m_layers_container2D.end() )
|
2020-06-24 02:19:08 +00:00
|
|
|
AddSolidAreasShapesToContainer( zone, layerContainer->second, layer );
|
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
|
|
|
}
|
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
if( GetFlag( FL_ZONE ) && GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
|
|
|
|
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-08-12 10:46:46 +00:00
|
|
|
// Add copper zones
|
2020-03-24 01:01:23 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
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
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
auto layerContainer = m_layers_poly.find( layer );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
if( layerContainer != m_layers_poly.end() )
|
2020-08-12 18:42:40 +00:00
|
|
|
zone->TransformSolidAreasShapesToPolygon( layer, *layerContainer->second );
|
2020-06-24 02:19:08 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simplify layer polygons
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Simplifying copper layers polygons" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
|
|
|
|
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-09-07 12:29:40 +00:00
|
|
|
if( m_F_Cu_PlatedPads_poly && ( m_layers_poly.find( F_Cu ) != m_layers_poly.end() ) )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET *layerPoly_F_Cu = m_layers_poly[F_Cu];
|
|
|
|
layerPoly_F_Cu->BooleanSubtract( *m_F_Cu_PlatedPads_poly, SHAPE_POLY_SET::POLYGON_MODE::PM_FAST );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-07 12:29:40 +00:00
|
|
|
m_F_Cu_PlatedPads_poly->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_B_Cu_PlatedPads_poly && ( m_layers_poly.find( B_Cu ) != m_layers_poly.end() ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-09-07 12:29:40 +00:00
|
|
|
SHAPE_POLY_SET *layerPoly_B_Cu = m_layers_poly[B_Cu];
|
|
|
|
layerPoly_B_Cu->BooleanSubtract( *m_B_Cu_PlatedPads_poly, SHAPE_POLY_SET::POLYGON_MODE::PM_FAST );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-07 12:29:40 +00:00
|
|
|
m_B_Cu_PlatedPads_poly->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-07 12:29:40 +00:00
|
|
|
std::vector< PCB_LAYER_ID > layer_id_without_F_and_B;
|
|
|
|
layer_id_without_F_and_B.clear();
|
|
|
|
layer_id_without_F_and_B.reserve( layer_id.size() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-07 12:29:40 +00:00
|
|
|
for( size_t i = 0; i < layer_id.size(); ++i )
|
|
|
|
{
|
|
|
|
if( ( layer_id[i] != F_Cu ) &&
|
|
|
|
( layer_id[i] != B_Cu ) )
|
|
|
|
layer_id_without_F_and_B.push_back( layer_id[i] );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2018-09-21 04:23:15 +00:00
|
|
|
|
2020-09-07 12:29:40 +00:00
|
|
|
if( layer_id_without_F_and_B.size() > 0 )
|
|
|
|
{
|
|
|
|
std::atomic<size_t> nextItem( 0 );
|
|
|
|
std::atomic<size_t> threadsFinished( 0 );
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2020-09-07 12:29:40 +00:00
|
|
|
size_t parallelThreadCount = std::min<size_t>(
|
|
|
|
std::max<size_t>( std::thread::hardware_concurrency(), 2 ),
|
|
|
|
layer_id_without_F_and_B.size() );
|
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
|
|
|
{
|
|
|
|
std::thread t = std::thread( [&nextItem, &threadsFinished, &layer_id_without_F_and_B, this]()
|
|
|
|
{
|
|
|
|
for( size_t i = nextItem.fetch_add( 1 );
|
|
|
|
i < layer_id_without_F_and_B.size();
|
|
|
|
i = nextItem.fetch_add( 1 ) )
|
|
|
|
{
|
|
|
|
auto layerPoly = m_layers_poly.find( layer_id_without_F_and_B[i] );
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2020-09-07 12:29:40 +00:00
|
|
|
if( layerPoly != m_layers_poly.end() )
|
|
|
|
// This will make a union of all added contours
|
|
|
|
layerPoly->second->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
|
|
|
|
|
|
|
threadsFinished++;
|
|
|
|
} );
|
|
|
|
|
|
|
|
t.detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
while( threadsFinished < parallelThreadCount )
|
|
|
|
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Simplify holes polygon contours
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Simplify holes contours" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
for( PCB_LAYER_ID layer : layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
if( m_layers_outer_holes_poly.find( layer ) != m_layers_outer_holes_poly.end() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// found
|
2020-03-24 01:01:23 +00:00
|
|
|
SHAPE_POLY_SET *polyLayer = m_layers_outer_holes_poly[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
polyLayer->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
wxASSERT( m_layers_inner_holes_poly.find( layer ) != m_layers_inner_holes_poly.end() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
polyLayer = m_layers_inner_holes_poly[layer];
|
2016-07-19 17:35:25 +00:00
|
|
|
polyLayer->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// End Build Copper layers
|
|
|
|
|
|
|
|
// This will make a union of all added contourns
|
|
|
|
m_through_outer_holes_poly.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
m_through_outer_holes_poly_NPTH.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
m_through_outer_holes_vias_poly.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2020-07-16 22:36:06 +00:00
|
|
|
m_through_outer_ring_holes_vias_poly.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Build Tech layers
|
|
|
|
// 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
|
2017-03-13 03:19:33 +00:00
|
|
|
static const PCB_LAYER_ID teckLayerList[] = {
|
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,
|
|
|
|
Eco2_User,
|
|
|
|
Edge_Cuts,
|
|
|
|
Margin
|
|
|
|
};
|
|
|
|
|
|
|
|
// User layers are not drawn here, only technical layers
|
2019-01-06 16:43:12 +00:00
|
|
|
for( LSEQ seq = LSET::AllNonCuMask().Seq( teckLayerList, arrayDim( teckLayerList ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
seq;
|
|
|
|
++seq )
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
const PCB_LAYER_ID curr_layer_id = *seq;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( !Is3DLayerEnabled( curr_layer_id ) )
|
2020-03-24 01:01:23 +00:00
|
|
|
continue;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
CBVHCONTAINER2D *layerContainer = new CBVHCONTAINER2D;
|
|
|
|
m_layers_container2D[curr_layer_id] = layerContainer;
|
|
|
|
|
|
|
|
SHAPE_POLY_SET *layerPoly = new SHAPE_POLY_SET;
|
|
|
|
m_layers_poly[curr_layer_id] = layerPoly;
|
|
|
|
|
|
|
|
// Add drawing objects
|
2020-03-24 01:01:23 +00:00
|
|
|
for( BOARD_ITEM* item : m_board->Drawings() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( !item->IsOnLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_LINE_T:
|
|
|
|
AddShapeWithClearanceToContainer( (DRAWSEGMENT*)item,
|
|
|
|
layerContainer,
|
|
|
|
curr_layer_id,
|
|
|
|
0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
AddShapeWithClearanceToContainer( (TEXTE_PCB*) item,
|
|
|
|
layerContainer,
|
|
|
|
curr_layer_id,
|
|
|
|
0 );
|
|
|
|
break;
|
|
|
|
|
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:
|
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_LEADER_T:
|
2017-02-01 13:52:17 +00:00
|
|
|
AddShapeWithClearanceToContainer( (DIMENSION*) item,
|
|
|
|
layerContainer,
|
|
|
|
curr_layer_id,
|
|
|
|
0 );
|
|
|
|
break;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add drawing contours
|
2020-03-24 01:01:23 +00:00
|
|
|
for( BOARD_ITEM* item : m_board->Drawings() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( !item->IsOnLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_LINE_T:
|
2020-08-12 21:18:13 +00:00
|
|
|
( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon( *layerPoly,
|
|
|
|
curr_layer_id, 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
2019-05-14 12:39:34 +00:00
|
|
|
( (TEXTE_PCB*) item )->TransformShapeWithClearanceToPolygonSet( *layerPoly, 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add modules tech layers - objects
|
|
|
|
// /////////////////////////////////////////////////////////////////////
|
2020-03-24 01:01:23 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( (curr_layer_id == F_SilkS) || (curr_layer_id == B_SilkS) )
|
|
|
|
{
|
|
|
|
int linewidth = g_DrawDefaultLineThickness;
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
for( D_PAD* pad : module->Pads() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( !pad->IsOnLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
buildPadShapeThickOutlineAsSegments( pad, layerContainer, linewidth );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-28 13:00:05 +00:00
|
|
|
AddPadsShapesWithClearanceToContainer( module, layerContainer, curr_layer_id, 0,
|
2020-09-06 19:09:43 +00:00
|
|
|
false,
|
|
|
|
false,
|
2020-08-28 13:00:05 +00:00
|
|
|
false );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
AddGraphicsShapesWithClearanceToContainer( module, layerContainer, curr_layer_id, 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add modules tech layers - contours
|
2020-03-24 01:01:23 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( (curr_layer_id == F_SilkS) || (curr_layer_id == B_SilkS) )
|
|
|
|
{
|
|
|
|
const int linewidth = g_DrawDefaultLineThickness;
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
for( D_PAD* pad : module->Pads() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( !pad->IsOnLayer( curr_layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
buildPadShapeThickOutlineAsPolygon( pad, *layerPoly, linewidth );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-28 14:17:19 +00:00
|
|
|
module->TransformPadsShapesWithClearanceToPolygon( curr_layer_id, *layerPoly, 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// On tech layers, use a poor circle approximation, only for texts (stroke font)
|
2019-05-14 12:39:34 +00:00
|
|
|
module->TransformGraphicTextWithClearanceToPolygonSet( curr_layer_id, *layerPoly, 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Add the remaining things with dynamic seg count for circles
|
|
|
|
transformGraphicModuleEdgeToPolygonSet( module, curr_layer_id, *layerPoly );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Draw non copper zones
|
|
|
|
if( GetFlag( FL_ZONE ) )
|
|
|
|
{
|
2020-08-26 23:52:12 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-08-26 23:52:12 +00:00
|
|
|
if( zone->IsOnLayer( curr_layer_id ) )
|
|
|
|
AddSolidAreasShapesToContainer( zone, layerContainer, curr_layer_id );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 23:52:12 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-08-26 23:52:12 +00:00
|
|
|
if( zone->IsOnLayer( curr_layer_id ) )
|
|
|
|
zone->TransformSolidAreasShapesToPolygon( curr_layer_id, *layerPoly );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
// This will make a union of all added contours
|
2016-07-19 17:35:25 +00:00
|
|
|
layerPoly->Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
|
|
|
// End Build Tech layers
|
|
|
|
|
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
|
|
|
|
|
|
|
m_through_holes_inner.BuildBVH();
|
|
|
|
m_through_holes_outer.BuildBVH();
|
2020-07-16 22:36:06 +00:00
|
|
|
m_through_holes_outer_ring.BuildBVH();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( !m_layers_holes2D.empty() )
|
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
for( auto& hole : m_layers_holes2D)
|
|
|
|
hole.second->BuildBVH();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We only need the Solder mask to initialize the BVH
|
|
|
|
// because..?
|
2020-03-24 01:01:23 +00:00
|
|
|
if( m_layers_container2D[B_Mask] )
|
|
|
|
m_layers_container2D[B_Mask]->BuildBVH();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
if( m_layers_container2D[F_Mask] )
|
|
|
|
m_layers_container2D[F_Mask]->BuildBVH();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|