KiCad PCB EDA Suite
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-2022 Mario Luzeiro <[email protected]>
5 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include "../3d_rendering/camera.h"
26#include "board_adapter.h"
31#include <board.h>
33#include <3d_math.h>
34#include "3d_fastmath.h"
36#include <pgm_base.h>
38#include <wx/log.h>
39#include <advanced_config.h>
40
41
42#define DEFAULT_BOARD_THICKNESS pcbIUScale.mmToIU( 1.6 )
43#define DEFAULT_COPPER_THICKNESS pcbIUScale.mmToIU( 0.035 ) // for 35 um
44// The solder mask layer (and silkscreen) thickness
45#define DEFAULT_TECH_LAYER_THICKNESS pcbIUScale.mmToIU( 0.025 )
46// The solder paste thickness is chosen bigger than the solder mask layer
47// to be sure is covers the mask when overlapping.
48#define SOLDERPASTE_LAYER_THICKNESS pcbIUScale.mmToIU( 0.04 )
49
50
56
64
65// To be used in Raytracing render to create bevels on layer items
67
68static bool g_ColorsLoaded = false;
69
78const wxChar *BOARD_ADAPTER::m_logTrace = wxT( "KI_TRACE_EDA_CINFO3D_VISU" );
79
80
82 m_Cfg( nullptr ),
83 m_IsBoardView( true ),
84 m_MousewheelPanning( true ),
85 m_IsPreviewer( false ),
86 m_board( nullptr ),
87 m_3dModelManager( nullptr ),
88 m_renderSettings( nullptr ),
89 m_colors( nullptr ),
90 m_layerZcoordTop(),
91 m_layerZcoordBottom()
92{
93 wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::BOARD_ADAPTER" ) );
94
95 if( PgmOrNull() )
96 m_colors = Pgm().GetSettingsManager().GetColorSettings();
97
100 m_boardCenter = SFVEC3F( 0.0f );
101
103
107
109
110 m_biuTo3Dunits = 1.0;
116
117 m_trackCount = 0;
118 m_viaCount = 0;
120 m_holeCount = 0;
122 m_averageTrackWidth = 0.0f;
123
124 m_BgColorBot = SFVEC4F( 0.4, 0.4, 0.5, 1.0 );
125 m_BgColorTop = SFVEC4F( 0.8, 0.8, 0.9, 1.0 );
126 m_BoardBodyColor = SFVEC4F( 0.4, 0.4, 0.5, 0.9 );
127 m_SolderMaskColorTop = SFVEC4F( 0.1, 0.2, 0.1, 0.83 );
128 m_SolderMaskColorBot = SFVEC4F( 0.1, 0.2, 0.1, 0.83 );
129 m_SolderPasteColor = SFVEC4F( 0.4, 0.4, 0.4, 1.0 );
130 m_SilkScreenColorTop = SFVEC4F( 0.9, 0.9, 0.9, 1.0 );
131 m_SilkScreenColorBot = SFVEC4F( 0.9, 0.9, 0.9, 1.0 );
132 m_CopperColor = SFVEC4F( 0.75, 0.61, 0.23, 1.0 );
133
134 m_platedPadsFront = nullptr;
135 m_platedPadsBack = nullptr;
136
137 m_frontPlatedPadPolys = nullptr;
138 m_backPlatedPadPolys = nullptr;
139
140 if( !g_ColorsLoaded )
141 {
142#define ADD_COLOR( list, r, g, b, a, name ) \
143 list.emplace_back( r/255.0, g/255.0, b/255.0, a, name )
144
145 ADD_COLOR( g_SilkscreenColors, 245, 245, 245, 1.0, NotSpecifiedPrm() ); // White
146 ADD_COLOR( g_SilkscreenColors, 20, 51, 36, 1.0, wxT( "Green" ) );
147 ADD_COLOR( g_SilkscreenColors, 181, 19, 21, 1.0, wxT( "Red" ) );
148 ADD_COLOR( g_SilkscreenColors, 2, 59, 162, 1.0, wxT( "Blue" ) );
149 ADD_COLOR( g_SilkscreenColors, 11, 11, 11, 1.0, wxT( "Black" ) );
150 ADD_COLOR( g_SilkscreenColors, 245, 245, 245, 1.0, wxT( "White" ) );
151 ADD_COLOR( g_SilkscreenColors, 32, 2, 53, 1.0, wxT( "Purple" ) );
152 ADD_COLOR( g_SilkscreenColors, 194, 195, 0, 1.0, wxT( "Yellow" ) );
153
154 ADD_COLOR( g_MaskColors, 20, 51, 36, 0.83, NotSpecifiedPrm() ); // Green
155 ADD_COLOR( g_MaskColors, 20, 51, 36, 0.83, wxT( "Green" ) );
156 ADD_COLOR( g_MaskColors, 91, 168, 12, 0.83, wxT( "Light Green" ) );
157 ADD_COLOR( g_MaskColors, 13, 104, 11, 0.83, wxT( "Saturated Green" ) );
158 ADD_COLOR( g_MaskColors, 181, 19, 21, 0.83, wxT( "Red" ) );
159 ADD_COLOR( g_MaskColors, 210, 40, 14, 0.83, wxT( "Light Red" ) );
160 ADD_COLOR( g_MaskColors, 239, 53, 41, 0.83, wxT( "Red/Orange" ) );
161 ADD_COLOR( g_MaskColors, 2, 59, 162, 0.83, wxT( "Blue" ) );
162 ADD_COLOR( g_MaskColors, 54, 79, 116, 0.83, wxT( "Light Blue 1" ) );
163 ADD_COLOR( g_MaskColors, 61, 85, 130, 0.83, wxT( "Light Blue 2" ) );
164 ADD_COLOR( g_MaskColors, 21, 70, 80, 0.83, wxT( "Green/Blue" ) );
165 ADD_COLOR( g_MaskColors, 11, 11, 11, 0.83, wxT( "Black" ) );
166 ADD_COLOR( g_MaskColors, 245, 245, 245, 0.83, wxT( "White" ) );
167 ADD_COLOR( g_MaskColors, 32, 2, 53, 0.83, wxT( "Purple" ) );
168 ADD_COLOR( g_MaskColors, 119, 31, 91, 0.83, wxT( "Light Purple" ) );
169 ADD_COLOR( g_MaskColors, 194, 195, 0, 0.83, wxT( "Yellow" ) );
170
171 ADD_COLOR( g_PasteColors, 128, 128, 128, 1.0, wxT( "Grey" ) );
172 ADD_COLOR( g_PasteColors, 90, 90, 90, 1.0, wxT( "Dark Grey" ) );
173 ADD_COLOR( g_PasteColors, 213, 213, 213, 1.0, wxT( "Silver" ) );
174
175 ADD_COLOR( g_FinishColors, 184, 115, 50, 1.0, wxT( "Copper" ) );
176 ADD_COLOR( g_FinishColors, 178, 156, 0, 1.0, wxT( "Gold" ) );
177 ADD_COLOR( g_FinishColors, 213, 213, 213, 1.0, wxT( "Silver" ) );
178 ADD_COLOR( g_FinishColors, 160, 160, 160, 1.0, wxT( "Tin" ) );
179
180 ADD_COLOR( g_BoardColors, 51, 43, 22, 0.83, wxT( "FR4 natural, dark" ) );
181 ADD_COLOR( g_BoardColors, 109, 116, 75, 0.83, wxT( "FR4 natural" ) );
182 ADD_COLOR( g_BoardColors, 252, 252, 250, 0.90, wxT( "PTFE natural" ) );
183 ADD_COLOR( g_BoardColors, 205, 130, 0, 0.68, wxT( "Polyimide" ) );
184 ADD_COLOR( g_BoardColors, 92, 17, 6, 0.90, wxT( "Phenolic natural" ) );
185 ADD_COLOR( g_BoardColors, 146, 99, 47, 0.83, wxT( "Brown 1" ) );
186 ADD_COLOR( g_BoardColors, 160, 123, 54, 0.83, wxT( "Brown 2" ) );
187 ADD_COLOR( g_BoardColors, 146, 99, 47, 0.83, wxT( "Brown 3" ) );
188 ADD_COLOR( g_BoardColors, 213, 213, 213, 1.0, wxT( "Aluminum" ) );
189
190 g_DefaultBackgroundTop = COLOR4D( 0.80, 0.80, 0.90, 1.0 );
191 g_DefaultBackgroundBot = COLOR4D( 0.40, 0.40, 0.50, 1.0 );
192
193 g_DefaultSilkscreen = COLOR4D( 0.94, 0.94, 0.94, 1.0 );
194 g_DefaultSolderMask = COLOR4D( 0.08, 0.20, 0.14, 0.83 );
195 g_DefaultSolderPaste = COLOR4D( 0.50, 0.50, 0.50, 1.0 );
196 g_DefaultSurfaceFinish = COLOR4D( 0.75, 0.61, 0.23, 1.0 );
197 g_DefaultBoardBody = COLOR4D( 0.43, 0.45, 0.30, 0.90 );
198
199 g_ColorsLoaded = true;
200 }
201#undef ADD_COLOR
202}
203
204
206{
208}
209
210
212{
213 wxASSERT( aLayer < PCB_LAYER_ID_COUNT );
214
215 if( m_board && !m_board->IsLayerEnabled( aLayer ) )
216 return false;
217
218 // see if layer needs to be shown
219 // check the flags
220 switch( aLayer )
221 {
222 case B_Adhes:
223 case F_Adhes:
225
226 case B_Paste:
227 case F_Paste:
229
230 case B_SilkS:
231 case F_SilkS:
233
234 case B_Mask:
235 case F_Mask:
237
238 case Dwgs_User:
239 case Cmts_User:
241
242 case Eco1_User:
243 case Eco2_User:
245
246 case Edge_Cuts:
248
249 case Margin:
250 return !m_Cfg->m_Render.realistic;
251
252 case B_Cu:
253 case F_Cu:
254 return !m_board || m_board->IsLayerVisible( aLayer ) || m_Cfg->m_Render.realistic;
255
256 default:
257 // the layer is an internal copper layer, used the visibility
258 return m_board && m_board->IsLayerVisible( aLayer );
259 }
260}
261
262
264{
265 if( m_IsPreviewer ) // In panel Preview, footprints are always shown, of course
266 return true;
267
268 if( aFPAttributes & FP_EXCLUDE_FROM_POS_FILES )
269 {
271 return false;
272 }
273
274 if( aFPAttributes & FP_SMD )
276
277 if( aFPAttributes & FP_THROUGH_HOLE )
279
281}
282
283
285{
288}
289
290
291unsigned int BOARD_ADAPTER::GetCircleSegmentCount( float aDiameter3DU ) const
292{
293 wxASSERT( aDiameter3DU > 0.0f );
294
295 return GetCircleSegmentCount( (int)( aDiameter3DU / m_biuTo3Dunits ) );
296}
297
298
299unsigned int BOARD_ADAPTER::GetCircleSegmentCount( int aDiameterBIU ) const
300{
301 wxASSERT( aDiameterBIU > 0 );
302
303 return GetArcToSegmentCount( aDiameterBIU / 2, ARC_HIGH_DEF, FULL_CIRCLE );
304}
305
306
307void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningReporter )
308{
309 wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::InitSettings" ) );
310
311 if( aStatusReporter )
312 aStatusReporter->Report( _( "Build board outline" ) );
313
314 wxString msg;
315
316 const bool haveOutline = createBoardPolygon( &msg );
317
318 if( aWarningReporter )
319 {
320 if( !haveOutline )
321 aWarningReporter->Report( msg, RPT_SEVERITY_WARNING );
322 else
323 aWarningReporter->Report( wxEmptyString );
324 }
325
326 BOX2I bbbox;
327
328 if( m_board )
329 {
332 && haveOutline );
333 }
334
335 // Gives a non null size to avoid issues in zoom / scale calculations
336 if( ( bbbox.GetWidth() == 0 ) && ( bbbox.GetHeight() == 0 ) )
337 bbbox.Inflate( pcbIUScale.mmToIU( 10 ) );
338
339 m_boardSize = bbbox.GetSize();
340 m_boardPos = bbbox.Centre();
341
342 wxASSERT( (m_boardSize.x > 0) && (m_boardSize.y > 0) );
343
344 m_boardPos.y = -m_boardPos.y; // The y coord is inverted in 3D viewer
345
347
348 // Ensure the board has 2 sides for 3D views, because it is hard to find
349 // a *really* single side board in the true life...
350 if( m_copperLayersCount < 2 )
352
353 // Calculate the conversion to apply to all positions.
355
361
362 g_BevelThickness3DU = pcbIUScale.mmToIU( ADVANCED_CFG::GetCfg().m_3DRT_BevelHeight_um / 1000.0 ) * m_biuTo3Dunits;
363
364 if( m_board )
365 {
367
368 if( bds.GetStackupDescriptor().GetCount() )
369 {
370 int thickness = 0;
371
372 for( BOARD_STACKUP_ITEM* item : bds.GetStackupDescriptor().GetList() )
373 {
374 switch( item->GetType() )
375 {
377 for( int sublayer = 0; sublayer < item->GetSublayersCount(); sublayer++ )
378 thickness += item->GetThickness( sublayer );
379 break;
380
382 if( item->GetBrdLayerId() == F_Cu )
383 m_frontCopperThickness3DU = item->GetThickness() * m_biuTo3Dunits;
384 else if( item->GetBrdLayerId() == B_Cu )
385 m_backCopperThickness3DU = item->GetThickness() * m_biuTo3Dunits;
386 else if( item->IsEnabled() )
387 thickness += item->GetThickness();
388
389 break;
390
391 default:
392 break;
393 }
394 }
395
397 }
398 }
399
400 // Init Z position of each layer
401 // calculate z position for each copper layer
402 // Zstart = -m_epoxyThickness / 2.0 is the z position of the back (bottom layer) (layer id = 31)
403 // Zstart = +m_epoxyThickness / 2.0 is the z position of the front (top layer) (layer id = 0)
404
405 // ____==__________==________==______ <- Bottom = +m_epoxyThickness / 2.0,
406 // | | Top = Bottom + m_copperThickness
407 // |__________________________________|
408 // == == == == <- Bottom = -m_epoxyThickness / 2.0,
409 // Top = Bottom - m_copperThickness
410
411 unsigned int layer;
412
413 for( layer = 0; layer < m_copperLayersCount; ++layer )
414 {
415 // This approximates internal layer positions (because we're treating all the dielectric
416 // layers as having the same thickness). But we don't render them anyway so it doesn't
417 // really matter.
420
421 if( layer < (m_copperLayersCount / 2) )
423 else
425 }
426
427 #define layerThicknessMargin 1.1
428 const float zpos_offset = m_nonCopperLayerThickness3DU * layerThicknessMargin;
429
430 // Fill remaining unused copper layers and back layer zpos with -m_boardBodyThickness / 2.0
431 for( ; layer < MAX_CU_LAYERS; layer++ )
432 {
433 m_layerZcoordBottom[layer] = -( m_boardBodyThickness3DU / 2.0f );
435 }
436
437 // This is the top of the copper layer thickness.
438 const float zpos_copperTop_back = m_layerZcoordTop[B_Cu];
439 const float zpos_copperTop_front = m_layerZcoordTop[F_Cu];
440
441 // calculate z position for each non copper layer
442 // Solder mask and Solder paste have the same Z position
443 for( int layer_id = MAX_CU_LAYERS; layer_id < PCB_LAYER_ID_COUNT; ++layer_id )
444 {
445 float zposTop;
446 float zposBottom;
447
448 switch( layer_id )
449 {
450 case B_Adhes:
451 zposBottom = zpos_copperTop_back - 2.0f * zpos_offset;
452 zposTop = zposBottom - m_nonCopperLayerThickness3DU;
453 break;
454
455 case F_Adhes:
456 zposBottom = zpos_copperTop_front + 2.0f * zpos_offset;
457 zposTop = zposBottom + m_nonCopperLayerThickness3DU;
458 break;
459
460 case B_Mask:
461 zposBottom = zpos_copperTop_back;
462 zposTop = zpos_copperTop_back - m_nonCopperLayerThickness3DU;
463 break;
464
465 case B_Paste:
466 zposBottom = zpos_copperTop_back;
467 zposTop = zpos_copperTop_back - m_solderPasteLayerThickness3DU;
468 break;
469
470 case F_Mask:
471 zposBottom = zpos_copperTop_front;
472 zposTop = zpos_copperTop_front + m_nonCopperLayerThickness3DU;
473 break;
474
475 case F_Paste:
476 zposBottom = zpos_copperTop_front;
477 zposTop = zpos_copperTop_front + m_solderPasteLayerThickness3DU;
478 break;
479
480 case B_SilkS:
481 zposBottom = zpos_copperTop_back - 1.0f * zpos_offset;
482 zposTop = zposBottom - m_nonCopperLayerThickness3DU;
483 break;
484
485 case F_SilkS:
486 zposBottom = zpos_copperTop_front + 1.0f * zpos_offset;
487 zposTop = zposBottom + m_nonCopperLayerThickness3DU;
488 break;
489
490 // !TODO: review
491 default:
492 zposTop = zpos_copperTop_front + (layer_id - MAX_CU_LAYERS + 3.0f) * zpos_offset;
493 zposBottom = zposTop - m_nonCopperLayerThickness3DU;
494 break;
495 }
496
497 m_layerZcoordTop[layer_id] = zposTop;
498 m_layerZcoordBottom[layer_id] = zposBottom;
499 }
500
502
504 0.0f );
505 boardSize /= 2.0f;
506
507 SFVEC3F boardMin = ( m_boardCenter - boardSize );
508 SFVEC3F boardMax = ( m_boardCenter + boardSize );
509
510 boardMin.z = m_layerZcoordTop[B_Adhes];
511 boardMax.z = m_layerZcoordTop[F_Adhes];
512
513 m_boardBoundingBox = BBOX_3D( boardMin, boardMax );
514
515#ifdef PRINT_STATISTICS_3D_VIEWER
516 unsigned stats_startCreateBoardPolyTime = GetRunningMicroSecs();
517#endif
518
519 if( aStatusReporter )
520 aStatusReporter->Report( _( "Create layers" ) );
521
522 createLayers( aStatusReporter );
523
524 COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
525
526 auto to_SFVEC4F =
527 []( const COLOR4D& src )
528 {
529 return SFVEC4F( src.r, src.g, src.b, src.a );
530 };
531
532 m_BgColorTop = to_SFVEC4F( colors->GetColor( LAYER_3D_BACKGROUND_TOP ) );
533 m_BgColorBot = to_SFVEC4F( colors->GetColor( LAYER_3D_BACKGROUND_BOTTOM ) );
534
535 m_SolderPasteColor = to_SFVEC4F( colors->GetColor( LAYER_3D_SOLDERPASTE ) );
536
537 if( m_board && colors->GetUseBoardStackupColors() )
538 {
540
541 auto findColor =
542 []( const wxString& aColorName, const CUSTOM_COLORS_LIST& aColorSet )
543 {
544 if( aColorName.StartsWith( wxT( "#" ) ) )
545 {
546 return KIGFX::COLOR4D( aColorName );
547 }
548 else
549 {
550 for( const CUSTOM_COLOR_ITEM& color : aColorSet )
551 {
552 if( color.m_ColorName == aColorName )
553 return color.m_Color;
554 }
555 }
556
557 return KIGFX::COLOR4D();
558 };
559
564
565 KIGFX::COLOR4D bodyColor( 0, 0, 0, 0 );
566
567 for( const BOARD_STACKUP_ITEM* stackupItem : stackup.GetList() )
568 {
569 wxString colorName = stackupItem->GetColor();
570
571 switch( stackupItem->GetType() )
572 {
574 if( stackupItem->GetBrdLayerId() == F_SilkS )
575 m_SilkScreenColorTop = to_SFVEC4F( findColor( colorName, g_SilkscreenColors ) );
576 else
577 m_SilkScreenColorBot = to_SFVEC4F( findColor( colorName, g_SilkscreenColors ) );
578 break;
579
581 if( stackupItem->GetBrdLayerId() == F_Mask )
582 m_SolderMaskColorTop = to_SFVEC4F( findColor( colorName, g_MaskColors ) );
583 else
584 m_SolderMaskColorBot = to_SFVEC4F( findColor( colorName, g_MaskColors ) );
585
586 break;
587
589 {
590 KIGFX::COLOR4D layerColor = findColor( colorName, g_BoardColors );
591
592 if( bodyColor == COLOR4D( 0, 0, 0, 0 ) )
593 bodyColor = layerColor;
594 else
595 bodyColor = bodyColor.Mix( layerColor, 1.0 - layerColor.a );
596
597 bodyColor.a += ( 1.0 - bodyColor.a ) * layerColor.a / 2;
598 break;
599 }
600
601 default:
602 break;
603 }
604 }
605
606 if( bodyColor != COLOR4D( 0, 0, 0, 0 ) )
607 m_BoardBodyColor = to_SFVEC4F( bodyColor );
608 else
609 m_BoardBodyColor = to_SFVEC4F( g_DefaultBoardBody );
610
611 const wxString& finishName = stackup.m_FinishType;
612
613 if( finishName.EndsWith( wxT( "OSP" ) ) )
614 {
615 m_CopperColor = to_SFVEC4F( findColor( wxT( "Copper" ), g_FinishColors ) );
616 }
617 else if( finishName.EndsWith( wxT( "IG" ) )
618 || finishName.EndsWith( wxT( "gold" ) ) )
619 {
620 m_CopperColor = to_SFVEC4F( findColor( wxT( "Gold" ), g_FinishColors ) );
621 }
622 else if( finishName.StartsWith( wxT( "HAL" ) )
623 || finishName.StartsWith( wxT( "HASL" ) )
624 || finishName.EndsWith( wxT( "tin" ) )
625 || finishName.EndsWith( wxT( "nickel" ) ) )
626 {
627 m_CopperColor = to_SFVEC4F( findColor( wxT( "Tin" ), g_FinishColors ) );
628 }
629 else if( finishName.EndsWith( wxT( "silver" ) ) )
630 {
631 m_CopperColor = to_SFVEC4F( findColor( wxT( "Silver" ), g_FinishColors ) );
632 }
633 else
634 {
636 }
637 }
638 else
639 {
641 m_SilkScreenColorTop = to_SFVEC4F( colors->GetColor( LAYER_3D_SILKSCREEN_TOP ) );
643 m_SolderMaskColorTop = to_SFVEC4F( colors->GetColor( LAYER_3D_SOLDERMASK_TOP ) );
644 m_CopperColor = to_SFVEC4F( colors->GetColor( LAYER_3D_COPPER ) );
645 m_BoardBodyColor = to_SFVEC4F( colors->GetColor( LAYER_3D_BOARD ) );
646 }
647}
648
649
650extern bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines,
651 int aErrorMax, int aChainingEpsilon,
652 OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr );
653
654
655bool BOARD_ADAPTER::createBoardPolygon( wxString* aErrorMsg )
656{
658
659 if( !m_board )
660 return false;
661
662 bool success;
663
665 {
666 if( !m_board->GetFirstFootprint() )
667 {
668 if( aErrorMsg )
669 *aErrorMsg = _( "No footprint loaded." );
670
671 return false;
672 }
673
674 // max dist from one endPt to next startPt
675 int chainingEpsilon = m_board->GetOutlinesChainingEpsilon();
676
679 chainingEpsilon );
680
681 // Make polygon strictly simple to avoid issues (especially in 3D viewer)
683
684 if( !success && aErrorMsg )
685 {
686 *aErrorMsg = _( "Footprint outline is missing or malformed. Run Footprint Checker for "
687 "a full analysis." );
688 }
689 }
690 else
691 {
693
694 if( !success && aErrorMsg )
695 *aErrorMsg = _( "Board outline is missing or malformed. Run DRC for a full analysis." );
696 }
697
698 return success;
699}
700
701
702float BOARD_ADAPTER::GetFootprintZPos( bool aIsFlipped ) const
703{
704 if( aIsFlipped )
705 {
708 else
710 }
711 else
712 {
715 else
717 }
718}
719
720
722{
723 wxASSERT( aLayerId < PCB_LAYER_ID_COUNT );
724
725 const COLOR4D color = m_colors->GetColor( aLayerId );
726
727 return SFVEC4F( color.r, color.g, color.b, color.a );
728}
729
730
732{
733 return GetColor( m_colors->GetColor( aItemId ) );
734}
735
736
738{
739 return SFVEC4F( aColor.r, aColor.g, aColor.b, aColor.a );
740}
741
742
744{
745 SFVEC2F sphericalCoord =
746 SFVEC2F( ( m_Cfg->m_Render.raytrace_lightElevation[i] + 90.0f ) / 180.0f,
747 m_Cfg->m_Render.raytrace_lightAzimuth[i] / 180.0f );
748
749 sphericalCoord.x = glm::clamp( sphericalCoord.x, 0.0f, 1.0f );
750 sphericalCoord.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f );
751
752 return sphericalCoord;
753}
Defines math related functions.
Defines math related functions.
int color
Definition: DXF_plotter.cpp:57
constexpr int ARC_HIGH_DEF
Definition: base_units.h:121
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
#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
bool BuildFootprintPolygonOutlines(BOARD *aBoard, SHAPE_POLY_SET &aOutlines, int aErrorMax, int aChainingEpsilon, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr)
This function is used to extract a board outline for a footprint view.
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
Definition: board_adapter.h:62
@ BS_ITEM_TYPE_COPPER
Definition: board_stackup.h:43
@ BS_ITEM_TYPE_SILKSCREEN
Definition: board_stackup.h:49
@ BS_ITEM_TYPE_DIELECTRIC
Definition: board_stackup.h:44
@ BS_ITEM_TYPE_SOLDERMASK
Definition: board_stackup.h:47
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
SFVEC4F m_BgColorTop
background top color
float m_solderPasteLayerThickness3DU
void createLayers(REPORTER *aStatusReporter)
VECTOR2I m_boardPos
Board center position in board internal units.
float m_backCopperThickness3DU
SFVEC4F m_SolderPasteColor
in realistic mode: solder paste color
static CUSTOM_COLORS_LIST g_PasteColors
BBOX_3D m_boardBoundingBox
3D bounding box of the board in 3D units.
static CUSTOM_COLORS_LIST g_FinishColors
static KIGFX::COLOR4D g_DefaultBoardBody
unsigned int m_viaCount
COLOR_SETTINGS * m_colors
bool IsFootprintShown(FOOTPRINT_ATTR_T aFPAttributes) const
Test if footprint should be displayed in relation to attributes and the flags.
static KIGFX::COLOR4D g_DefaultSolderMask
BVH_CONTAINER_2D m_throughHoleOds
List of PTH outer diameters.
std::array< float, PCB_LAYER_ID_COUNT > m_layerZcoordBottom
Bottom (Start) Z position of each layer in 3D units.
static CUSTOM_COLORS_LIST g_SilkscreenColors
BVH_CONTAINER_2D m_throughHoleIds
List of PTH inner diameters.
unsigned int m_trackCount
float m_averageTrackWidth
SHAPE_POLY_SET m_board_poly
Board outline polygon.
SFVEC4F m_SolderMaskColorBot
in realistic mode: solder mask color ( bot )
BVH_CONTAINER_2D m_throughHoleAnnularRings
List of via annular rings.
bool m_IsPreviewer
true if the board adaptater is living in a 3D preview panel, false for the standard 3D viewer
static CUSTOM_COLORS_LIST g_MaskColors
int GetHolePlatingThickness() const noexcept
Get the hole plating thickness (NB: in BOARD UNITS!).
void InitSettings(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
Function to be called by the render when it need to reload the settings for the board.
SFVEC4F m_SolderMaskColorTop
in realistic mode: solder mask color ( top )
SFVEC4F GetColor(const COLOR4D &aColor) const
float m_averageViaHoleDiameter
static KIGFX::COLOR4D g_DefaultBackgroundTop
float m_averageHoleDiameter
static KIGFX::COLOR4D g_DefaultSurfaceFinish
SFVEC4F m_CopperColor
in realistic mode: copper color
SFVEC2F GetSphericalCoord(int i) const
BVH_CONTAINER_2D * m_platedPadsBack
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
static KIGFX::COLOR4D g_DefaultSolderPaste
float m_boardBodyThickness3DU
std::array< float, PCB_LAYER_ID_COUNT > m_layerZcoordTop
Top (End) Z position of each layer in 3D units.
static CUSTOM_COLORS_LIST g_BoardColors
VECTOR2I m_boardSize
Board size in board internal units.
SHAPE_POLY_SET * m_backPlatedPadPolys
EDA_3D_VIEWER_SETTINGS * m_Cfg
SFVEC4F m_SilkScreenColorTop
in realistic mode: SilkScreen color ( top )
SFVEC4F m_SilkScreenColorBot
in realistic mode: SilkScreen color ( bot )
SFVEC4F GetItemColor(int aItemId) const
Get the technical color of a layer.
unsigned int GetCircleSegmentCount(float aDiameter3DU) const
float m_nonCopperLayerThickness3DU
unsigned int m_holeCount
bool Is3dLayerEnabled(PCB_LAYER_ID aLayer) const
Check if a layer is enabled.
SFVEC4F m_BoardBodyColor
in realistic mode: FR4 board color
bool createBoardPolygon(wxString *aErrorMsg)
Create the board outline polygon.
unsigned int m_copperLayersCount
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
SFVEC4F GetLayerColor(PCB_LAYER_ID aLayerId) const
Get the technical color of a layer.
double m_biuTo3Dunits
Scale factor to convert board internal units to 3D units normalized between -1.0 and 1....
SFVEC4F m_BgColorBot
background bottom color
SHAPE_POLY_SET * m_frontPlatedPadPolys
Container for design settings for a BOARD object.
int GetHolePlatingThickness() const
Pad & via drills are finish size.
BOARD_STACKUP & GetStackupDescriptor()
Manage one layer needed to make a physical board.
Definition: board_stackup.h:91
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.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:269
bool IsFootprintHolder() const
Find out if the board is being used to hold a single footprint for editing/viewing.
Definition: board.h:299
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:613
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:403
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:1972
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1253
int GetCopperLayerCount() const
Definition: board.cpp:563
int GetOutlinesChainingEpsilon()
Definition: board.h:668
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:593
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:704
coord_type GetHeight() const
Definition: box2.h:188
coord_type GetWidth() const
Definition: box2.h:187
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
Vec Centre() const
Definition: box2.h:70
const Vec & GetSize() const
Definition: box2.h:179
void Clear() override
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
bool GetUseBoardStackupColors() const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:102
double r
Red component.
Definition: color4d.h:372
double g
Green component.
Definition: color4d.h:373
double a
Alpha component.
Definition: color4d.h:375
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:374
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
Represent a set of closed polygons.
void Simplify(POLYGON_MODE aFastMode)
const std::function< void(const wxString &msg, BOARD_ITEM *itemA, BOARD_ITEM *itemB, const VECTOR2I &pt)> OUTLINE_ERROR_HANDLER
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: cvpcb.cpp:125
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
#define _(s)
static constexpr EDA_ANGLE & FULL_CIRCLE
Definition: eda_angle.h:427
FOOTPRINT_ATTR_T
The set of attributes allowed within a FOOTPRINT, using FOOTPRINT::SetAttributes() and FOOTPRINT::Get...
Definition: footprint.h:67
@ FP_SMD
Definition: footprint.h:69
@ FP_EXCLUDE_FROM_POS_FILES
Definition: footprint.h:70
@ FP_THROUGH_HOLE
Definition: footprint.h:68
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.
@ LAYER_3D_SOLDERMASK_TOP
Definition: layer_ids.h:444
@ LAYER_3D_COPPER
Definition: layer_ids.h:440
@ LAYER_3D_BACKGROUND_TOP
Definition: layer_ids.h:438
@ LAYER_3D_SOLDERMASK_BOTTOM
Definition: layer_ids.h:443
@ LAYER_3D_BOARD
Definition: layer_ids.h:439
@ LAYER_3D_SILKSCREEN_TOP
Definition: layer_ids.h:442
@ LAYER_3D_SOLDERPASTE
Definition: layer_ids.h:445
@ LAYER_3D_BACKGROUND_BOTTOM
Definition: layer_ids.h:437
@ LAYER_3D_SILKSCREEN_BOTTOM
Definition: layer_ids.h:441
#define MAX_CU_LAYERS
Definition: layer_ids.h:140
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ B_Adhes
Definition: layer_ids.h:97
@ Edge_Cuts
Definition: layer_ids.h:113
@ Dwgs_User
Definition: layer_ids.h:109
@ F_Paste
Definition: layer_ids.h:101
@ Cmts_User
Definition: layer_ids.h:110
@ F_Adhes
Definition: layer_ids.h:98
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ Eco1_User
Definition: layer_ids.h:111
@ F_Mask
Definition: layer_ids.h:107
@ B_Paste
Definition: layer_ids.h:100
@ Margin
Definition: layer_ids.h:114
@ F_SilkS
Definition: layer_ids.h:104
@ Eco2_User
Definition: layer_ids.h:112
@ B_SilkS
Definition: layer_ids.h:103
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:137
@ F_Cu
Definition: layer_ids.h:64
see class PGM_BASE
unsigned GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
@ RPT_SEVERITY_WARNING
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
wxString NotSpecifiedPrm()
Manage a bounding box defined by two SFVEC3F min max points.
Definition: bbox_3d.h:42
void Reset()
Reset the bounding box to zero and de-initialize it.
Definition: bbox_3d.cpp:95
A class to handle a custom color (predefined color) for the color picker dialog.
constexpr int mmToIU(double mm) const
Definition: base_units.h:89
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46