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>
|
2021-01-29 17:36:18 +00:00
|
|
|
* Copyright (C) 1992-2021 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 cinfo3d_visu.cpp
|
|
|
|
* @brief Handles data related with the board to be visualized
|
|
|
|
*/
|
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "../3d_rendering/camera.h"
|
2020-03-26 14:05:20 +00:00
|
|
|
#include "board_adapter.h"
|
2021-01-03 22:23:00 +00:00
|
|
|
#include <3d_rendering/3d_render_raytracing/shapes2D/polygon_2d.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <3d_math.h>
|
|
|
|
#include "3d_fastmath.h"
|
2018-03-22 19:15:34 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2021-03-26 17:02:30 +00:00
|
|
|
#include <convert_to_biu.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Trace mask used to enable or disable the trace output of this class.
|
|
|
|
* The debug output can be turned on by setting the WXTRACE environment variable to
|
|
|
|
* "KI_TRACE_EDA_CINFO3D_VISU". See the wxWidgets documentation on wxLogTrace for
|
|
|
|
* more information.
|
2020-12-16 22:10:42 +00:00
|
|
|
*
|
|
|
|
* @ingroup trace_env_vars
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
2020-03-26 14:05:20 +00:00
|
|
|
const wxChar *BOARD_ADAPTER::m_logTrace = wxT( "KI_TRACE_EDA_CINFO3D_VISU" );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
BOARD_ADAPTER::BOARD_ADAPTER() :
|
2020-03-25 13:13:03 +00:00
|
|
|
m_board( nullptr ),
|
2021-01-07 19:33:43 +00:00
|
|
|
m_3dModelManager( nullptr ),
|
2020-03-25 13:13:03 +00:00
|
|
|
m_colors( nullptr ),
|
|
|
|
m_layerZcoordTop(),
|
2020-03-26 14:05:20 +00:00
|
|
|
m_layerZcoordBottom()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-26 14:05:20 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::BOARD_ADAPTER" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_gridType = GRID3D_TYPE::NONE;
|
|
|
|
m_antiAliasingMode = ANTIALIASING_MODE::AA_8X;
|
2016-07-19 17:35:25 +00:00
|
|
|
m_drawFlags.resize( FL_LAST, false );
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
if( PgmOrNull() )
|
|
|
|
m_colors = Pgm().GetSettingsManager().GetColorSettings();
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_renderEngine = RENDER_ENGINE::OPENGL_LEGACY;
|
|
|
|
m_materialMode = MATERIAL_MODE::NORMAL;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_boardPos = wxPoint();
|
|
|
|
m_boardSize = wxSize();
|
2018-04-11 17:59:28 +00:00
|
|
|
m_boardCenter = SFVEC3F( 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-08-20 17:22:30 +00:00
|
|
|
m_boardBoundingBox.Reset();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_throughHoleIds.Clear();
|
|
|
|
m_throughHoleOds.Clear();
|
|
|
|
m_throughHoleAnnularRings.Clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_copperLayersCount = -1;
|
|
|
|
m_epoxyThickness3DU = 0.0f;
|
|
|
|
m_copperThickness3DU = 0.0f;
|
|
|
|
m_nonCopperLayerThickness3DU = 0.0f;
|
2021-03-26 17:02:30 +00:00
|
|
|
m_solderPasteLayerThickness3DU = 0.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
m_biuTo3Dunits = 1.0;
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_trackCount = 0;
|
|
|
|
m_viaCount = 0;
|
|
|
|
m_averageViaHoleDiameter = 0.0f;
|
|
|
|
m_holeCount = 0;
|
|
|
|
m_averageHoleDiameter = 0.0f;
|
|
|
|
m_averageTrackWidth = 0.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
SetFlag( FL_USE_REALISTIC_MODE, true );
|
2020-11-12 23:50:33 +00:00
|
|
|
SetFlag( FL_FP_ATTRIBUTES_NORMAL, true );
|
2016-07-19 17:35:25 +00:00
|
|
|
SetFlag( FL_SHOW_BOARD_BODY, true );
|
2020-07-16 22:36:06 +00:00
|
|
|
SetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS, false );
|
2020-11-12 23:50:33 +00:00
|
|
|
SetFlag( FL_FP_ATTRIBUTES_NORMAL, true );
|
|
|
|
SetFlag( FL_FP_ATTRIBUTES_NORMAL_INSERT, true );
|
|
|
|
SetFlag( FL_FP_ATTRIBUTES_VIRTUAL, true );
|
2016-07-19 17:35:25 +00:00
|
|
|
SetFlag( FL_ZONE, true );
|
|
|
|
SetFlag( FL_SILKSCREEN, true );
|
|
|
|
SetFlag( FL_SOLDERMASK, true );
|
2020-01-29 16:00:05 +00:00
|
|
|
SetFlag( FL_SUBTRACT_MASK_FROM_SILK, false );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-04-17 21:33:23 +00:00
|
|
|
SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, true );
|
|
|
|
SetFlag( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE, false );
|
|
|
|
SetFlag( FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE, false );
|
|
|
|
SetFlag( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE, false );
|
|
|
|
SetFlag( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE, false );
|
|
|
|
|
2020-09-27 17:18:44 +00:00
|
|
|
SetFlag( FL_USE_SELECTION, true );
|
|
|
|
|
2020-08-21 08:56:15 +00:00
|
|
|
m_BgColorBot = SFVEC4F( 0.4, 0.4, 0.5, 1.0 );
|
|
|
|
m_BgColorTop = SFVEC4F( 0.8, 0.8, 0.9, 1.0 );
|
2020-08-30 16:47:30 +00:00
|
|
|
m_BoardBodyColor = SFVEC4F( 0.4, 0.4, 0.5, 0.9 );
|
|
|
|
m_SolderMaskColorTop = SFVEC4F( 0.1, 0.2, 0.1, 0.83 );
|
|
|
|
m_SolderMaskColorBot = SFVEC4F( 0.1, 0.2, 0.1, 0.83 );
|
2020-08-21 08:56:15 +00:00
|
|
|
m_SolderPasteColor = SFVEC4F( 0.4, 0.4, 0.4, 1.0 );
|
|
|
|
m_SilkScreenColorTop = SFVEC4F( 0.9, 0.9, 0.9, 1.0 );
|
|
|
|
m_SilkScreenColorBot = SFVEC4F( 0.9, 0.9, 0.9, 1.0 );
|
|
|
|
m_CopperColor = SFVEC4F( 0.75, 0.61, 0.23, 1.0 );
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_platedPadsFront = nullptr;
|
|
|
|
m_platedPadsBack = nullptr;
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_frontPlatedPadPolys = nullptr;
|
|
|
|
m_backPlatedPadPolys = nullptr;
|
2020-09-20 09:32:47 +00:00
|
|
|
|
|
|
|
// Avoid raytracing options not initialized:
|
2021-01-07 19:33:43 +00:00
|
|
|
m_RtShadowSampleCount = 0;
|
|
|
|
m_RtReflectionSampleCount = 0;
|
|
|
|
m_RtRefractionSampleCount = 0;
|
2020-09-20 09:32:47 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_RtSpreadShadows = 0.0;
|
|
|
|
m_RtSpreadReflections = 0.0;
|
|
|
|
m_RtSpreadRefractions = 0.0;
|
2020-09-20 09:32:47 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_RtRecursiveReflectionCount = 0;
|
|
|
|
m_RtRecursiveRefractionCount = 0;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
BOARD_ADAPTER::~BOARD_ADAPTER()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
destroyLayers();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
bool BOARD_ADAPTER::Is3dLayerEnabled( PCB_LAYER_ID aLayer ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
wxASSERT( aLayer < PCB_LAYER_ID_COUNT );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-29 17:36:18 +00:00
|
|
|
if( !m_board->IsLayerEnabled( aLayer ) )
|
|
|
|
return false;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// see if layer needs to be shown
|
|
|
|
// check the flags
|
|
|
|
switch( aLayer )
|
|
|
|
{
|
|
|
|
case B_Adhes:
|
|
|
|
case F_Adhes:
|
2021-01-29 17:36:18 +00:00
|
|
|
return GetFlag( FL_ADHESIVE );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case B_Paste:
|
|
|
|
case F_Paste:
|
2021-01-29 17:36:18 +00:00
|
|
|
return GetFlag( FL_SOLDERPASTE );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case B_SilkS:
|
|
|
|
case F_SilkS:
|
2021-01-29 17:36:18 +00:00
|
|
|
return GetFlag( FL_SILKSCREEN );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case B_Mask:
|
|
|
|
case F_Mask:
|
2021-01-29 17:36:18 +00:00
|
|
|
return GetFlag( FL_SOLDERMASK );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case Dwgs_User:
|
|
|
|
case Cmts_User:
|
|
|
|
if( GetFlag( FL_USE_REALISTIC_MODE ) )
|
|
|
|
return false;
|
|
|
|
|
2021-01-29 17:36:18 +00:00
|
|
|
return GetFlag( FL_COMMENTS );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case Eco1_User:
|
|
|
|
case Eco2_User:
|
|
|
|
if( GetFlag( FL_USE_REALISTIC_MODE ) )
|
|
|
|
return false;
|
|
|
|
|
2021-01-29 17:36:18 +00:00
|
|
|
return GetFlag( FL_ECO );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case Edge_Cuts:
|
|
|
|
if( GetFlag( FL_SHOW_BOARD_BODY ) || GetFlag( FL_USE_REALISTIC_MODE ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case Margin:
|
|
|
|
if( GetFlag( FL_USE_REALISTIC_MODE ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case B_Cu:
|
|
|
|
case F_Cu:
|
2020-05-31 21:42:04 +00:00
|
|
|
return m_board->IsLayerVisible( aLayer ) || GetFlag( FL_USE_REALISTIC_MODE );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// the layer is an internal copper layer, used the visibility
|
2020-05-31 21:42:04 +00:00
|
|
|
return m_board->IsLayerVisible( aLayer );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
bool BOARD_ADAPTER::GetFlag( DISPLAY3D_FLG aFlag ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aFlag < FL_LAST );
|
|
|
|
|
|
|
|
return m_drawFlags[aFlag];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
void BOARD_ADAPTER::SetFlag( DISPLAY3D_FLG aFlag, bool aState )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aFlag < FL_LAST );
|
|
|
|
|
|
|
|
m_drawFlags[aFlag] = aState;
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
bool BOARD_ADAPTER::IsFootprintShown( FOOTPRINT_ATTR_T aFPAttributes ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-13 02:09:34 +00:00
|
|
|
if( aFPAttributes & FP_SMD )
|
2020-11-12 23:50:33 +00:00
|
|
|
return GetFlag( FL_FP_ATTRIBUTES_NORMAL_INSERT );
|
2020-11-13 02:09:34 +00:00
|
|
|
else if( aFPAttributes & FP_THROUGH_HOLE )
|
2020-11-12 23:50:33 +00:00
|
|
|
return GetFlag( FL_FP_ATTRIBUTES_NORMAL );
|
2020-08-26 21:43:38 +00:00
|
|
|
else
|
2020-11-12 23:50:33 +00:00
|
|
|
return GetFlag( FL_FP_ATTRIBUTES_VIRTUAL );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-26 17:02:30 +00:00
|
|
|
// !TODO: define the actual copper thickness by user from board stackup
|
|
|
|
#define COPPER_THICKNESS Millimeter2iu( 0.035 ) // for 35 um
|
|
|
|
// The solder mask layer (and silkscreen) thickness
|
|
|
|
#define TECH_LAYER_THICKNESS Millimeter2iu( 0.04 )
|
|
|
|
// The solder paste thickness is chosen bigger than the solder mask layer
|
|
|
|
// to be sure is covers the mask when overlapping.
|
|
|
|
#define SOLDERPASTE_LAYER_THICKNESS Millimeter2iu( 0.08 )
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
int BOARD_ADAPTER::GetHolePlatingThickness() const noexcept
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-10-01 00:13:04 +00:00
|
|
|
return m_board->GetDesignSettings().GetHolePlatingThickness();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
unsigned int BOARD_ADAPTER::GetCircleSegmentCount( float aDiameter3DU ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aDiameter3DU > 0.0f );
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
return GetCircleSegmentCount( (int)( aDiameter3DU / m_biuTo3Dunits ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
unsigned int BOARD_ADAPTER::GetCircleSegmentCount( int aDiameterBIU ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2018-03-22 19:15:34 +00:00
|
|
|
wxASSERT( aDiameterBIU > 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-10 23:05:20 +00:00
|
|
|
return GetArcToSegmentCount( aDiameterBIU / 2, ARC_HIGH_DEF, 360.0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningReporter )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-26 14:05:20 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::InitSettings" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-10 16:30:11 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Build board outline" ) );
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
const bool succeedToGetBoardPolygon = createBoardPolygon( &msg );
|
|
|
|
|
|
|
|
if( aWarningReporter )
|
|
|
|
{
|
|
|
|
if( !succeedToGetBoardPolygon )
|
|
|
|
aWarningReporter->Report( msg, RPT_SEVERITY_WARNING );
|
|
|
|
else
|
|
|
|
aWarningReporter->Report( wxEmptyString );
|
|
|
|
}
|
|
|
|
|
2020-07-07 09:40:35 +00:00
|
|
|
// Calculates the board bounding box (board outlines + items)
|
|
|
|
// to ensure any item, even outside the board outlines can be seen
|
2020-11-10 16:30:11 +00:00
|
|
|
bool boardEdgesOnly = true;
|
|
|
|
|
|
|
|
if( m_board->IsFootprintHolder() || !GetFlag( FL_USE_REALISTIC_MODE )
|
|
|
|
|| !succeedToGetBoardPolygon )
|
|
|
|
boardEdgesOnly = false;
|
|
|
|
|
|
|
|
EDA_RECT bbbox = m_board->ComputeBoundingBox( boardEdgesOnly );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Gives a non null size to avoid issues in zoom / scale calculations
|
|
|
|
if( ( bbbox.GetWidth() == 0 ) && ( bbbox.GetHeight() == 0 ) )
|
|
|
|
bbbox.Inflate( Millimeter2iu( 10 ) );
|
|
|
|
|
|
|
|
m_boardSize = bbbox.GetSize();
|
|
|
|
m_boardPos = bbbox.Centre();
|
|
|
|
|
|
|
|
wxASSERT( (m_boardSize.x > 0) && (m_boardSize.y > 0) );
|
|
|
|
|
|
|
|
m_boardPos.y = -m_boardPos.y; // The y coord is inverted in 3D viewer
|
|
|
|
|
|
|
|
m_copperLayersCount = m_board->GetCopperLayerCount();
|
|
|
|
|
|
|
|
// Ensure the board has 2 sides for 3D views, because it is hard to find
|
|
|
|
// a *really* single side board in the true life...
|
|
|
|
if( m_copperLayersCount < 2 )
|
|
|
|
m_copperLayersCount = 2;
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
// Calculate the conversion to apply to all positions.
|
2016-07-19 17:35:25 +00:00
|
|
|
m_biuTo3Dunits = RANGE_SCALE_3D / std::max( m_boardSize.x, m_boardSize.y );
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
m_epoxyThickness3DU = m_board->GetDesignSettings().GetBoardThickness() * m_biuTo3Dunits;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// !TODO: use value defined by user (currently use default values by ctor
|
|
|
|
m_copperThickness3DU = COPPER_THICKNESS * m_biuTo3Dunits;
|
|
|
|
m_nonCopperLayerThickness3DU = TECH_LAYER_THICKNESS * m_biuTo3Dunits;
|
2021-03-26 17:02:30 +00:00
|
|
|
m_solderPasteLayerThickness3DU = SOLDERPASTE_LAYER_THICKNESS * m_biuTo3Dunits;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Init Z position of each layer
|
|
|
|
// calculate z position for each copper layer
|
|
|
|
// Zstart = -m_epoxyThickness / 2.0 is the z position of the back (bottom layer) (layer id = 31)
|
|
|
|
// Zstart = +m_epoxyThickness / 2.0 is the z position of the front (top layer) (layer id = 0)
|
|
|
|
// all unused copper layer z position are set to 0
|
|
|
|
|
|
|
|
// ____==__________==________==______ <- Bottom = +m_epoxyThickness / 2.0,
|
|
|
|
// | | Top = Bottom + m_copperThickness
|
|
|
|
// |__________________________________|
|
|
|
|
// == == == == <- Bottom = -m_epoxyThickness / 2.0,
|
|
|
|
// Top = Bottom - m_copperThickness
|
|
|
|
|
|
|
|
unsigned int layer;
|
|
|
|
|
|
|
|
for( layer = 0; layer < m_copperLayersCount; ++layer )
|
|
|
|
{
|
|
|
|
m_layerZcoordBottom[layer] = m_epoxyThickness3DU / 2.0f -
|
|
|
|
(m_epoxyThickness3DU * layer / (m_copperLayersCount - 1) );
|
|
|
|
|
|
|
|
if( layer < (m_copperLayersCount / 2) )
|
|
|
|
m_layerZcoordTop[layer] = m_layerZcoordBottom[layer] + m_copperThickness3DU;
|
|
|
|
else
|
|
|
|
m_layerZcoordTop[layer] = m_layerZcoordBottom[layer] - m_copperThickness3DU;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define layerThicknessMargin 1.1
|
|
|
|
const float zpos_offset = m_nonCopperLayerThickness3DU * layerThicknessMargin;
|
|
|
|
|
|
|
|
// Fill remaining unused copper layers and back layer zpos
|
|
|
|
// with -m_epoxyThickness / 2.0
|
|
|
|
for( ; layer < MAX_CU_LAYERS; layer++ )
|
|
|
|
{
|
|
|
|
m_layerZcoordBottom[layer] = -(m_epoxyThickness3DU / 2.0f);
|
|
|
|
m_layerZcoordTop[layer] = -(m_epoxyThickness3DU / 2.0f) - m_copperThickness3DU;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is the top of the copper layer thickness.
|
|
|
|
const float zpos_copperTop_back = m_layerZcoordTop[B_Cu];
|
|
|
|
const float zpos_copperTop_front = m_layerZcoordTop[F_Cu];
|
|
|
|
|
|
|
|
// calculate z position for each non copper layer
|
|
|
|
// Solder mask and Solder paste have the same Z position
|
2017-03-13 03:19:33 +00:00
|
|
|
for( int layer_id = MAX_CU_LAYERS; layer_id < PCB_LAYER_ID_COUNT; ++layer_id )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
float zposTop;
|
|
|
|
float zposBottom;
|
|
|
|
|
|
|
|
switch( layer_id )
|
|
|
|
{
|
|
|
|
case B_Adhes:
|
|
|
|
zposBottom = zpos_copperTop_back - 2.0f * zpos_offset;
|
|
|
|
zposTop = zposBottom - m_nonCopperLayerThickness3DU;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F_Adhes:
|
|
|
|
zposBottom = zpos_copperTop_front + 2.0f * zpos_offset;
|
|
|
|
zposTop = zposBottom + m_nonCopperLayerThickness3DU;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case B_Mask:
|
|
|
|
zposBottom = zpos_copperTop_back;
|
|
|
|
zposTop = zpos_copperTop_back - m_nonCopperLayerThickness3DU;
|
|
|
|
break;
|
|
|
|
|
2021-03-26 17:02:30 +00:00
|
|
|
case B_Paste:
|
|
|
|
zposBottom = zpos_copperTop_back;
|
|
|
|
zposTop = zpos_copperTop_back - m_solderPasteLayerThickness3DU;
|
|
|
|
break;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
case F_Mask:
|
2021-03-26 17:02:30 +00:00
|
|
|
zposBottom = zpos_copperTop_front;
|
2016-07-19 17:35:25 +00:00
|
|
|
zposTop = zpos_copperTop_front + m_nonCopperLayerThickness3DU;
|
2021-03-26 17:02:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case F_Paste:
|
2016-07-19 17:35:25 +00:00
|
|
|
zposBottom = zpos_copperTop_front;
|
2021-03-26 17:02:30 +00:00
|
|
|
zposTop = zpos_copperTop_front + m_solderPasteLayerThickness3DU;
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case B_SilkS:
|
|
|
|
zposBottom = zpos_copperTop_back - 1.0f * zpos_offset;
|
|
|
|
zposTop = zposBottom - m_nonCopperLayerThickness3DU;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F_SilkS:
|
|
|
|
zposBottom = zpos_copperTop_front + 1.0f * zpos_offset;
|
|
|
|
zposTop = zposBottom + m_nonCopperLayerThickness3DU;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// !TODO: review
|
|
|
|
default:
|
|
|
|
zposTop = zpos_copperTop_front + (layer_id - MAX_CU_LAYERS + 3.0f) * zpos_offset;
|
|
|
|
zposBottom = zposTop - m_nonCopperLayerThickness3DU;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_layerZcoordTop[layer_id] = zposTop;
|
|
|
|
m_layerZcoordBottom[layer_id] = zposBottom;
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
m_boardCenter = SFVEC3F( m_boardPos.x * m_biuTo3Dunits, m_boardPos.y * m_biuTo3Dunits, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
SFVEC3F boardSize = SFVEC3F( m_boardSize.x * m_biuTo3Dunits, m_boardSize.y * m_biuTo3Dunits,
|
2016-07-19 17:35:25 +00:00
|
|
|
0.0f );
|
2020-12-16 22:10:42 +00:00
|
|
|
boardSize /= 2.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
SFVEC3F boardMin = ( m_boardCenter - boardSize );
|
|
|
|
SFVEC3F boardMax = ( m_boardCenter + boardSize );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
boardMin.z = m_layerZcoordTop[B_Adhes];
|
|
|
|
boardMax.z = m_layerZcoordTop[F_Adhes];
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
m_boardBoundingBox = BBOX_3D( boardMin, boardMax );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
#ifdef PRINT_STATISTICS_3D_VIEWER
|
|
|
|
unsigned stats_startCreateBoardPolyTime = GetRunningMicroSecs();
|
|
|
|
#endif
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Create layers" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
createLayers( aStatusReporter );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-30 22:12:13 +00:00
|
|
|
extern bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines,
|
2020-12-24 21:35:31 +00:00
|
|
|
int aErrorMax, int aChainingEpsilon,
|
2020-11-21 20:42:27 +00:00
|
|
|
OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr );
|
2020-09-30 22:12:13 +00:00
|
|
|
|
|
|
|
|
2020-08-17 20:07:27 +00:00
|
|
|
bool BOARD_ADAPTER::createBoardPolygon( wxString* aErrorMsg )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
m_board_poly.RemoveAllContours();
|
|
|
|
|
2020-11-20 13:55:10 +00:00
|
|
|
bool success;
|
2020-09-30 22:12:13 +00:00
|
|
|
|
|
|
|
if( m_board->IsFootprintHolder() )
|
|
|
|
{
|
2020-11-21 20:42:27 +00:00
|
|
|
if( !m_board->GetFirstFootprint() )
|
|
|
|
{
|
|
|
|
if( aErrorMsg )
|
|
|
|
*aErrorMsg = _( "No footprint loaded." );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-24 21:00:41 +00:00
|
|
|
int chainingEpsilon = Millimeter2iu( 0.02 ); // max dist from one endPt to next startPt
|
|
|
|
|
2020-10-22 20:27:46 +00:00
|
|
|
success = BuildFootprintPolygonOutlines( m_board, m_board_poly,
|
2020-12-24 21:00:41 +00:00
|
|
|
m_board->GetDesignSettings().m_MaxError,
|
|
|
|
chainingEpsilon );
|
2020-09-30 22:12:13 +00:00
|
|
|
|
|
|
|
// Make polygon strictly simple to avoid issues (especially in 3D viewer)
|
|
|
|
m_board_poly.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
|
2020-11-20 13:55:10 +00:00
|
|
|
if( !success && aErrorMsg )
|
2020-11-21 20:42:27 +00:00
|
|
|
{
|
2020-11-24 14:22:05 +00:00
|
|
|
*aErrorMsg = _( "Footprint outline is missing or malformed. Run Footprint Checker for "
|
|
|
|
"a full analysis." );
|
2020-11-21 20:42:27 +00:00
|
|
|
}
|
2020-09-30 22:12:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-20 13:55:10 +00:00
|
|
|
success = m_board->GetBoardPolygonOutlines( m_board_poly );
|
2020-09-30 22:12:13 +00:00
|
|
|
|
2020-11-20 13:55:10 +00:00
|
|
|
if( !success && aErrorMsg )
|
2020-11-24 14:22:05 +00:00
|
|
|
*aErrorMsg = _( "Board outline is missing or malformed. Run DRC for a full analysis." );
|
2020-09-30 22:12:13 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-30 22:12:13 +00:00
|
|
|
return success;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
float BOARD_ADAPTER::GetFootprintZPos( bool aIsFlipped ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( aIsFlipped )
|
|
|
|
{
|
|
|
|
if( GetFlag( FL_SOLDERPASTE ) )
|
|
|
|
return m_layerZcoordBottom[B_SilkS];
|
|
|
|
else
|
|
|
|
return m_layerZcoordBottom[B_Paste];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( GetFlag( FL_SOLDERPASTE ) )
|
|
|
|
return m_layerZcoordTop[F_SilkS];
|
|
|
|
else
|
|
|
|
return m_layerZcoordTop[F_Paste];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-21 08:56:15 +00:00
|
|
|
SFVEC4F BOARD_ADAPTER::GetLayerColor( PCB_LAYER_ID aLayerId ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
wxASSERT( aLayerId < PCB_LAYER_ID_COUNT );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
const COLOR4D color = m_colors->GetColor( aLayerId );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-08-21 08:56:15 +00:00
|
|
|
return SFVEC4F( color.r, color.g, color.b, color.a );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-21 08:56:15 +00:00
|
|
|
SFVEC4F BOARD_ADAPTER::GetItemColor( int aItemId ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
return GetColor( m_colors->GetColor( aItemId ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-21 08:56:15 +00:00
|
|
|
SFVEC4F BOARD_ADAPTER::GetColor( COLOR4D aColor ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-08-21 08:56:15 +00:00
|
|
|
return SFVEC4F( aColor.r, aColor.g, aColor.b, aColor.a );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|