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-2022 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 thickness += item->GetThickness();
378 break;
379
381 if( item->GetBrdLayerId() == F_Cu )
382 m_frontCopperThickness3DU = item->GetThickness() * m_biuTo3Dunits;
383 else if( item->GetBrdLayerId() == B_Cu )
384 m_backCopperThickness3DU = item->GetThickness() * m_biuTo3Dunits;
385 else if( item->IsEnabled() )
386 thickness += item->GetThickness();
387
388 break;
389
390 default:
391 break;
392 }
393 }
394
396 }
397 }
398
399 // Init Z position of each layer
400 // calculate z position for each copper layer
401 // Zstart = -m_epoxyThickness / 2.0 is the z position of the back (bottom layer) (layer id = 31)
402 // Zstart = +m_epoxyThickness / 2.0 is the z position of the front (top layer) (layer id = 0)
403
404 // ____==__________==________==______ <- Bottom = +m_epoxyThickness / 2.0,
405 // | | Top = Bottom + m_copperThickness
406 // |__________________________________|
407 // == == == == <- Bottom = -m_epoxyThickness / 2.0,
408 // Top = Bottom - m_copperThickness
409
410 unsigned int layer;
411
412 for( layer = 0; layer < m_copperLayersCount; ++layer )
413 {
414 // This approximates internal layer positions (because we're treating all the dielectric
415 // layers as having the same thickness). But we don't render them anyway so it doesn't
416 // really matter.
419
420 if( layer < (m_copperLayersCount / 2) )
422 else
424 }
425
426 #define layerThicknessMargin 1.1
427 const float zpos_offset = m_nonCopperLayerThickness3DU * layerThicknessMargin;
428
429 // Fill remaining unused copper layers and back layer zpos with -m_boardBodyThickness / 2.0
430 for( ; layer < MAX_CU_LAYERS; layer++ )
431 {
432 m_layerZcoordBottom[layer] = -( m_boardBodyThickness3DU / 2.0f );
434 }
435
436 // This is the top of the copper layer thickness.
437 const float zpos_copperTop_back = m_layerZcoordTop[B_Cu];
438 const float zpos_copperTop_front = m_layerZcoordTop[F_Cu];
439
440 // calculate z position for each non copper layer
441 // Solder mask and Solder paste have the same Z position
442 for( int layer_id = MAX_CU_LAYERS; layer_id < PCB_LAYER_ID_COUNT; ++layer_id )
443 {
444 float zposTop;
445 float zposBottom;
446
447 switch( layer_id )
448 {
449 case B_Adhes:
450 zposBottom = zpos_copperTop_back - 2.0f * zpos_offset;
451 zposTop = zposBottom - m_nonCopperLayerThickness3DU;
452 break;
453
454 case F_Adhes:
455 zposBottom = zpos_copperTop_front + 2.0f * zpos_offset;
456 zposTop = zposBottom + m_nonCopperLayerThickness3DU;
457 break;
458
459 case B_Mask:
460 zposBottom = zpos_copperTop_back;
461 zposTop = zpos_copperTop_back - m_nonCopperLayerThickness3DU;
462 break;
463
464 case B_Paste:
465 zposBottom = zpos_copperTop_back;
466 zposTop = zpos_copperTop_back - m_solderPasteLayerThickness3DU;
467 break;
468
469 case F_Mask:
470 zposBottom = zpos_copperTop_front;
471 zposTop = zpos_copperTop_front + m_nonCopperLayerThickness3DU;
472 break;
473
474 case F_Paste:
475 zposBottom = zpos_copperTop_front;
476 zposTop = zpos_copperTop_front + m_solderPasteLayerThickness3DU;
477 break;
478
479 case B_SilkS:
480 zposBottom = zpos_copperTop_back - 1.0f * zpos_offset;
481 zposTop = zposBottom - m_nonCopperLayerThickness3DU;
482 break;
483
484 case F_SilkS:
485 zposBottom = zpos_copperTop_front + 1.0f * zpos_offset;
486 zposTop = zposBottom + m_nonCopperLayerThickness3DU;
487 break;
488
489 // !TODO: review
490 default:
491 zposTop = zpos_copperTop_front + (layer_id - MAX_CU_LAYERS + 3.0f) * zpos_offset;
492 zposBottom = zposTop - m_nonCopperLayerThickness3DU;
493 break;
494 }
495
496 m_layerZcoordTop[layer_id] = zposTop;
497 m_layerZcoordBottom[layer_id] = zposBottom;
498 }
499
501
503 0.0f );
504 boardSize /= 2.0f;
505
506 SFVEC3F boardMin = ( m_boardCenter - boardSize );
507 SFVEC3F boardMax = ( m_boardCenter + boardSize );
508
509 boardMin.z = m_layerZcoordTop[B_Adhes];
510 boardMax.z = m_layerZcoordTop[F_Adhes];
511
512 m_boardBoundingBox = BBOX_3D( boardMin, boardMax );
513
514#ifdef PRINT_STATISTICS_3D_VIEWER
515 unsigned stats_startCreateBoardPolyTime = GetRunningMicroSecs();
516#endif
517
518 if( aStatusReporter )
519 aStatusReporter->Report( _( "Create layers" ) );
520
521 createLayers( aStatusReporter );
522
523 COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
524
525 auto to_SFVEC4F =
526 []( const COLOR4D& src )
527 {
528 return SFVEC4F( src.r, src.g, src.b, src.a );
529 };
530
531 m_BgColorTop = to_SFVEC4F( colors->GetColor( LAYER_3D_BACKGROUND_TOP ) );
532 m_BgColorBot = to_SFVEC4F( colors->GetColor( LAYER_3D_BACKGROUND_BOTTOM ) );
533
534 m_SolderPasteColor = to_SFVEC4F( colors->GetColor( LAYER_3D_SOLDERPASTE ) );
535
536 if( m_board && colors->GetUseBoardStackupColors() )
537 {
539
540 auto findColor =
541 []( const wxString& aColorName, const CUSTOM_COLORS_LIST& aColorSet )
542 {
543 if( aColorName.StartsWith( wxT( "#" ) ) )
544 {
545 return KIGFX::COLOR4D( aColorName );
546 }
547 else
548 {
549 for( const CUSTOM_COLOR_ITEM& color : aColorSet )
550 {
551 if( color.m_ColorName == aColorName )
552 return color.m_Color;
553 }
554 }
555
556 return KIGFX::COLOR4D();
557 };
558
563
564 KIGFX::COLOR4D bodyColor( 0, 0, 0, 0 );
565
566 for( const BOARD_STACKUP_ITEM* stackupItem : stackup.GetList() )
567 {
568 wxString colorName = stackupItem->GetColor();
569
570 switch( stackupItem->GetType() )
571 {
573 if( stackupItem->GetBrdLayerId() == F_SilkS )
574 m_SilkScreenColorTop = to_SFVEC4F( findColor( colorName, g_SilkscreenColors ) );
575 else
576 m_SilkScreenColorBot = to_SFVEC4F( findColor( colorName, g_SilkscreenColors ) );
577 break;
578
580 if( stackupItem->GetBrdLayerId() == F_Mask )
581 m_SolderMaskColorTop = to_SFVEC4F( findColor( colorName, g_MaskColors ) );
582 else
583 m_SolderMaskColorBot = to_SFVEC4F( findColor( colorName, g_MaskColors ) );
584
585 break;
586
588 {
589 KIGFX::COLOR4D layerColor = findColor( colorName, g_BoardColors );
590
591 if( bodyColor == COLOR4D( 0, 0, 0, 0 ) )
592 bodyColor = layerColor;
593 else
594 bodyColor = bodyColor.Mix( layerColor, 1.0 - layerColor.a );
595
596 bodyColor.a += ( 1.0 - bodyColor.a ) * layerColor.a / 2;
597 break;
598 }
599
600 default:
601 break;
602 }
603 }
604
605 if( bodyColor != COLOR4D( 0, 0, 0, 0 ) )
606 m_BoardBodyColor = to_SFVEC4F( bodyColor );
607 else
608 m_BoardBodyColor = to_SFVEC4F( g_DefaultBoardBody );
609
610 const wxString& finishName = stackup.m_FinishType;
611
612 if( finishName.EndsWith( wxT( "OSP" ) ) )
613 {
614 m_CopperColor = to_SFVEC4F( findColor( wxT( "Copper" ), g_FinishColors ) );
615 }
616 else if( finishName.EndsWith( wxT( "IG" ) )
617 || finishName.EndsWith( wxT( "gold" ) ) )
618 {
619 m_CopperColor = to_SFVEC4F( findColor( wxT( "Gold" ), g_FinishColors ) );
620 }
621 else if( finishName.StartsWith( wxT( "HAL" ) )
622 || finishName.StartsWith( wxT( "HASL" ) )
623 || finishName.EndsWith( wxT( "tin" ) )
624 || finishName.EndsWith( wxT( "nickel" ) ) )
625 {
626 m_CopperColor = to_SFVEC4F( findColor( wxT( "Tin" ), g_FinishColors ) );
627 }
628 else if( finishName.EndsWith( wxT( "silver" ) ) )
629 {
630 m_CopperColor = to_SFVEC4F( findColor( wxT( "Silver" ), g_FinishColors ) );
631 }
632 else
633 {
635 }
636 }
637 else
638 {
640 m_SilkScreenColorTop = to_SFVEC4F( colors->GetColor( LAYER_3D_SILKSCREEN_TOP ) );
642 m_SolderMaskColorTop = to_SFVEC4F( colors->GetColor( LAYER_3D_SOLDERMASK_TOP ) );
643 m_CopperColor = to_SFVEC4F( colors->GetColor( LAYER_3D_COPPER ) );
644 m_BoardBodyColor = to_SFVEC4F( colors->GetColor( LAYER_3D_BOARD ) );
645 }
646}
647
648
649extern bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines,
650 int aErrorMax, int aChainingEpsilon,
651 OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr );
652
653
654bool BOARD_ADAPTER::createBoardPolygon( wxString* aErrorMsg )
655{
657
658 if( !m_board )
659 return false;
660
661 bool success;
662
664 {
665 if( !m_board->GetFirstFootprint() )
666 {
667 if( aErrorMsg )
668 *aErrorMsg = _( "No footprint loaded." );
669
670 return false;
671 }
672
673 int chainingEpsilon = pcbIUScale.mmToIU( 0.02 ); // max dist from one endPt to next startPt
674
677 chainingEpsilon );
678
679 // Make polygon strictly simple to avoid issues (especially in 3D viewer)
681
682 if( !success && aErrorMsg )
683 {
684 *aErrorMsg = _( "Footprint outline is missing or malformed. Run Footprint Checker for "
685 "a full analysis." );
686 }
687 }
688 else
689 {
691
692 if( !success && aErrorMsg )
693 *aErrorMsg = _( "Board outline is missing or malformed. Run DRC for a full analysis." );
694 }
695
696 return success;
697}
698
699
700float BOARD_ADAPTER::GetFootprintZPos( bool aIsFlipped ) const
701{
702 if( aIsFlipped )
703 {
706 else
708 }
709 else
710 {
713 else
715 }
716}
717
718
720{
721 wxASSERT( aLayerId < PCB_LAYER_ID_COUNT );
722
723 const COLOR4D color = m_colors->GetColor( aLayerId );
724
725 return SFVEC4F( color.r, color.g, color.b, color.a );
726}
727
728
730{
731 return GetColor( m_colors->GetColor( aItemId ) );
732}
733
734
736{
737 return SFVEC4F( aColor.r, aColor.g, aColor.b, aColor.a );
738}
739
740
742{
743 SFVEC2F sphericalCoord =
744 SFVEC2F( ( m_Cfg->m_Render.raytrace_lightElevation[i] + 90.0f ) / 180.0f,
745 m_Cfg->m_Render.raytrace_lightAzimuth[i] / 180.0f );
746
747 sphericalCoord.x = glm::clamp( sphericalCoord.x, 0.0f, 1.0f );
748 sphericalCoord.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f );
749
750 return sphericalCoord;
751}
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:90
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:265
bool IsFootprintHolder() const
Find out if the board is being used to hold a single footprint for editing/viewing.
Definition: board.h:295
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:537
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:397
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:1893
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1177
int GetCopperLayerCount() const
Definition: board.cpp:499
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:517
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:628
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:104
double r
Red component.
Definition: color4d.h:384
double g
Green component.
Definition: color4d.h:385
double a
Alpha component.
Definition: color4d.h:387
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition: color4d.h:305
double b
Blue component.
Definition: color4d.h:386
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:410
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:442
@ LAYER_3D_COPPER
Definition: layer_ids.h:438
@ LAYER_3D_BACKGROUND_TOP
Definition: layer_ids.h:436
@ LAYER_3D_SOLDERMASK_BOTTOM
Definition: layer_ids.h:441
@ LAYER_3D_BOARD
Definition: layer_ids.h:437
@ LAYER_3D_SILKSCREEN_TOP
Definition: layer_ids.h:440
@ LAYER_3D_SOLDERPASTE
Definition: layer_ids.h:443
@ LAYER_3D_BACKGROUND_BOTTOM
Definition: layer_ids.h:435
@ LAYER_3D_SILKSCREEN_BOTTOM
Definition: layer_ids.h:439
#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:618
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46