KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_adapter.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2023 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2023 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include "board_adapter.h"
23
24#include <wx/log.h>
25
26#include <gal/3d/camera.h>
31#include <board.h>
33#include <footprint.h>
34#include <layer_range.h>
35#include <3d_math.h>
36#include "3d_fastmath.h"
38#include <lset.h>
39#include <pgm_base.h>
42#include <pcb_track.h>
43#include <pcbnew_settings.h>
44#include <advanced_config.h>
45
46
47#define DEFAULT_BOARD_THICKNESS pcbIUScale.mmToIU( 1.6 )
48#define DEFAULT_COPPER_THICKNESS pcbIUScale.mmToIU( 0.035 ) // for 35 um
49// The solder mask layer (and silkscreen) thickness
50#define DEFAULT_TECH_LAYER_THICKNESS pcbIUScale.mmToIU( 0.025 )
51// The solder paste thickness is chosen bigger than the solder mask layer
52// to be sure is covers the mask when overlapping.
53#define SOLDERPASTE_LAYER_THICKNESS pcbIUScale.mmToIU( 0.04 )
54
55
56std::vector<CUSTOM_COLOR_ITEM> BOARD_ADAPTER::g_SilkColors;
57std::vector<CUSTOM_COLOR_ITEM> BOARD_ADAPTER::g_MaskColors;
58std::vector<CUSTOM_COLOR_ITEM> BOARD_ADAPTER::g_PasteColors;
59std::vector<CUSTOM_COLOR_ITEM> BOARD_ADAPTER::g_FinishColors;
60std::vector<CUSTOM_COLOR_ITEM> BOARD_ADAPTER::g_BoardColors;
61
74
75// To be used in Raytracing render to create bevels on layer items
77
78static bool g_ColorsLoaded = false;
79
88const wxChar *BOARD_ADAPTER::m_logTrace = wxT( "KI_TRACE_EDA_CINFO3D_VISU" );
89
90
92 m_Cfg( nullptr ),
93 m_IsBoardView( true ),
94 m_MousewheelPanning( true ),
95 m_IsPreviewer( false ),
96 m_board( nullptr ),
97 m_3dModelManager( nullptr ),
100{
101 wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::BOARD_ADAPTER" ) );
102
105 m_boardCenter = SFVEC3F( 0.0f );
106
107 m_boardBoundingBox.Reset();
108
109 m_TH_IDs.Clear();
110 m_TH_ODs.Clear();
111 m_viaAnnuli.Clear();
112
114
115 m_biuTo3Dunits = 1.0;
123
124 m_trackCount = 0;
125 m_viaCount = 0;
127 m_holeCount = 0;
129 m_averageTrackWidth = 0.0f;
130
131 m_BgColorBot = SFVEC4F( 0.4, 0.4, 0.5, 1.0 );
132 m_BgColorTop = SFVEC4F( 0.8, 0.8, 0.9, 1.0 );
133 m_BoardBodyColor = SFVEC4F( 0.4, 0.4, 0.5, 0.9 );
134 m_SolderMaskColorTop = SFVEC4F( 0.1, 0.2, 0.1, 0.83 );
135 m_SolderMaskColorBot = SFVEC4F( 0.1, 0.2, 0.1, 0.83 );
136 m_SolderPasteColor = SFVEC4F( 0.4, 0.4, 0.4, 1.0 );
137 m_SilkScreenColorTop = SFVEC4F( 0.9, 0.9, 0.9, 1.0 );
138 m_SilkScreenColorBot = SFVEC4F( 0.9, 0.9, 0.9, 1.0 );
139 m_CopperColor = SFVEC4F( 0.75, 0.61, 0.23, 1.0 );
140 m_UserDrawingsColor = SFVEC4F( 0.85, 0.85, 0.85, 1.0 );
141 m_UserCommentsColor = SFVEC4F( 0.85, 0.85, 0.85, 1.0 );
142 m_ECO1Color = SFVEC4F( 0.70, 0.10, 0.10, 1.0 );
143 m_ECO2Color = SFVEC4F( 0.70, 0.10, 0.10, 1.0 );
144 m_FFabColor = SFVEC4F( 0.60, 0.60, 0.60, 1.0 );
145 m_BFabColor = SFVEC4F( 0.60, 0.60, 0.60, 1.0 );
146 // Based on default board colourscheme for F.CrtYd and B.CrtYd
147 m_FCourtyardColor = SFVEC4F( 1.000, 0.149, 0.886, 1.0 );
148 m_BCourtyardColor = SFVEC4F( 1.000, 0.149, 0.886, 1.0 );
149
150 for( int ii = 0; ii < 45; ++ii )
151 m_UserDefinedLayerColor[ii] = SFVEC4F( 0.70, 0.10, 0.10, 1.0 );
152
153 m_platedPadsFront = nullptr;
154 m_platedPadsBack = nullptr;
155 m_offboardPadsFront = nullptr;
156 m_offboardPadsBack = nullptr;
157
158 m_frontPlatedCopperPolys = nullptr;
159 m_backPlatedCopperPolys = nullptr;
160
162
163 if( !g_ColorsLoaded )
164 {
165#define ADD_COLOR( list, r, g, b, a, name ) \
166 list.emplace_back( r/255.0, g/255.0, b/255.0, a, name )
167
168 ADD_COLOR( g_SilkColors, 245, 245, 245, 1.0, NotSpecifiedPrm() ); // White
169 ADD_COLOR( g_SilkColors, 20, 51, 36, 1.0, wxT( "Green" ) );
170 ADD_COLOR( g_SilkColors, 181, 19, 21, 1.0, wxT( "Red" ) );
171 ADD_COLOR( g_SilkColors, 2, 59, 162, 1.0, wxT( "Blue" ) );
172 ADD_COLOR( g_SilkColors, 11, 11, 11, 1.0, wxT( "Black" ) );
173 ADD_COLOR( g_SilkColors, 245, 245, 245, 1.0, wxT( "White" ) );
174 ADD_COLOR( g_SilkColors, 32, 2, 53, 1.0, wxT( "Purple" ) );
175 ADD_COLOR( g_SilkColors, 194, 195, 0, 1.0, wxT( "Yellow" ) );
176
177 ADD_COLOR( g_MaskColors, 20, 51, 36, 0.83, NotSpecifiedPrm() ); // Green
178 ADD_COLOR( g_MaskColors, 20, 51, 36, 0.83, wxT( "Green" ) );
179 ADD_COLOR( g_MaskColors, 91, 168, 12, 0.83, wxT( "Light Green" ) );
180 ADD_COLOR( g_MaskColors, 13, 104, 11, 0.83, wxT( "Saturated Green" ) );
181 ADD_COLOR( g_MaskColors, 181, 19, 21, 0.83, wxT( "Red" ) );
182 ADD_COLOR( g_MaskColors, 210, 40, 14, 0.83, wxT( "Light Red" ) );
183 ADD_COLOR( g_MaskColors, 239, 53, 41, 0.83, wxT( "Red/Orange" ) );
184 ADD_COLOR( g_MaskColors, 2, 59, 162, 0.83, wxT( "Blue" ) );
185 ADD_COLOR( g_MaskColors, 54, 79, 116, 0.83, wxT( "Light Blue 1" ) );
186 ADD_COLOR( g_MaskColors, 61, 85, 130, 0.83, wxT( "Light Blue 2" ) );
187 ADD_COLOR( g_MaskColors, 21, 70, 80, 0.83, wxT( "Green/Blue" ) );
188 ADD_COLOR( g_MaskColors, 11, 11, 11, 0.83, wxT( "Black" ) );
189 ADD_COLOR( g_MaskColors, 245, 245, 245, 0.83, wxT( "White" ) );
190 ADD_COLOR( g_MaskColors, 32, 2, 53, 0.83, wxT( "Purple" ) );
191 ADD_COLOR( g_MaskColors, 119, 31, 91, 0.83, wxT( "Light Purple" ) );
192 ADD_COLOR( g_MaskColors, 194, 195, 0, 0.83, wxT( "Yellow" ) );
193
194 ADD_COLOR( g_PasteColors, 128, 128, 128, 1.0, wxT( "Grey" ) );
195 ADD_COLOR( g_PasteColors, 90, 90, 90, 1.0, wxT( "Dark Grey" ) );
196 ADD_COLOR( g_PasteColors, 213, 213, 213, 1.0, wxT( "Silver" ) );
197
198 ADD_COLOR( g_FinishColors, 184, 115, 50, 1.0, wxT( "Copper" ) );
199 ADD_COLOR( g_FinishColors, 178, 156, 0, 1.0, wxT( "Gold" ) );
200 ADD_COLOR( g_FinishColors, 213, 213, 213, 1.0, wxT( "Silver" ) );
201 ADD_COLOR( g_FinishColors, 160, 160, 160, 1.0, wxT( "Tin" ) );
202
203 ADD_COLOR( g_BoardColors, 51, 43, 22, 0.83, wxT( "FR4 natural, dark" ) );
204 ADD_COLOR( g_BoardColors, 109, 116, 75, 0.83, wxT( "FR4 natural" ) );
205 ADD_COLOR( g_BoardColors, 252, 252, 250, 0.90, wxT( "PTFE natural" ) );
206 ADD_COLOR( g_BoardColors, 205, 130, 0, 0.68, wxT( "Polyimide" ) );
207 ADD_COLOR( g_BoardColors, 92, 17, 6, 0.90, wxT( "Phenolic natural" ) );
208 ADD_COLOR( g_BoardColors, 146, 99, 47, 0.83, wxT( "Brown 1" ) );
209 ADD_COLOR( g_BoardColors, 160, 123, 54, 0.83, wxT( "Brown 2" ) );
210 ADD_COLOR( g_BoardColors, 146, 99, 47, 0.83, wxT( "Brown 3" ) );
211 ADD_COLOR( g_BoardColors, 213, 213, 213, 1.0, wxT( "Aluminum" ) );
212
213 g_DefaultBackgroundTop = COLOR4D( 0.80, 0.80, 0.90, 1.0 );
214 g_DefaultBackgroundBot = COLOR4D( 0.40, 0.40, 0.50, 1.0 );
215
216 g_DefaultSilkscreen = COLOR4D( 0.94, 0.94, 0.94, 1.0 );
217 g_DefaultSolderMask = COLOR4D( 0.08, 0.20, 0.14, 0.83 );
218 g_DefaultSolderPaste = COLOR4D( 0.50, 0.50, 0.50, 1.0 );
219 g_DefaultAdhesive = COLOR4D( 0.70, 0.11, 0.17, 1.0 );
220 g_DefaultSurfaceFinish = COLOR4D( 0.75, 0.61, 0.23, 1.0 );
221 g_DefaultBoardBody = COLOR4D( 0.43, 0.45, 0.30, 0.90 );
222
223 g_DefaultComments = COLOR4D( 0.85, 0.85, 0.85, 1.0 );
224 g_DefaultECOs = COLOR4D( 0.70, 0.10, 0.10, 1.0 );
225
226 g_DefaultFabColor = COLOR4D( 0.60, 0.60, 0.60, 1.0 );
227 g_DefaultCourtyardColor = COLOR4D( 1.000, 0.149, 0.886, 1.0 );
228
229 g_ColorsLoaded = true;
230 }
231#undef ADD_COLOR
232}
233
234
239
240
242{
245
246 for( int layer = F_Cu; layer < PCB_LAYER_ID_COUNT; ++layer )
247 m_BoardEditorColors[ layer ] = cs->GetColor( layer );
248}
249
250
252 const std::bitset<LAYER_3D_END>& aVisibilityFlags ) const
253{
254 wxASSERT( aLayer < PCB_LAYER_ID_COUNT );
255
256 if( m_board && !m_board->IsLayerEnabled( aLayer ) )
257 return false;
258
259 switch( aLayer )
260 {
261 case B_Cu: return aVisibilityFlags.test( LAYER_3D_COPPER_BOTTOM );
262 case F_Cu: return aVisibilityFlags.test( LAYER_3D_COPPER_TOP );
263 case B_Adhes: return aVisibilityFlags.test( LAYER_3D_ADHESIVE );
264 case F_Adhes: return aVisibilityFlags.test( LAYER_3D_ADHESIVE );
265 case B_Paste: return aVisibilityFlags.test( LAYER_3D_SOLDERPASTE );
266 case F_Paste: return aVisibilityFlags.test( LAYER_3D_SOLDERPASTE );
267 case B_SilkS: return aVisibilityFlags.test( LAYER_3D_SILKSCREEN_BOTTOM );
268 case F_SilkS: return aVisibilityFlags.test( LAYER_3D_SILKSCREEN_TOP );
269 case B_Mask: return aVisibilityFlags.test( LAYER_3D_SOLDERMASK_BOTTOM );
270 case F_Mask: return aVisibilityFlags.test( LAYER_3D_SOLDERMASK_TOP );
271 case Dwgs_User: return aVisibilityFlags.test( LAYER_3D_USER_DRAWINGS );
272 case Cmts_User: return aVisibilityFlags.test( LAYER_3D_USER_COMMENTS );
273 case Eco1_User: return aVisibilityFlags.test( LAYER_3D_USER_ECO1 );
274 case Eco2_User: return aVisibilityFlags.test( LAYER_3D_USER_ECO2 );
275 case F_Fab: return aVisibilityFlags.test( LAYER_3D_F_FAB );
276 case B_Fab: return aVisibilityFlags.test( LAYER_3D_B_FAB );
277 case F_CrtYd: return aVisibilityFlags.test( LAYER_3D_F_COURTYARD );
278 case B_CrtYd: return aVisibilityFlags.test( LAYER_3D_B_COURTYARD );
279 default:
280 {
281 int layer3D = MapPCBLayerTo3DLayer( aLayer );
282
283 if( layer3D != UNDEFINED_LAYER )
284 return aVisibilityFlags.test( layer3D );
285
286 return m_board && m_board->IsLayerVisible( aLayer );
287 }
288 }
289}
290
291
292bool BOARD_ADAPTER::IsFootprintShown( const FOOTPRINT* aFootprint ) const
293{
294 if( m_IsPreviewer ) // In panel Preview, footprints are always shown, of course
295 return true;
296
297 if( !aFootprint )
298 return false;
299
300 const wxString variantName = m_board ? m_board->GetCurrentVariant() : wxString();
301 const bool excludedFromPos = aFootprint->GetExcludedFromPosFilesForVariant( variantName );
302 const bool dnp = aFootprint->GetDNPForVariant( variantName );
303 const auto attributes = static_cast<FOOTPRINT_ATTR_T>( aFootprint->GetAttributes() );
304
305 if( excludedFromPos )
306 {
307 if( !m_Cfg->m_Render.show_footprints_not_in_posfile )
308 return false;
309 }
310
311 if( dnp )
312 {
313 if( !m_Cfg->m_Render.show_footprints_dnp )
314 return false;
315 }
316
317 if( attributes & FP_SMD )
318 return m_Cfg->m_Render.show_footprints_insert;
319
320 if( attributes & FP_THROUGH_HOLE )
321 return m_Cfg->m_Render.show_footprints_normal;
322
323 return m_Cfg->m_Render.show_footprints_virtual;
324}
325
326
328{
329 return m_board ? m_board->GetDesignSettings().GetHolePlatingThickness()
331}
332
333
334unsigned int BOARD_ADAPTER::GetCircleSegmentCount( float aDiameter3DU ) const
335{
336 wxASSERT( aDiameter3DU > 0.0f );
337
338 return GetCircleSegmentCount( (int)( aDiameter3DU / m_biuTo3Dunits ) );
339}
340
341
342unsigned int BOARD_ADAPTER::GetCircleSegmentCount( int aDiameterBIU ) const
343{
344 wxASSERT( aDiameterBIU > 0 );
345
346 return GetArcToSegmentCount( aDiameterBIU / 2, m_board->GetDesignSettings().m_MaxError, FULL_CIRCLE );
347}
348
349
350void BOARD_ADAPTER::InitSettings( std::shared_ptr<REPORTER> aStatusReporter,
351 std::shared_ptr<REPORTER> aWarningReporter )
352{
353 wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::InitSettings" ) );
354
355 if( aStatusReporter )
356 aStatusReporter->Report( _( "Build board outline" ) );
357
358 wxString msg;
359
360 const bool haveOutline = createBoardPolygon( &msg );
361
362 if( aWarningReporter )
363 {
364 if( !haveOutline )
365 aWarningReporter->Report( msg, RPT_SEVERITY_WARNING );
366 else
367 aWarningReporter->Report( wxEmptyString );
368 }
369
370 BOX2I bbbox;
371
372 if( m_board )
373 bbbox = m_board->ComputeBoundingBox( !m_board->IsFootprintHolder() && haveOutline, true );
374
375 // Gives a non null size to avoid issues in zoom / scale calculations
376 if( ( bbbox.GetWidth() == 0 ) && ( bbbox.GetHeight() == 0 ) )
377 bbbox.Inflate( pcbIUScale.mmToIU( 10 ) );
378
379 m_boardSize = bbbox.GetSize();
380 m_boardPos = bbbox.Centre();
381
382 wxASSERT( (m_boardSize.x > 0) && (m_boardSize.y > 0) );
383
384 m_boardPos.y = -m_boardPos.y; // The y coord is inverted in 3D viewer
385
386 m_copperLayersCount = m_board ? m_board->GetCopperLayerCount() : 2;
387
388 // Ensure the board has 2 sides for 3D views, because it is hard to find
389 // a *really* single side board in the true life...
390 if( m_copperLayersCount < 2 )
392
393 // Calculate the conversion to apply to all positions.
395
396 // Hack to keep "home" zoom from being too small.
397 if( !m_board || !m_board->IsFootprintHolder() )
398 m_biuTo3Dunits *= 1.6f;
399
401
409
410 g_BevelThickness3DU = pcbIUScale.mmToIU( ADVANCED_CFG::GetCfg().m_3DRT_BevelHeight_um / 1000.0 )
412
413 if( m_board )
414 {
415 const BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
416
417 if( bds.GetStackupDescriptor().GetCount() )
418 {
419 int body_thickness = 0;
420
421 for( BOARD_STACKUP_ITEM* item : bds.GetStackupDescriptor().GetList() )
422 {
423 switch( item->GetType() )
424 {
426 for( int sublayer = 0; sublayer < item->GetSublayersCount(); sublayer++ )
427 body_thickness += item->GetThickness( sublayer );
428
429 break;
430
432 {
433 // The copper thickness must be > 0 to avoid draw issues (divide by 0 for
434 // instance). We use a minimal arbitrary value = 1 micrometer here:
435 int copper_thickness = std::max( item->GetThickness(), pcbIUScale.mmToIU( 0.001 ) );
436
437 if( item->GetBrdLayerId() == F_Cu )
438 m_frontCopperThickness3DU = copper_thickness * m_biuTo3Dunits;
439 else if( item->GetBrdLayerId() == B_Cu )
440 m_backCopperThickness3DU = copper_thickness * m_biuTo3Dunits;
441 else if( item->IsEnabled() )
442 body_thickness += copper_thickness;
443
444 break;
445 }
446
448 {
449 // The mask thickness must be > 0 to avoid draw issues (divide by 0 for
450 // instance). We use a minimal arbitrary value = 1 micrometer here:
451 int mask_thickness = std::max( item->GetThickness(), pcbIUScale.mmToIU( 0.001 ) );
452
453 if( item->GetBrdLayerId() == F_Mask )
454 m_frontMaskThickness3DU = mask_thickness * m_biuTo3Dunits;
455 else if( item->GetBrdLayerId() == B_Mask )
456 m_backMaskThickness3DU = mask_thickness * m_biuTo3Dunits;
457 }
458
459 default:
460 break;
461 }
462 }
463
464 m_boardBodyThickness3DU = body_thickness * m_biuTo3Dunits;
465 }
466 }
467
468 // Init Z position of each layer
469 // calculate z position for each copper layer
470 // Zstart = -m_epoxyThickness / 2.0 is the z position of the back (bottom layer)
471 // (layer id = B_Cu)
472 // Zstart = +m_epoxyThickness / 2.0 is the z position of the front (top layer)
473 // (layer id = F_Cu)
474
475 // ____==__________==________==______ <- Bottom = +m_epoxyThickness / 2.0,
476 // | | Top = Bottom + m_copperThickness
477 // |__________________________________|
478 // == == == == <- Bottom = -m_epoxyThickness / 2.0,
479 // Top = Bottom - m_copperThickness
480
481 // Generate the Z position of copper layers
482 // A copper layer Z position has 2 values: its top Z position and its bottom Z position
483 for( auto layer_id : LAYER_RANGE( F_Cu, B_Cu, m_copperLayersCount ) )
484 {
485 // This approximates internal layer positions (because we're treating all the dielectric
486 // layers as having the same thickness). But we don't render them anyway so it doesn't
487 // really matter.
488 int layer_pos; // the position of the copper layer from board top to bottom
489
490 switch( layer_id )
491 {
492 case F_Cu: layer_pos = 0; break;
493 case B_Cu: layer_pos = m_copperLayersCount - 1; break;
494 default: layer_pos = ( layer_id - B_Cu )/2; break;
495 };
496
498 - ( m_boardBodyThickness3DU * layer_pos / ( m_copperLayersCount - 1 ) );
499
500 if( layer_pos < (m_copperLayersCount / 2) )
502 else
504 }
505
506 #define layerThicknessMargin 1.1
507 const float zpos_offset = m_nonCopperLayerThickness3DU * layerThicknessMargin;
508
509 // This is the top of the copper layer thickness.
510 const float zpos_copperTop_back = m_layerZcoordTop[B_Cu];
511 const float zpos_copperTop_front = m_layerZcoordTop[F_Cu];
512
513 // Fill not copper layers zpos
514 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; layer++ )
515 {
516 PCB_LAYER_ID layer_id = ToLAYER_ID( layer );
517
518 if( IsCopperLayer( layer_id ) )
519 continue;
520
521 float zposBottom;
522 float zposTop;
523
524 switch( layer_id )
525 {
526 case B_Mask:
527 zposBottom = zpos_copperTop_back;
528 zposTop = zpos_copperTop_back - m_backMaskThickness3DU;
529 break;
530
531 case B_Paste:
532 zposBottom = zpos_copperTop_back;
533 zposTop = zpos_copperTop_back - m_solderPasteLayerThickness3DU;
534 break;
535
536 case F_Mask:
537 zposBottom = zpos_copperTop_front;
538 zposTop = zpos_copperTop_front + m_frontMaskThickness3DU;
539 break;
540
541 case F_Paste:
542 zposBottom = zpos_copperTop_front;
543 zposTop = zpos_copperTop_front + m_solderPasteLayerThickness3DU;
544 break;
545
546 case B_SilkS:
547 zposBottom = zpos_copperTop_back - 1.0f * zpos_offset;
548 zposTop = zposBottom - m_nonCopperLayerThickness3DU;
549 break;
550
551 case F_SilkS:
552 zposBottom = zpos_copperTop_front + 1.0f * zpos_offset;
553 zposTop = zposBottom + m_nonCopperLayerThickness3DU;
554 break;
555
556 default:
557 if( m_board->IsBackLayer( layer_id ) )
558 {
559 zposBottom = zpos_copperTop_back - 2.0f * zpos_offset;
560 zposTop = zposBottom - m_nonCopperLayerThickness3DU;
561 }
562 else
563 {
564 zposBottom = zpos_copperTop_front + 2.0f * zpos_offset;
565 zposTop = zposBottom + m_nonCopperLayerThickness3DU;
566 }
567 break;
568 }
569
570 m_layerZcoordTop[layer_id] = zposTop;
571 m_layerZcoordBottom[layer_id] = zposBottom;
572 }
573
575
577 boardSize /= 2.0f;
578
579 SFVEC3F boardMin = ( m_boardCenter - boardSize );
580 SFVEC3F boardMax = ( m_boardCenter + boardSize );
581
582 boardMin.z = m_layerZcoordTop[B_Adhes];
583 boardMax.z = m_layerZcoordTop[F_Adhes];
584
585 m_boardBoundingBox = BBOX_3D( boardMin, boardMax );
586}
587
588
589void BOARD_ADAPTER::CreateLayers( std::shared_ptr<REPORTER> aStatusReporter, std::stop_token aStop )
590{
591#ifdef PRINT_STATISTICS_3D_VIEWER
592 int64_t stats_startCreateBoardPolyTime = GetRunningMicroSecs();
593#endif
594
595 if( aStatusReporter )
596 aStatusReporter->Report( _( "Create layers" ) );
597
598 createLayers( aStatusReporter, aStop );
599
600 auto to_SFVEC4F =
601 []( const COLOR4D& src )
602 {
603 return SFVEC4F( src.r, src.g, src.b, src.a );
604 };
605
606 std::map<int, COLOR4D> colors = GetLayerColors();
607
608 m_BgColorTop = to_SFVEC4F( colors[ LAYER_3D_BACKGROUND_TOP ] );
609 m_BgColorBot = to_SFVEC4F( colors[ LAYER_3D_BACKGROUND_BOTTOM ] );
610 m_SolderPasteColor = to_SFVEC4F( colors[ LAYER_3D_SOLDERPASTE ] );
611 m_AdhesiveColor = to_SFVEC4F( colors[ LAYER_3D_ADHESIVE ] );
612 m_SilkScreenColorBot = to_SFVEC4F( colors[ LAYER_3D_SILKSCREEN_BOTTOM ] );
613 m_SilkScreenColorTop = to_SFVEC4F( colors[ LAYER_3D_SILKSCREEN_TOP ] );
614 m_SolderMaskColorBot = to_SFVEC4F( colors[ LAYER_3D_SOLDERMASK_BOTTOM ] );
615 m_SolderMaskColorTop = to_SFVEC4F( colors[ LAYER_3D_SOLDERMASK_TOP ] );
616 m_CopperColor = to_SFVEC4F( colors[ LAYER_3D_COPPER_TOP ] );
617 m_BoardBodyColor = to_SFVEC4F( colors[ LAYER_3D_BOARD ] );
618 m_UserDrawingsColor = to_SFVEC4F( colors[ LAYER_3D_USER_DRAWINGS ] );
619 m_UserCommentsColor = to_SFVEC4F( colors[ LAYER_3D_USER_COMMENTS ] );
620 m_ECO1Color = to_SFVEC4F( colors[ LAYER_3D_USER_ECO1 ] );
621 m_ECO2Color = to_SFVEC4F( colors[ LAYER_3D_USER_ECO2 ] );
622 m_FFabColor = to_SFVEC4F( colors[ LAYER_3D_F_FAB ] );
623 m_BFabColor = to_SFVEC4F( colors[ LAYER_3D_B_FAB ] );
624 m_FCourtyardColor = to_SFVEC4F( colors[ LAYER_3D_F_COURTYARD ] );
625 m_BCourtyardColor = to_SFVEC4F( colors[ LAYER_3D_B_COURTYARD ] );
626
627 for( int layer = LAYER_3D_USER_1; layer <= LAYER_3D_USER_45; ++layer )
628 m_UserDefinedLayerColor[ layer - LAYER_3D_USER_1 ] = to_SFVEC4F( colors[ layer ] );
629}
630
631
632std::map<int, COLOR4D> BOARD_ADAPTER::GetDefaultColors() const
633{
634 std::map<int, COLOR4D> colors;
635
655
657
658 for( int layer = LAYER_3D_USER_1; layer <= LAYER_3D_USER_45; ++layer )
659 colors[ layer ] = settings->GetColor( layer );
660
661 return colors;
662}
663
664
665std::map<int, COLOR4D> BOARD_ADAPTER::GetLayerColors() const
666{
667 std::map<int, COLOR4D> colors;
668
669 if( LAYER_PRESET_3D* preset = m_Cfg->FindPreset( m_Cfg->m_CurrentPreset ) )
670 {
671 colors = preset->colors;
672 }
673 else
674 {
676
677 for( const auto& [ layer, defaultColor /* unused */ ] : GetDefaultColors() )
678 colors[ layer ] = settings->GetColor( layer );
679 }
680
681 if( m_Cfg->m_UseStackupColors && m_board )
682 {
683 const BOARD_STACKUP& stackup = m_board->GetDesignSettings().GetStackupDescriptor();
684 KIGFX::COLOR4D bodyColor( 0, 0, 0, 0 );
685
686 // Can't do a const KIGFX::COLOR4D& return type here because there are temporary variables
687 auto findColor =
688 []( const wxString& aName, const std::vector<CUSTOM_COLOR_ITEM>& aColorSet ) -> const KIGFX::COLOR4D
689 {
690 if( aName.StartsWith( wxT( "#" ) ) )
691 {
692 return KIGFX::COLOR4D( aName );
693 }
694 else
695 {
696 for( const CUSTOM_COLOR_ITEM& color : aColorSet )
697 {
698 if( color.m_ColorName == aName )
699 return color.m_Color;
700 }
701 }
702
703 return KIGFX::COLOR4D();
704 };
705
706 for( const BOARD_STACKUP_ITEM* stackupItem : stackup.GetList() )
707 {
708 wxString colorName = stackupItem->GetColor();
709
710 switch( stackupItem->GetType() )
711 {
713 if( stackupItem->GetBrdLayerId() == F_SilkS )
714 colors[ LAYER_3D_SILKSCREEN_TOP ] = findColor( colorName, g_SilkColors );
715 else
716 colors[ LAYER_3D_SILKSCREEN_BOTTOM ] = findColor( colorName, g_SilkColors );
717
718 break;
719
721 if( stackupItem->GetBrdLayerId() == F_Mask )
722 colors[ LAYER_3D_SOLDERMASK_TOP ] = findColor( colorName, g_MaskColors );
723 else
724 colors[ LAYER_3D_SOLDERMASK_BOTTOM ] = findColor( colorName, g_MaskColors );
725
726 break;
727
729 {
730 KIGFX::COLOR4D layerColor = findColor( colorName, g_BoardColors );
731
732 if( bodyColor == COLOR4D( 0, 0, 0, 0 ) )
733 bodyColor = layerColor;
734 else
735 bodyColor = bodyColor.Mix( layerColor, 1.0 - layerColor.a );
736
737 bodyColor.a += ( 1.0 - bodyColor.a ) * layerColor.a / 2;
738 break;
739 }
740
741 default:
742 break;
743 }
744 }
745
746 if( bodyColor != COLOR4D( 0, 0, 0, 0 ) )
747 colors[ LAYER_3D_BOARD ] = bodyColor;
748
749 const wxString& finishName = stackup.m_FinishType;
750
751 if( finishName.EndsWith( wxT( "OSP" ) ) )
752 {
753 colors[ LAYER_3D_COPPER_TOP ] = findColor( wxT( "Copper" ), g_FinishColors );
754 }
755 else if( finishName.EndsWith( wxT( "IG" ) )
756 || finishName.EndsWith( wxT( "gold" ) ) )
757 {
758 colors[ LAYER_3D_COPPER_TOP ] = findColor( wxT( "Gold" ), g_FinishColors );
759 }
760 else if( finishName.StartsWith( wxT( "HAL" ) )
761 || finishName.StartsWith( wxT( "HASL" ) )
762 || finishName.EndsWith( wxT( "tin" ) )
763 || finishName.EndsWith( wxT( "nickel" ) ) )
764 {
765 colors[ LAYER_3D_COPPER_TOP ] = findColor( wxT( "Tin" ), g_FinishColors );
766 }
767 else if( finishName.EndsWith( wxT( "silver" ) ) )
768 {
769 colors[ LAYER_3D_COPPER_TOP ] = findColor( wxT( "Silver" ), g_FinishColors );
770 }
771 }
772
773 colors[ LAYER_3D_COPPER_BOTTOM ] = colors[ LAYER_3D_COPPER_TOP ];
774
775 for( const auto& [layer, val] : m_ColorOverrides )
776 colors[layer] = val;
777
778 return colors;
779}
780
781
782void BOARD_ADAPTER::SetLayerColors( const std::map<int, COLOR4D>& aColors )
783{
785
786 for( const auto& [ layer, color ] : aColors )
787 {
788 settings->SetColor( layer, color );
789
790 if( layer >= LAYER_3D_USER_1 && layer <= LAYER_3D_USER_45 )
792 }
793
794 Pgm().GetSettingsManager().SaveColorSettings( settings, "3d_viewer" );
795}
796
797
798void BOARD_ADAPTER::SetVisibleLayers( const std::bitset<LAYER_3D_END>& aLayers )
799{
800 m_Cfg->m_Render.show_board_body = aLayers.test( LAYER_3D_BOARD );
801 m_Cfg->m_Render.show_plated_barrels = aLayers.test( LAYER_3D_PLATED_BARRELS );
802 m_Cfg->m_Render.show_copper_top = aLayers.test( LAYER_3D_COPPER_TOP );
803 m_Cfg->m_Render.show_copper_bottom = aLayers.test( LAYER_3D_COPPER_BOTTOM );
804 m_Cfg->m_Render.show_silkscreen_top = aLayers.test( LAYER_3D_SILKSCREEN_TOP );
805 m_Cfg->m_Render.show_silkscreen_bottom = aLayers.test( LAYER_3D_SILKSCREEN_BOTTOM );
806 m_Cfg->m_Render.show_soldermask_top = aLayers.test( LAYER_3D_SOLDERMASK_TOP );
807 m_Cfg->m_Render.show_soldermask_bottom = aLayers.test( LAYER_3D_SOLDERMASK_BOTTOM );
808 m_Cfg->m_Render.show_solderpaste = aLayers.test( LAYER_3D_SOLDERPASTE );
809 m_Cfg->m_Render.show_adhesive = aLayers.test( LAYER_3D_ADHESIVE );
810 m_Cfg->m_Render.show_comments = aLayers.test( LAYER_3D_USER_COMMENTS );
811 m_Cfg->m_Render.show_drawings = aLayers.test( LAYER_3D_USER_DRAWINGS );
812 m_Cfg->m_Render.show_eco1 = aLayers.test( LAYER_3D_USER_ECO1 );
813 m_Cfg->m_Render.show_eco2 = aLayers.test( LAYER_3D_USER_ECO2 );
814 m_Cfg->m_Render.show_f_fab = aLayers.test( LAYER_3D_F_FAB );
815 m_Cfg->m_Render.show_b_fab = aLayers.test( LAYER_3D_B_FAB );
816 m_Cfg->m_Render.show_f_courtyard = aLayers.test( LAYER_3D_F_COURTYARD );
817 m_Cfg->m_Render.show_b_courtyard = aLayers.test( LAYER_3D_B_COURTYARD );
818
819 for( int layer = LAYER_3D_USER_1; layer <= LAYER_3D_USER_45; ++layer )
820 m_Cfg->m_Render.show_user[ layer - LAYER_3D_USER_1 ] = aLayers.test( layer );
821
822 m_Cfg->m_Render.show_footprints_normal = aLayers.test( LAYER_3D_TH_MODELS );
823 m_Cfg->m_Render.show_footprints_insert = aLayers.test( LAYER_3D_SMD_MODELS );
824 m_Cfg->m_Render.show_footprints_virtual = aLayers.test( LAYER_3D_VIRTUAL_MODELS );
825 m_Cfg->m_Render.show_footprints_not_in_posfile = aLayers.test( LAYER_3D_MODELS_NOT_IN_POS );
826 m_Cfg->m_Render.show_footprints_dnp = aLayers.test( LAYER_3D_MODELS_MARKED_DNP );
827
828 m_Cfg->m_Render.show_fp_references = aLayers.test( LAYER_FP_REFERENCES );
829 m_Cfg->m_Render.show_fp_values = aLayers.test( LAYER_FP_VALUES );
830 m_Cfg->m_Render.show_fp_text = aLayers.test( LAYER_FP_TEXT );
831
832 m_Cfg->m_Render.show_model_bbox = aLayers.test( LAYER_3D_BOUNDING_BOXES );
833 m_Cfg->m_Render.show_off_board_silk = aLayers.test( LAYER_3D_OFF_BOARD_SILK );
834 m_Cfg->m_Render.show_navigator = aLayers.test( LAYER_3D_NAVIGATOR );
835}
836
837
838std::bitset<LAYER_3D_END> BOARD_ADAPTER::GetVisibleLayers() const
839{
841 return *m_visibilityOverride;
842
843 std::bitset<LAYER_3D_END> ret;
844
845 if( m_IsPreviewer )
846 {
847 // The preview has one board-body button and no layer controls, so it cannot follow
848 // the per-layer flags the 3D viewer's appearance panel writes: a mask switched off
849 // there would leave the preview showing bare substrate with no way back.
850 if( m_Cfg->m_Render.preview_show_board_body )
851 {
852 ret.set( LAYER_3D_BOARD, true );
853 ret.set( LAYER_3D_SOLDERMASK_TOP, true );
854 ret.set( LAYER_3D_SOLDERMASK_BOTTOM, true );
855 ret.set( LAYER_3D_SOLDERPASTE, true );
856 ret.set( LAYER_3D_ADHESIVE, m_Cfg->m_Render.show_adhesive );
857 }
858
859 ret.set( LAYER_3D_PLATED_BARRELS, true );
860 ret.set( LAYER_3D_COPPER_TOP, true );
861 ret.set( LAYER_3D_COPPER_BOTTOM, true );
862 ret.set( LAYER_3D_SILKSCREEN_TOP, true );
863 ret.set( LAYER_3D_SILKSCREEN_BOTTOM, true );
864 ret.set( LAYER_3D_USER_COMMENTS, true );
865 ret.set( LAYER_3D_USER_DRAWINGS, true );
866 ret.set( LAYER_3D_USER_ECO1, true );
867 ret.set( LAYER_3D_USER_ECO2, true );
868 ret.set( LAYER_3D_F_FAB, true );
869 ret.set( LAYER_3D_B_FAB, true );
870 ret.set( LAYER_3D_F_COURTYARD, true );
871 ret.set( LAYER_3D_B_COURTYARD, true );
872
873 for( int layer = LAYER_3D_USER_1; layer <= LAYER_3D_USER_45; ++layer )
874 ret.set( layer, true );
875
876 ret.set( LAYER_FP_REFERENCES, true );
877 ret.set( LAYER_FP_VALUES, true );
878 ret.set( LAYER_FP_TEXT, true );
879
880 ret.set( LAYER_3D_TH_MODELS, true );
881 ret.set( LAYER_3D_SMD_MODELS, true );
882 ret.set( LAYER_3D_VIRTUAL_MODELS, true );
883 ret.set( LAYER_3D_MODELS_NOT_IN_POS, true );
884 ret.set( LAYER_3D_MODELS_MARKED_DNP, true );
885
886 ret.set( LAYER_3D_BOUNDING_BOXES, m_Cfg->m_Render.show_model_bbox );
887 ret.set( LAYER_3D_OFF_BOARD_SILK, m_Cfg->m_Render.show_off_board_silk );
888 ret.set( LAYER_3D_NAVIGATOR, m_Cfg->m_Render.show_navigator );
889
890 return ret;
891 }
892
893 ret.set( LAYER_3D_BOARD, m_Cfg->m_Render.show_board_body );
894 ret.set( LAYER_3D_PLATED_BARRELS, m_Cfg->m_Render.show_plated_barrels );
895 ret.set( LAYER_3D_COPPER_TOP, m_Cfg->m_Render.show_copper_top );
896 ret.set( LAYER_3D_COPPER_BOTTOM, m_Cfg->m_Render.show_copper_bottom );
897 ret.set( LAYER_3D_SILKSCREEN_TOP, m_Cfg->m_Render.show_silkscreen_top );
898 ret.set( LAYER_3D_SILKSCREEN_BOTTOM, m_Cfg->m_Render.show_silkscreen_bottom );
899 ret.set( LAYER_3D_SOLDERMASK_TOP, m_Cfg->m_Render.show_soldermask_top );
900 ret.set( LAYER_3D_SOLDERMASK_BOTTOM, m_Cfg->m_Render.show_soldermask_bottom );
901 ret.set( LAYER_3D_SOLDERPASTE, m_Cfg->m_Render.show_solderpaste );
902 ret.set( LAYER_3D_ADHESIVE, m_Cfg->m_Render.show_adhesive );
903 ret.set( LAYER_3D_USER_COMMENTS, m_Cfg->m_Render.show_comments );
904 ret.set( LAYER_3D_USER_DRAWINGS, m_Cfg->m_Render.show_drawings );
905 ret.set( LAYER_3D_USER_ECO1, m_Cfg->m_Render.show_eco1 );
906 ret.set( LAYER_3D_USER_ECO2, m_Cfg->m_Render.show_eco2 );
907 ret.set( LAYER_3D_F_FAB, m_Cfg->m_Render.show_f_fab );
908 ret.set( LAYER_3D_B_FAB, m_Cfg->m_Render.show_b_fab );
909 ret.set( LAYER_3D_F_COURTYARD, m_Cfg->m_Render.show_f_courtyard );
910 ret.set( LAYER_3D_B_COURTYARD, m_Cfg->m_Render.show_b_courtyard );
911
912 for( int layer = LAYER_3D_USER_1; layer <= LAYER_3D_USER_45; ++layer )
913 ret.set( layer, m_Cfg->m_Render.show_user[ layer - LAYER_3D_USER_1 ] );
914
915 ret.set( LAYER_FP_REFERENCES, m_Cfg->m_Render.show_fp_references );
916 ret.set( LAYER_FP_VALUES, m_Cfg->m_Render.show_fp_values );
917 ret.set( LAYER_FP_TEXT, m_Cfg->m_Render.show_fp_text );
918
919 ret.set( LAYER_3D_TH_MODELS, m_Cfg->m_Render.show_footprints_normal );
920 ret.set( LAYER_3D_SMD_MODELS, m_Cfg->m_Render.show_footprints_insert );
921 ret.set( LAYER_3D_VIRTUAL_MODELS, m_Cfg->m_Render.show_footprints_virtual );
922 ret.set( LAYER_3D_MODELS_NOT_IN_POS, m_Cfg->m_Render.show_footprints_not_in_posfile );
923 ret.set( LAYER_3D_MODELS_MARKED_DNP, m_Cfg->m_Render.show_footprints_dnp );
924
925 ret.set( LAYER_3D_BOUNDING_BOXES, m_Cfg->m_Render.show_model_bbox );
926 ret.set( LAYER_3D_OFF_BOARD_SILK, m_Cfg->m_Render.show_off_board_silk );
927 ret.set( LAYER_3D_NAVIGATOR, m_Cfg->m_Render.show_navigator );
928
929 if( m_Cfg->m_CurrentPreset == FOLLOW_PCB )
930 {
931 if( !m_board )
932 return ret;
933
934 ret.set( LAYER_3D_BOARD, true );
935 ret.set( LAYER_3D_COPPER_TOP, m_board->IsLayerVisible( F_Cu ) );
936 ret.set( LAYER_3D_COPPER_BOTTOM, m_board->IsLayerVisible( B_Cu ) );
937 ret.set( LAYER_3D_SILKSCREEN_TOP, m_board->IsLayerVisible( F_SilkS ) );
938 ret.set( LAYER_3D_SILKSCREEN_BOTTOM, m_board->IsLayerVisible( B_SilkS ) );
939 ret.set( LAYER_3D_SOLDERMASK_TOP, m_board->IsLayerVisible( F_Mask ) );
940 ret.set( LAYER_3D_SOLDERMASK_BOTTOM, m_board->IsLayerVisible( B_Mask ) );
941 ret.set( LAYER_3D_SOLDERPASTE, m_board->IsLayerVisible( F_Paste ) );
942 ret.set( LAYER_3D_ADHESIVE, m_board->IsLayerVisible( F_Adhes ) );
943 ret.set( LAYER_3D_USER_COMMENTS, m_board->IsLayerVisible( Cmts_User ) );
944 ret.set( LAYER_3D_USER_DRAWINGS, m_board->IsLayerVisible( Dwgs_User ) );
945 ret.set( LAYER_3D_USER_ECO1, m_board->IsLayerVisible( Eco1_User ) );
946 ret.set( LAYER_3D_USER_ECO2, m_board->IsLayerVisible( Eco2_User ) );
947 ret.set( LAYER_3D_F_FAB, m_board->IsLayerVisible( F_Fab ) );
948 ret.set( LAYER_3D_B_FAB, m_board->IsLayerVisible( B_Fab ) );
949 ret.set( LAYER_3D_F_COURTYARD, m_board->IsLayerVisible( F_CrtYd ) );
950 ret.set( LAYER_3D_B_COURTYARD, m_board->IsLayerVisible( B_CrtYd ) );
951
953 ret.set( layer, m_board->IsElementVisible( layer ) );
954 }
955 else if( m_Cfg->m_CurrentPreset == FOLLOW_PLOT_SETTINGS )
956 {
957 if( !m_board )
958 return ret;
959
960 const PCB_PLOT_PARAMS& plotParams = m_board->GetPlotOptions();
961 LSET layers = plotParams.GetLayerSelection();
962
963 for( PCB_LAYER_ID commonLayer : plotParams.GetPlotOnAllLayersSequence() )
964 layers.set( commonLayer );
965
966 ret.set( LAYER_3D_BOARD, true );
967 ret.set( LAYER_3D_COPPER_TOP, layers.test( F_Cu ) );
968 ret.set( LAYER_3D_COPPER_BOTTOM, layers.test( B_Cu ) );
969 ret.set( LAYER_3D_SILKSCREEN_TOP, layers.test( F_SilkS ) );
970 ret.set( LAYER_3D_SILKSCREEN_BOTTOM, layers.test( B_SilkS ) );
971 ret.set( LAYER_3D_SOLDERMASK_TOP, layers.test( F_Mask ) );
972 ret.set( LAYER_3D_SOLDERMASK_BOTTOM, layers.test( B_Mask ) );
973 ret.set( LAYER_3D_SOLDERPASTE, layers.test( F_Paste ) );
974 ret.set( LAYER_3D_ADHESIVE, layers.test( F_Adhes ) );
975 ret.set( LAYER_3D_USER_COMMENTS, layers.test( Cmts_User ) );
976 ret.set( LAYER_3D_USER_DRAWINGS, layers.test( Dwgs_User ) );
977 ret.set( LAYER_3D_USER_ECO1, layers.test( Eco1_User ) );
978 ret.set( LAYER_3D_USER_ECO2, layers.test( Eco2_User ) );
979 ret.set( LAYER_3D_F_FAB, layers.test( F_Fab ) );
980 ret.set( LAYER_3D_B_FAB, layers.test( B_Fab ) );
981 ret.set( LAYER_3D_F_COURTYARD, layers.test( F_CrtYd ) );
982 ret.set( LAYER_3D_B_COURTYARD, layers.test( B_CrtYd ) );
983
984 for( int layer = LAYER_3D_USER_1; layer <= LAYER_3D_USER_45; ++layer )
985 ret.set( layer, layers.test( Map3DLayerToPCBLayer( layer ) ) );
986
987 ret.set( LAYER_FP_REFERENCES, plotParams.GetPlotReference() );
988 ret.set( LAYER_FP_VALUES, plotParams.GetPlotValue() );
989 ret.set( LAYER_FP_TEXT, plotParams.GetPlotFPText() );
990 }
991 else if( LAYER_PRESET_3D* preset = m_Cfg->FindPreset( m_Cfg->m_CurrentPreset ) )
992 {
993 ret = preset->layers;
994 }
995
996 return ret;
997}
998
999
1000std::bitset<LAYER_3D_END> BOARD_ADAPTER::GetDefaultVisibleLayers() const
1001{
1002 std::bitset<LAYER_3D_END> ret;
1003
1004 ret.set( LAYER_3D_BOARD, true );
1005 ret.set( LAYER_3D_PLATED_BARRELS, true );
1006 ret.set( LAYER_3D_COPPER_TOP, true );
1007 ret.set( LAYER_3D_COPPER_BOTTOM, true );
1008 ret.set( LAYER_3D_SILKSCREEN_TOP, true );
1009 ret.set( LAYER_3D_SILKSCREEN_BOTTOM, true );
1010 ret.set( LAYER_3D_SOLDERMASK_TOP, true );
1011 ret.set( LAYER_3D_SOLDERMASK_BOTTOM, true );
1012 ret.set( LAYER_3D_SOLDERPASTE, true );
1013 ret.set( LAYER_3D_ADHESIVE, true );
1014 ret.set( LAYER_3D_USER_COMMENTS, false );
1015 ret.set( LAYER_3D_USER_DRAWINGS, false );
1016 ret.set( LAYER_3D_USER_ECO1, false );
1017 ret.set( LAYER_3D_USER_ECO2, false );
1018 ret.set( LAYER_3D_F_FAB, false );
1019 ret.set( LAYER_3D_B_FAB, false );
1020 ret.set( LAYER_3D_F_COURTYARD, false );
1021 ret.set( LAYER_3D_B_COURTYARD, false );
1022
1023 for( int layer = LAYER_3D_USER_1; layer <= LAYER_3D_USER_45; ++layer )
1024 ret.set( layer, false );
1025
1026 ret.set( LAYER_FP_REFERENCES, true );
1027 ret.set( LAYER_FP_VALUES, true );
1028 ret.set( LAYER_FP_TEXT, true );
1029
1030 ret.set( LAYER_3D_TH_MODELS, true );
1031 ret.set( LAYER_3D_SMD_MODELS, true );
1032 ret.set( LAYER_3D_VIRTUAL_MODELS, true );
1033 ret.set( LAYER_3D_MODELS_NOT_IN_POS, false );
1034 ret.set( LAYER_3D_MODELS_MARKED_DNP, false );
1035
1036 ret.set( LAYER_3D_BOUNDING_BOXES, false );
1037 ret.set( LAYER_3D_OFF_BOARD_SILK, false );
1038 ret.set( LAYER_3D_NAVIGATOR, true );
1039
1040 return ret;
1041}
1042
1043
1045{
1046 return m_Cfg->m_Render.use_board_editor_copper_colors && !m_board->IsFootprintHolder();
1047}
1048
1049
1050bool BOARD_ADAPTER::createBoardPolygon( wxString* aErrorMsg )
1051{
1052 m_board_poly.RemoveAllContours();
1053
1054 if( !m_board )
1055 return false;
1056
1057 bool success;
1058
1059 if( m_board->IsFootprintHolder() )
1060 {
1061 if( !m_board->GetFirstFootprint() )
1062 {
1063 if( aErrorMsg )
1064 *aErrorMsg = _( "No footprint loaded." );
1065
1066 return false;
1067 }
1068
1069 // max dist from one endPt to next startPt
1070 int chainingEpsilon = m_board->GetOutlinesChainingEpsilon();
1071
1073 m_board->GetDesignSettings().m_MaxError,
1074 chainingEpsilon );
1075 m_board_poly.Simplify();
1076
1077 if( !success && aErrorMsg )
1078 {
1079 *aErrorMsg = _( "Footprint outline is missing or malformed. Run Footprint Checker for "
1080 "a full analysis." );
1081 }
1082 }
1083 else
1084 {
1085 success = m_board->GetBoardPolygonOutlines( m_board_poly, true, nullptr, false, true );
1086
1087 if( !success && aErrorMsg )
1088 *aErrorMsg = _( "Board outline is missing or malformed. Run DRC for a full analysis." );
1089 }
1090
1091 return success;
1092}
1093
1094
1095float BOARD_ADAPTER::GetFootprintZPos( bool aIsFlipped ) const
1096{
1097 if( aIsFlipped )
1098 {
1099 if( auto it = m_layerZcoordBottom.find( B_Paste ); it != m_layerZcoordBottom.end() )
1100 return it->second;
1101 }
1102 else
1103 {
1104 if( auto it = m_layerZcoordTop.find( F_Paste ); it != m_layerZcoordTop.end() )
1105 return it->second;
1106 }
1107
1108 return 0.0;
1109}
1110
1111
1112glm::mat4 BOARD_ADAPTER::GetFootprintMatrix( const FOOTPRINT& aFootprint ) const
1113{
1114 const VECTOR2I pos = aFootprint.GetPosition();
1115 glm::mat4 matrix( 1.0f );
1116
1117 matrix = glm::translate( matrix, SFVEC3F( pos.x * BiuTo3dUnits(), -pos.y * BiuTo3dUnits(),
1118 GetFootprintZPos( aFootprint.IsFlipped() ) ) );
1119
1120 if( !aFootprint.GetOrientation().IsZero() )
1121 {
1122 matrix = glm::rotate( matrix, (float) aFootprint.GetOrientation().AsRadians(),
1123 SFVEC3F( 0.0f, 0.0f, 1.0f ) );
1124 }
1125
1126 if( aFootprint.IsFlipped() )
1127 {
1128 matrix = glm::rotate( matrix, glm::pi<float>(), SFVEC3F( 0.0f, 1.0f, 0.0f ) );
1129 matrix = glm::rotate( matrix, glm::pi<float>(), SFVEC3F( 0.0f, 0.0f, 1.0f ) );
1130 }
1131
1132 return glm::scale( matrix, SFVEC3F( BiuTo3dUnits() * pcbIUScale.IU_PER_MM ) );
1133}
1134
1135
1137{
1138 if( aLayerId >= LAYER_3D_USER_1 && aLayerId <= LAYER_3D_USER_45 )
1139 aLayerId = Map3DLayerToPCBLayer( aLayerId );
1140
1141 wxASSERT( aLayerId < PCB_LAYER_ID_COUNT );
1142
1143 return GetColor( m_BoardEditorColors.at( aLayerId ) );
1144}
1145
1146
1148{
1149 return SFVEC4F( aColor.r, aColor.g, aColor.b, aColor.a );
1150}
1151
1152
1154{
1155 SFVEC2F sphericalCoord = SFVEC2F( ( m_Cfg->m_Render.raytrace_lightElevation[i] + 90.0f ) / 180.0f,
1156 m_Cfg->m_Render.raytrace_lightAzimuth[i] / 180.0f );
1157
1158 sphericalCoord.x = glm::clamp( sphericalCoord.x, 0.0f, 1.0f );
1159 sphericalCoord.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f );
1160
1161 return sphericalCoord;
1162}
Defines math related functions.
Defines math related functions.
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
#define SOLDERPASTE_LAYER_THICKNESS
#define ADD_COLOR(list, r, g, b, a, name)
float g_BevelThickness3DU
#define DEFAULT_TECH_LAYER_THICKNESS
#define DEFAULT_BOARD_THICKNESS
#define layerThicknessMargin
static bool g_ColorsLoaded
#define DEFAULT_COPPER_THICKNESS
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
@ BS_ITEM_TYPE_COPPER
@ BS_ITEM_TYPE_SILKSCREEN
@ BS_ITEM_TYPE_DIELECTRIC
@ BS_ITEM_TYPE_SOLDERMASK
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
Define an abstract camera.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
wxString m_ColorTheme
Active color theme name.
BASE_SET & set(size_t pos)
Definition base_set.h:126
std::map< int, COLOR4D > m_BoardEditorColors
list of colors used by the board editor
double BiuTo3dUnits() const noexcept
Board integer units To 3D units.
BVH_CONTAINER_2D * m_offboardPadsBack
SFVEC4F m_BgColorTop
background top color
SFVEC4F m_ECO2Color
void SetVisibleLayers(const std::bitset< LAYER_3D_END > &aLayers)
static std::vector< CUSTOM_COLOR_ITEM > g_PasteColors
float m_solderPasteLayerThickness3DU
SFVEC4F GetLayerColor(int aLayerId) const
Get the technical color of a layer.
std::map< PCB_LAYER_ID, float > m_layerZcoordBottom
Bottom (Start) Z pos of each layer.
void CreateLayers(std::shared_ptr< REPORTER > aStatusReporter, std::stop_token aStop=std::stop_token())
Creates the layers for the board, should be called after InitSettings.
S3D_CACHE * m_3dModelManager
VECTOR2I m_boardPos
Board center position in board internal units.
float m_backCopperThickness3DU
bool GetUseBoardEditorCopperLayerColors() const
static KIGFX::COLOR4D g_DefaultComments
SFVEC4F m_SolderPasteColor
BBOX_3D m_boardBoundingBox
3D bounding box of the board in 3D units.
void createLayers(std::shared_ptr< REPORTER > aStatusReporter, std::stop_token aStop)
static KIGFX::COLOR4D g_DefaultBoardBody
SFVEC4F m_UserDefinedLayerColor[45]
static KIGFX::COLOR4D g_DefaultAdhesive
unsigned int m_viaCount
static KIGFX::COLOR4D g_DefaultFabColor
static KIGFX::COLOR4D g_DefaultSolderMask
std::map< int, COLOR4D > GetLayerColors() const
Build a color list which is used to store colors layers.
static std::vector< CUSTOM_COLOR_ITEM > g_BoardColors
std::optional< std::bitset< LAYER_3D_END > > m_visibilityOverride
static std::vector< CUSTOM_COLOR_ITEM > g_MaskColors
static std::vector< CUSTOM_COLOR_ITEM > g_SilkColors
SHAPE_POLY_SET * m_frontPlatedCopperPolys
BVH_CONTAINER_2D m_TH_ODs
List of PTH outer diameters.
float m_frontMaskThickness3DU
unsigned int m_trackCount
float m_averageTrackWidth
SHAPE_POLY_SET m_board_poly
Board outline polygon.
std::bitset< LAYER_3D_END > GetVisibleLayers() const
SFVEC4F m_SolderMaskColorBot
bool m_IsPreviewer
true if we're in a 3D preview panel, false for the standard 3D viewer
int GetHolePlatingThickness() const noexcept
Get the hole plating thickness (NB: in BOARD UNITS!).
static KIGFX::COLOR4D g_DefaultECOs
SFVEC4F m_SolderMaskColorTop
SFVEC4F GetColor(const COLOR4D &aColor) const
BVH_CONTAINER_2D * m_offboardPadsFront
float m_averageViaHoleDiameter
static KIGFX::COLOR4D g_DefaultBackgroundTop
glm::mat4 GetFootprintMatrix(const FOOTPRINT &aFootprint) const
Build the transform from footprint-local model units to 3D world units.
SFVEC4F m_FFabColor
float m_averageHoleDiameter
static KIGFX::COLOR4D g_DefaultSurfaceFinish
SFVEC4F m_CopperColor
void ReloadColorSettings() noexcept
static std::vector< CUSTOM_COLOR_ITEM > g_FinishColors
SFVEC2F GetSphericalCoord(int i) const
BVH_CONTAINER_2D * m_platedPadsBack
std::bitset< LAYER_3D_END > GetDefaultVisibleLayers() const
SFVEC4F m_BCourtyardColor
void InitSettings(std::shared_ptr< REPORTER > aStatusReporter, std::shared_ptr< REPORTER > aWarningReporter)
Function to be called by the render when it need to reload the settings for the board.
std::map< PCB_LAYER_ID, float > m_layerZcoordTop
Top (End) Z pos of each layer in 3D units.
float GetFootprintZPos(bool aIsFlipped) const
Get the position of the footprint in 3d integer units considering if it is flipped or not.
float m_frontCopperThickness3DU
float m_backMaskThickness3DU
SFVEC4F m_AdhesiveColor
static KIGFX::COLOR4D g_DefaultSolderPaste
float m_boardBodyThickness3DU
VECTOR2I m_boardSize
Board size in board internal units.
SHAPE_POLY_SET * m_backPlatedCopperPolys
void SetLayerColors(const std::map< int, COLOR4D > &aColors)
EDA_3D_VIEWER_SETTINGS * m_Cfg
std::map< int, COLOR4D > m_ColorOverrides
allows to override color scheme colors
SFVEC4F m_SilkScreenColorTop
SFVEC4F m_SilkScreenColorBot
bool IsFootprintShown(const FOOTPRINT *aFootprint) const
Test if footprint should be displayed in relation to attributes and the flags.
unsigned int GetCircleSegmentCount(float aDiameter3DU) const
SFVEC4F m_FCourtyardColor
static KIGFX::COLOR4D g_DefaultCourtyardColor
SFVEC4F m_BFabColor
float m_nonCopperLayerThickness3DU
unsigned int m_holeCount
BVH_CONTAINER_2D m_viaAnnuli
List of via annular rings.
SFVEC4F m_BoardBodyColor
bool createBoardPolygon(wxString *aErrorMsg)
Create the board outline polygon.
unsigned int m_copperLayersCount
std::map< int, COLOR4D > GetDefaultColors() const
BVH_CONTAINER_2D m_TH_IDs
List of PTH inner diameters.
SFVEC4F m_UserCommentsColor
static KIGFX::COLOR4D g_DefaultSilkscreen
BVH_CONTAINER_2D * m_platedPadsFront
SFVEC3F m_boardCenter
3D center position of the board in 3D units.
static KIGFX::COLOR4D g_DefaultBackgroundBot
bool Is3dLayerEnabled(PCB_LAYER_ID aLayer, const std::bitset< LAYER_3D_END > &aVisibilityFlags) const
Check if a layer is enabled.
SFVEC4F m_ECO1Color
SFVEC4F m_UserDrawingsColor
double m_biuTo3Dunits
Scale factor to convert board internal units.
SFVEC4F m_BgColorBot
background bottom color
Container for design settings for a BOARD object.
BOARD_STACKUP & GetStackupDescriptor()
Manage one layer needed to make a physical board.
Manage layers needed to make a physical board.
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
int GetCount() const
wxString m_FinishType
The name of external copper finish.
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:553
constexpr size_type GetWidth() const
Definition box2.h:211
constexpr Vec Centre() const
Definition box2.h:94
constexpr size_type GetHeight() const
Definition box2.h:212
constexpr const SizeVec & GetSize() const
Definition box2.h:203
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetColor(int aLayer, const COLOR4D &aColor)
COLOR4D GetColor(int aLayer) const
bool IsZero() const
Definition eda_angle.h:135
double AsRadians() const
Definition eda_angle.h:119
EDA_ANGLE GetOrientation() const
Definition footprint.h:439
int GetAttributes() const
Definition footprint.h:551
bool IsFlipped() const
Definition footprint.h:662
bool GetDNPForVariant(const wxString &aVariantName) const
Get the DNP status for a specific variant.
bool GetExcludedFromPosFilesForVariant(const wxString &aVariantName) const
Get the exclude-from-position-files status for a specific variant.
VECTOR2I GetPosition() const override
Definition footprint.h:436
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
double r
Red component.
Definition color4d.h:391
double g
Green component.
Definition color4d.h:392
double a
Alpha component.
Definition color4d.h:394
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition color4d.h:293
double b
Blue component.
Definition color4d.h:393
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Parameters and options when plotting/printing a board.
LSEQ GetPlotOnAllLayersSequence() const
LSET GetLayerSelection() const
bool GetPlotReference() const
bool GetPlotValue() const
bool GetPlotFPText() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:123
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely save a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
bool BuildFootprintPolygonOutlines(BOARD *aBoard, SHAPE_POLY_SET &aOutlines, int aErrorMax, int aChainingEpsilon, OUTLINE_ERROR_HANDLER *aErrorHandler)
Extract a board outline for a footprint view.
#define _(s)
#define FOLLOW_PLOT_SETTINGS
#define FOLLOW_PCB
static constexpr EDA_ANGLE FULL_CIRCLE
Definition eda_angle.h:446
FOOTPRINT_ATTR_T
The set of attributes allowed within a FOOTPRINT, using FOOTPRINT::SetAttributes() and FOOTPRINT::Get...
Definition footprint.h:85
@ FP_SMD
Definition footprint.h:87
@ FP_THROUGH_HOLE
Definition footprint.h:86
a few functions useful in geometry calculations.
int GetArcToSegmentCount(int aRadius, int aErrorMax, const EDA_ANGLE &aArcAngle)
static const wxChar * m_logTrace
Trace mask used to enable or disable debug output for this class.
PCB_LAYER_ID Map3DLayerToPCBLayer(int aLayer)
Definition layer_id.cpp:277
int MapPCBLayerTo3DLayer(PCB_LAYER_ID aLayer)
Definition layer_id.cpp:347
@ LAYER_3D_USER_1
Definition layer_ids.h:593
@ LAYER_3D_SOLDERMASK_TOP
Definition layer_ids.h:582
@ LAYER_3D_NAVIGATOR
Definition layer_ids.h:643
@ LAYER_3D_BOUNDING_BOXES
Definition layer_ids.h:644
@ LAYER_3D_ADHESIVE
Definition layer_ids.h:584
@ LAYER_3D_SMD_MODELS
Definition layer_ids.h:639
@ LAYER_3D_BACKGROUND_TOP
Definition layer_ids.h:575
@ LAYER_3D_USER_COMMENTS
Definition layer_ids.h:585
@ LAYER_3D_SOLDERMASK_BOTTOM
Definition layer_ids.h:581
@ LAYER_3D_BOARD
Definition layer_ids.h:576
@ LAYER_3D_PLATED_BARRELS
Definition layer_ids.h:646
@ LAYER_3D_USER_ECO1
Definition layer_ids.h:587
@ LAYER_3D_USER_ECO2
Definition layer_ids.h:588
@ LAYER_3D_TH_MODELS
Definition layer_ids.h:638
@ LAYER_3D_B_FAB
Definition layer_ids.h:590
@ LAYER_3D_SILKSCREEN_TOP
Definition layer_ids.h:580
@ LAYER_3D_B_COURTYARD
Definition layer_ids.h:592
@ LAYER_3D_VIRTUAL_MODELS
Definition layer_ids.h:640
@ LAYER_3D_MODELS_MARKED_DNP
Definition layer_ids.h:642
@ LAYER_3D_COPPER_TOP
Definition layer_ids.h:577
@ LAYER_3D_SOLDERPASTE
Definition layer_ids.h:583
@ LAYER_3D_OFF_BOARD_SILK
Definition layer_ids.h:645
@ LAYER_3D_MODELS_NOT_IN_POS
Definition layer_ids.h:641
@ LAYER_3D_USER_45
Definition layer_ids.h:637
@ LAYER_3D_USER_DRAWINGS
Definition layer_ids.h:586
@ LAYER_3D_COPPER_BOTTOM
Definition layer_ids.h:578
@ LAYER_3D_BACKGROUND_BOTTOM
Definition layer_ids.h:574
@ LAYER_3D_SILKSCREEN_BOTTOM
Definition layer_ids.h:579
@ LAYER_3D_F_COURTYARD
Definition layer_ids.h:591
@ LAYER_3D_F_FAB
Definition layer_ids.h:589
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:703
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition layer_ids.h:224
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ B_Adhes
Definition layer_ids.h:99
@ Dwgs_User
Definition layer_ids.h:103
@ F_Paste
Definition layer_ids.h:100
@ Cmts_User
Definition layer_ids.h:104
@ F_Adhes
Definition layer_ids.h:98
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ Eco1_User
Definition layer_ids.h:105
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ F_Fab
Definition layer_ids.h:115
@ F_SilkS
Definition layer_ids.h:96
@ B_CrtYd
Definition layer_ids.h:111
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ Eco2_User
Definition layer_ids.h:106
@ B_SilkS
Definition layer_ids.h:97
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:167
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
@ RPT_SEVERITY_WARNING
#define DEFAULT_THEME
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
T * GetAppSettings(const char *aFilename)
wxString NotSpecifiedPrm()
Manage a bounding box defined by two SFVEC3F min max points.
Definition bbox_3d.h:39
A class to handle a custom color (predefined color) for the color picker dialog.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
glm::vec2 SFVEC2F
Definition xv3d_types.h:38
glm::vec3 SFVEC3F
Definition xv3d_types.h:40
glm::vec4 SFVEC4F
Definition xv3d_types.h:42