KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_adapter.h
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-2016 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#ifndef BOARD_ADAPTER_H
26#define BOARD_ADAPTER_H
27
28#include <array>
29#include <vector>
30#include "../3d_rendering/raytracing/accelerators/container_2d.h"
31#include "../3d_rendering/raytracing/accelerators/container_3d.h"
32#include "../3d_rendering/raytracing/shapes3D/bbox_3d.h"
33#include "../3d_rendering/camera.h"
34#include "../3d_enums.h"
35#include "../3d_cache/3d_cache.h"
36#include "../common_ogl/ogl_attr_list.h"
37#include "../3d_viewer/eda_3d_viewer_settings.h"
38
39#include <layer_ids.h>
40#include <pad.h>
41#include <pcb_track.h>
42#include <pcb_base_frame.h>
43#include <pcb_text.h>
44#include <pcb_shape.h>
45#include <pcb_dimension.h>
46#include <zone.h>
47#include <footprint.h>
48#include <reporter.h>
50
51class COLOR_SETTINGS;
52
54typedef std::map<PCB_LAYER_ID, BVH_CONTAINER_2D*> MAP_CONTAINER_2D_BASE;
55
57typedef std::map<PCB_LAYER_ID, SHAPE_POLY_SET*> MAP_POLY;
58
62#define RANGE_SCALE_3D 8.0f
63
64
69{
70public:
72
74
80 void Set3dCacheManager( S3D_CACHE* aCacheMgr ) noexcept { m_3dModelManager = aCacheMgr; }
81 S3D_CACHE* Get3dCacheManager() const noexcept { return m_3dModelManager; }
82
88 bool Is3dLayerEnabled( PCB_LAYER_ID aLayer ) const;
89
93 bool IsFootprintShown( FOOTPRINT_ATTR_T aFPAttributes ) const;
94
100 void SetBoard( BOARD* aBoard ) noexcept { m_board = aBoard; }
101 const BOARD* GetBoard() const noexcept { return m_board; }
102
103 void ReloadColorSettings() noexcept;
104
111 void InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
112
118 double BiuTo3dUnits() const noexcept { return m_biuTo3Dunits; }
119
125 const BBOX_3D& GetBBox() const noexcept { return m_boardBoundingBox; }
126
130 float GetBoardBodyThickness() const noexcept { return m_boardBodyThickness3DU; }
131
136
140 float GetFrontCopperThickness() const noexcept { return m_frontCopperThickness3DU; }
141 float GetBackCopperThickness() const noexcept { return m_backCopperThickness3DU; }
142
146 int GetHolePlatingThickness() const noexcept;
147
153 VECTOR2I GetBoardSize() const noexcept { return m_boardSize; }
154
160 VECTOR2I GetBoardPos() const noexcept { return m_boardPos; }
161
167 const SFVEC3F& GetBoardCenter() const noexcept { return m_boardCenter; }
168
176 float GetFootprintZPos( bool aIsFlipped ) const ;
177
183 const SHAPE_POLY_SET& GetBoardPoly() const noexcept { return m_board_poly; }
184
191 SFVEC4F GetLayerColor( PCB_LAYER_ID aLayerId ) const;
192
199 SFVEC4F GetItemColor( int aItemId ) const;
200
205 SFVEC4F GetColor( const COLOR4D& aColor ) const;
206
207 SFVEC2F GetSphericalCoord( int i ) const;
208
215 float GetLayerTopZPos( PCB_LAYER_ID aLayerId ) const noexcept
216 {
217 return m_layerZcoordTop[aLayerId];
218 }
219
226 float GetLayerBottomZPos( PCB_LAYER_ID aLayerId ) const noexcept
227 {
228 return m_layerZcoordBottom[aLayerId];
229 }
230
236 const MAP_CONTAINER_2D_BASE& GetLayerMap() const noexcept { return m_layerMap; }
237 const BVH_CONTAINER_2D* GetPlatedPadsFront() const noexcept { return m_platedPadsFront; }
238 const BVH_CONTAINER_2D* GetPlatedPadsBack() const noexcept { return m_platedPadsBack; }
239
240 const MAP_CONTAINER_2D_BASE& GetLayerHoleMap() const noexcept { return m_layerHoleMap; }
241 const BVH_CONTAINER_2D& GetThroughHoleIds() const noexcept { return m_throughHoleIds; }
242 const BVH_CONTAINER_2D& GetThroughHoleOds() const noexcept { return m_throughHoleOds; }
243
251 const SHAPE_POLY_SET& GetThroughHoleOdPolys() const noexcept
252 {
254 }
255
257 {
259 }
260
262 {
264 }
265
267 {
269 }
270
275 {
276 return m_throughHoleViaOds;
277 }
278
280 {
282 }
283
284 unsigned int GetViaCount() const noexcept { return m_viaCount; }
285 unsigned int GetHoleCount() const noexcept { return m_holeCount; }
286
290 float GetAverageViaHoleDiameter() const noexcept { return m_averageViaHoleDiameter; }
291
295 float GetAverageHoleDiameter() const noexcept { return m_averageHoleDiameter; }
296
300 float GetAverageTrackWidth() const noexcept { return m_averageTrackWidth; }
301
306 unsigned int GetCircleSegmentCount( float aDiameter3DU ) const;
307
312 unsigned int GetCircleSegmentCount( int aDiameterBIU ) const;
313
319 const MAP_POLY& GetPolyMap() const noexcept { return m_layers_poly; }
320
323 const MAP_POLY& GetHoleIdPolysMap() const noexcept { return m_layerHoleIdPolys; }
324 const MAP_POLY& GetHoleOdPolysMap() const noexcept { return m_layerHoleOdPolys; }
325
326private:
332 bool createBoardPolygon( wxString* aErrorMsg );
333 void createLayers( REPORTER* aStatusReporter );
334 void destroyLayers();
335
336 // Helper functions to create the board
337 void createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer );
338
339 void createPadWithMargin( const PAD *aPad, CONTAINER_2D_BASE* aDstContainer,
340 PCB_LAYER_ID aLayer, const VECTOR2I& aMargin ) const;
341
342 OBJECT_2D* createPadWithDrill( const PAD* aPad, int aInflateValue );
343
344 void addPads( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aDstContainer,
345 PCB_LAYER_ID aLayerId, bool aSkipPlatedPads, bool aSkipNonPlatedPads );
346
347 void addFootprintShapes( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aDstContainer,
348 PCB_LAYER_ID aLayerId );
349
350 void addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aDstContainer,
351 const BOARD_ITEM* aOwner );
352
353 void addShape( const PCB_SHAPE* aShape, CONTAINER_2D_BASE* aContainer,
354 const BOARD_ITEM* aOwner );
355
356 void addShape( const PCB_DIMENSION_BASE* aDimension, CONTAINER_2D_BASE* aDstContainer,
357 const BOARD_ITEM* aOwner );
358
359 void addSolidAreasShapes( const ZONE* aZone, CONTAINER_2D_BASE* aDstContainer,
360 PCB_LAYER_ID aLayerId );
361
362 void transformArcToSegments( const VECTOR2I& aCentre, const VECTOR2I& aStart,
363 const EDA_ANGLE& aArcAngle, int aCircleToSegmentsCount, int aWidth,
364 CONTAINER_2D_BASE* aDstContainer, const BOARD_ITEM& aOwner );
365
366 void buildPadOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, int aWidth );
367
368 // Helper functions to create poly contours
369 void buildPadOutlineAsPolygon( const PAD* aPad, SHAPE_POLY_SET& aBuffer, int aWidth) const;
370
371 void transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer,
372 SHAPE_POLY_SET& aBuffer ) const;
373
374public:
380
388
389public:
391
396
406
407private:
412
417
420
423
426
431
433
436
439
445
447
450
451 std::array<float, PCB_LAYER_ID_COUNT> m_layerZcoordTop;
453
454 std::array<float, PCB_LAYER_ID_COUNT> m_layerZcoordBottom;
456
462
463 unsigned int m_trackCount;
465 unsigned int m_viaCount;
467 unsigned int m_holeCount;
469
475 static const wxChar* m_logTrace;
476
477};
478
479
481{
482public:
483 virtual BOARD_ADAPTER& GetAdapter() = 0;
484 virtual CAMERA& GetCurrentCamera() = 0;
485
487};
488
489#endif // BOARD_ADAPTER_H
std::map< PCB_LAYER_ID, SHAPE_POLY_SET * > MAP_POLY
A type that stores polysets for each layer id.
Definition: board_adapter.h:57
std::map< PCB_LAYER_ID, BVH_CONTAINER_2D * > MAP_CONTAINER_2D_BASE
A type that stores a container of 2d objects for each layer id.
Definition: board_adapter.h:54
Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:69
const BVH_CONTAINER_2D & GetThroughHoleViaOds() const noexcept
MAP_CONTAINER_2D_BASE m_layerHoleMap
Holes for each layer.
double BiuTo3dUnits() const noexcept
Board integer units To 3D units.
SFVEC4F m_BgColorTop
background top color
float m_solderPasteLayerThickness3DU
const MAP_CONTAINER_2D_BASE & GetLayerHoleMap() const noexcept
void buildPadOutlineAsPolygon(const PAD *aPad, SHAPE_POLY_SET &aBuffer, int aWidth) const
S3D_CACHE * m_3dModelManager
void createLayers(REPORTER *aStatusReporter)
void addFootprintShapes(const FOOTPRINT *aFootprint, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId)
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
const SHAPE_POLY_SET & GetBoardPoly() const noexcept
Get the current polygon of the epoxy board.
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
const SHAPE_POLY_SET & GetThroughHoleOdPolys() const noexcept
Get through hole outside diameter 2D polygons.
const MAP_POLY & GetPolyMap() const noexcept
Get map of polygon's layers.
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.
MAP_POLY m_layerHoleOdPolys
Hole outer diameters (per layer)
static CUSTOM_COLORS_LIST g_SilkscreenColors
void addSolidAreasShapes(const ZONE *aZone, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId)
BVH_CONTAINER_2D m_throughHoleIds
List of PTH inner diameters.
VECTOR2I GetBoardSize() const noexcept
Get the board size.
const MAP_POLY & GetHoleOdPolysMap() const noexcept
MAP_CONTAINER_2D_BASE m_layerMap
2D elements for each layer.
float GetAverageTrackWidth() const noexcept
unsigned int m_trackCount
const BBOX_3D & GetBBox() const noexcept
Get the board outling bounding box.
float m_averageTrackWidth
SHAPE_POLY_SET m_board_poly
Board outline polygon.
BVH_CONTAINER_2D m_throughHoleViaIds
List of via hole inner diameters.
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
const BVH_CONTAINER_2D & GetThroughHoleIds() const noexcept
VECTOR2I GetBoardPos() const noexcept
Get the board center.
static CUSTOM_COLORS_LIST g_MaskColors
MAP_POLY m_layerHoleIdPolys
Hole inner diameters (per layer)
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.
float GetLayerBottomZPos(PCB_LAYER_ID aLayerId) const noexcept
Get the bottom z position.
SFVEC4F m_SolderMaskColorTop
in realistic mode: solder mask color ( top )
SFVEC4F GetColor(const COLOR4D &aColor) const
SHAPE_POLY_SET m_throughHoleOdPolys
PTH outer diameters.
float m_averageViaHoleDiameter
SHAPE_POLY_SET m_throughHoleViaOdPolys
Via hole outer diameters.
static KIGFX::COLOR4D g_DefaultBackgroundTop
const BVH_CONTAINER_2D * GetPlatedPadsBack() const noexcept
const MAP_POLY & GetHoleIdPolysMap() const noexcept
float GetBackCopperThickness() const noexcept
BVH_CONTAINER_2D m_throughHoleViaOds
List of via hole outer diameters.
float m_averageHoleDiameter
static KIGFX::COLOR4D g_DefaultSurfaceFinish
SFVEC4F m_CopperColor
in realistic mode: copper color
void ReloadColorSettings() noexcept
void createPadWithMargin(const PAD *aPad, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayer, const VECTOR2I &aMargin) const
float GetAverageViaHoleDiameter() const noexcept
void addPads(const FOOTPRINT *aFootprint, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId, bool aSkipPlatedPads, bool aSkipNonPlatedPads)
const SHAPE_POLY_SET * GetFrontPlatedPadPolys()
SFVEC2F GetSphericalCoord(int i) const
unsigned int GetViaCount() const noexcept
const BOARD * GetBoard() const noexcept
BVH_CONTAINER_2D * m_platedPadsBack
void SetBoard(BOARD *aBoard) noexcept
Set current board to be rendered.
const SFVEC3F & GetBoardCenter() const noexcept
The board center position 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
SHAPE_POLY_SET m_throughHoleAnnularRingPolys
Via annular ring outer diameters.
float GetNonCopperLayerThickness() const noexcept
Get the non copper layers thickness (in 3D units).
static KIGFX::COLOR4D g_DefaultSolderPaste
float GetLayerTopZPos(PCB_LAYER_ID aLayerId) const noexcept
Get the top z position.
const SHAPE_POLY_SET & GetOuterNonPlatedThroughHolePoly() const noexcept
void transformArcToSegments(const VECTOR2I &aCentre, const VECTOR2I &aStart, const EDA_ANGLE &aArcAngle, int aCircleToSegmentsCount, int aWidth, CONTAINER_2D_BASE *aDstContainer, const BOARD_ITEM &aOwner)
float m_boardBodyThickness3DU
void buildPadOutlineAsSegments(const PAD *aPad, CONTAINER_2D_BASE *aDstContainer, int aWidth)
const SHAPE_POLY_SET * GetBackPlatedPadPolys()
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
void addShape(const PCB_SHAPE *aShape, CONTAINER_2D_BASE *aContainer, const BOARD_ITEM *aOwner)
void createTrack(const PCB_TRACK *aTrack, CONTAINER_2D_BASE *aDstContainer)
const MAP_CONTAINER_2D_BASE & GetLayerMap() const noexcept
Get the map of containers that have the objects per layer.
MAP_POLY m_layers_poly
Amalgamated polygon contours for various types of items.
SHAPE_POLY_SET m_nonPlatedThroughHoleOdPolys
NPTH outer diameters.
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 )
unsigned int GetHoleCount() const noexcept
SFVEC4F m_SilkScreenColorBot
in realistic mode: SilkScreen color ( bot )
SFVEC4F GetItemColor(int aItemId) const
Get the technical color of a layer.
const SHAPE_POLY_SET & GetThroughHoleAnnularRingPolys() const noexcept
const BVH_CONTAINER_2D * GetPlatedPadsFront() const noexcept
unsigned int GetCircleSegmentCount(float aDiameter3DU) const
float m_nonCopperLayerThickness3DU
const BVH_CONTAINER_2D & GetThroughHoleAnnularRings() const noexcept
RENDER_SETTINGS * m_renderSettings
float GetFrontCopperThickness() const noexcept
Get the copper layer thicknesses (in 3D units).
unsigned int m_holeCount
float GetBoardBodyThickness() const noexcept
Get the board body thickness, including internal copper layers (in 3D units).
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.
float GetAverageHoleDiameter() const noexcept
void transformFPShapesToPolySet(const FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aBuffer) const
unsigned int m_copperLayersCount
bool m_MousewheelPanning
const SHAPE_POLY_SET & GetThroughHoleViaOdPolys() const noexcept
static KIGFX::COLOR4D g_DefaultSilkscreen
BVH_CONTAINER_2D * m_platedPadsFront
void Set3dCacheManager(S3D_CACHE *aCacheMgr) noexcept
Update the cache manager pointer.
Definition: board_adapter.h:80
SFVEC3F m_boardCenter
3D center position of the board in 3D units.
const BVH_CONTAINER_2D & GetThroughHoleOds() const noexcept
static KIGFX::COLOR4D g_DefaultBackgroundBot
SFVEC4F GetLayerColor(PCB_LAYER_ID aLayerId) const
Get the technical color of a layer.
S3D_CACHE * Get3dCacheManager() const noexcept
Definition: board_adapter.h:81
OBJECT_2D * createPadWithDrill(const PAD *aPad, int aInflateValue)
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
void addText(const EDA_TEXT *aText, CONTAINER_2D_BASE *aDstContainer, const BOARD_ITEM *aOwner)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:71
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:270
A class used to derive camera objects from.
Definition: camera.h:78
Color settings are a bit different than most of the settings objects in that there can be more than o...
virtual BOARD_ADAPTER & GetAdapter()=0
virtual CAMERA & GetCurrentCamera()=0
virtual ~EDA_3D_BOARD_HOLDER()
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:77
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Definition: pad.h:59
Abstract dimension API.
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
Cache for storing the 3D shapes.
Definition: 3d_cache.h:53
Represent a set of closed polygons.
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
FOOTPRINT_ATTR_T
The set of attributes allowed within a FOOTPRINT, using FOOTPRINT::SetAttributes() and FOOTPRINT::Get...
Definition: footprint.h:68
static const wxChar * m_logTrace
Trace mask used to enable or disable debug output for this class.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
Manage a bounding box defined by two SFVEC3F min max points.
Definition: bbox_3d.h:42
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46