KiCad PCB EDA Suite
render_3d_legacy.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 <mrluzeiro@ua.pt>
5  * Copyright (C) 2015-2020 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 
29 #ifndef RENDER_3D_LEGACY_H_
30 #define RENDER_3D_LEGACY_H_
31 
32 #include "../render_3d_base.h"
33 #include "layer_triangles.h"
34 
35 #include "../3d_render_raytracing/shapes2D/polygon_2d.h"
36 #include "../3d_render_raytracing/shapes2D/triangle_2d.h"
37 #include "../3d_render_raytracing/shapes2D/4pt_polygon_2d.h"
38 #include "../3d_render_raytracing/shapes2D/filled_circle_2d.h"
39 #include "../3d_render_raytracing/shapes2D/ring_2d.h"
40 #include "../3d_render_raytracing/shapes2D/round_segment_2d.h"
41 
42 #include "3d_model.h"
43 
44 #include "3d_cache/3d_info.h"
45 
46 #include <map>
47 
48 
49 typedef std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST* > MAP_OGL_DISP_LISTS;
50 typedef std::list<TRIANGLE_DISPLAY_LIST* > LIST_TRIANGLES;
51 typedef std::map< wxString, MODEL_3D* > MAP_3DMODEL;
52 
53 #define SIZE_OF_CIRCLE_TEXTURE 1024
54 
59 {
60 public:
61  explicit RENDER_3D_LEGACY( EDA_3D_CANVAS* aCanvas, BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
62 
64 
65  void SetCurWindowSize( const wxSize& aSize ) override;
66  bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
67 
68  int GetWaitForEditingTimeOut() override;
69 
70  void SetCurrentRollOverItem( BOARD_ITEM* aRollOverItem )
71  {
72  m_currentRollOverItem = aRollOverItem;
73  }
74 
78  void Load3dModelsIfNeeded();
79 
80 private:
81  OPENGL_RENDER_LIST* generateHoles( const LIST_OBJECT2D& aListHolesObject2d,
82  const SHAPE_POLY_SET& aPoly, float aZtop,
83  float aZbot, bool aInvertFaces,
84  const BVH_CONTAINER_2D* aThroughHoles = nullptr );
85 
87  const SHAPE_POLY_SET* aPolyList,
88  PCB_LAYER_ID aLayerId,
89  const BVH_CONTAINER_2D* aThroughHoles = nullptr );
90 
92  const SFVEC2F& v1, const SFVEC2F& v2, float top, float bot );
93 
94  void addObjectTriangles( const RING_2D* aRing, TRIANGLE_DISPLAY_LIST* aDstLayer,
95  float aZtop, float aZbot );
96 
97  void addObjectTriangles( const POLYGON_4PT_2D* aPoly, TRIANGLE_DISPLAY_LIST* aDstLayer,
98  float aZtop, float aZbot );
99 
100  void addObjectTriangles( const FILLED_CIRCLE_2D* aFilledCircle,
101  TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot );
102 
103  void addObjectTriangles( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer,
104  float aZtop, float aZbot );
105 
106  void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg,
107  TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot );
108 
109  void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPosition,
110  bool aDrawMiddleSegments, bool aSkipRenderHoles );
111 
112  void renderBoardBody( bool aSkipRenderHoles );
113 
114  void getLayerZPos( PCB_LAYER_ID aLayerID, float& aOutZtop, float& aOutZbot ) const;
115 
116  void generateRing( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
117  unsigned int aNr_sides_per_circle,
118  std::vector< SFVEC2F >& aInnerContourResult,
119  std::vector< SFVEC2F >& aOuterContourResult, bool aInvertOrder );
120 
121  void generateCylinder( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
122  float aZtop, float aZbot, unsigned int aNr_sides_per_circle,
123  TRIANGLE_DISPLAY_LIST* aDstLayer );
124 
125  void generateViasAndPads();
126 
134  void load3dModels( REPORTER* aStatusReporter );
135 
141  void render3dModels( bool aRenderTopOrBot, bool aRenderTransparentOnly );
142 
143  void render3dModelsSelected( bool aRenderTopOrBot, bool aRenderTransparentOnly,
144  bool aRenderSelectedOnly );
145 
146  void renderFootprint( const FOOTPRINT* aFootprint, bool aRenderTransparentOnly,
147  bool aIsSelected );
148 
149  void setLightFront( bool enabled );
150  void setLightTop( bool enabled );
151  void setLightBottom( bool enabled );
152 
153  void render3dArrows();
154 
160  void generate3dGrid( GRID3D_TYPE aGridType );
161 
162  // Materials
163  void setupMaterials();
164 
165  void setCopperMaterial();
167  void unsetDepthOffset();
168 
169  void setLayerMaterial( PCB_LAYER_ID aLayerID );
170  SFVEC4F getLayerColor( PCB_LAYER_ID aLayerID );
171 
172  bool initializeOpenGL();
173  OPENGL_RENDER_LIST* createBoard( const SHAPE_POLY_SET& aBoardPoly,
174  const BVH_CONTAINER_2D* aThroughHoles = nullptr );
175  void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
176 
177  void setArrowMaterial();
178 
179  void freeAllLists();
180 
181  struct
182  {
192  } m_materials;
193 
205 
208 
209  GLuint m_grid;
211 
214 
216 
218 
220 };
222 
223 #endif // RENDER_3D_LEGACY_H_
void SetCurrentRollOverItem(BOARD_ITEM *aRollOverItem)
int GetWaitForEditingTimeOut() override
Give the interface the time (in ms) that it should wait for editing or movements before (this works f...
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
void render3dModels(bool aRenderTopOrBot, bool aRenderTransparentOnly)
void reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
OPENGL_RENDER_LIST * createBoard(const SHAPE_POLY_SET &aBoardPoly, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
Store arrays of triangles to be used to create display lists.
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
std::map< wxString, MODEL_3D * > MAP_3DMODEL
MAP_OGL_DISP_LISTS m_layers
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46
void render3dModelsSelected(bool aRenderTopOrBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly)
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:48
OPENGL_RENDER_LIST * m_platedPadsFront
void setLightBottom(bool enabled)
void generate3dGrid(GRID3D_TYPE aGridType)
Create a 3D grid to an OpenGL display list.
void renderFootprint(const FOOTPRINT *aFootprint, bool aRenderTransparentOnly, bool aIsSelected)
void setPlatedCopperAndDepthOffset(PCB_LAYER_ID aLayer_id)
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:70
std::list< TRIANGLE_DISPLAY_LIST * > LIST_TRIANGLES
MAP_3DMODEL m_3dModelMap
void addTopAndBottomTriangles(TRIANGLE_DISPLAY_LIST *aDst, const SFVEC2F &v0, const SFVEC2F &v1, const SFVEC2F &v2, float top, float bot)
defines the basic data associated with a single 3D model.
void getLayerZPos(PCB_LAYER_ID aLayerID, float &aOutZtop, float &aOutZbot) const
void setLayerMaterial(PCB_LAYER_ID aLayerID)
void generateRing(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, unsigned int aNr_sides_per_circle, std::vector< SFVEC2F > &aInnerContourResult, std::vector< SFVEC2F > &aOuterContourResult, bool aInvertOrder)
void generateCylinder(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer)
OPENGL_RENDER_LIST * m_outerThroughHoles
OPENGL_RENDER_LIST * m_outerThroughHoleRings
OPENGL_RENDER_LIST * m_boardWithHoles
A class used to derive camera objects from.
Definition: camera.h:77
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
MAP_OGL_DISP_LISTS m_outerLayerHoles
OPENGL_RENDER_LIST * m_antiBoard
Represent a set of closed polygons.
Object to render the board using openGL legacy mode.
bool Redraw(bool aIsMoving, REPORTER *aStatusReporter, REPORTER *aWarningReporter) override
Redraw the view.
OPENGL_RENDER_LIST * m_board
void addObjectTriangles(const RING_2D *aRing, TRIANGLE_DISPLAY_LIST *aDstLayer, float aZtop, float aZbot)
GRID3D_TYPE m_lastGridType
Stores the last grid type.
OPENGL_RENDER_LIST * generateHoles(const LIST_OBJECT2D &aListHolesObject2d, const SHAPE_POLY_SET &aPoly, float aZtop, float aZbot, bool aInvertFaces, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
This is a base class to hold data and functions for render targets.
RENDER_3D_LEGACY(EDA_3D_CANVAS *aCanvas, BOARD_ADAPTER &aAdapter, CAMERA &aCamera)
OPENGL_RENDER_LIST * generateLayerList(const BVH_CONTAINER_2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayerId, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
void load3dModels(REPORTER *aStatusReporter)
Load footprint models from the cache and load it to openGL lists in the form of MODEL_3D objects.
GRID3D_TYPE
Grid types.
Definition: 3d_enums.h:99
Store the OpenGL display lists to related with a layer.
Simple non-intersecting polygon with 4 points.
BOARD_ITEM * m_currentRollOverItem
void renderBoardBody(bool aSkipRenderHoles)
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
GLuint m_grid
oGL list that stores current grid
SHAPE_POLY_SET m_antiBoardPolys
The negative polygon representation of the board outline.
void setLightFront(bool enabled)
void renderSolderMaskLayer(PCB_LAYER_ID aLayerID, float aZPosition, bool aDrawMiddleSegments, bool aSkipRenderHoles)
SMATERIAL m_GrayMaterial
std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST * > MAP_OGL_DISP_LISTS
SFVEC4F getLayerColor(PCB_LAYER_ID aLayerID)
std::list< OBJECT_2D * > LIST_OBJECT2D
Definition: container_2d.h:36
OPENGL_RENDER_LIST * m_platedPadsBack
MAP_OGL_DISP_LISTS m_innerLayerHoles
OPENGL_RENDER_LIST * m_vias
void SetCurWindowSize(const wxSize &aSize) override
Before each render, the canvas will tell the render what is the size of its windows,...
Implement a legacy 3D model render.
void setLightTop(bool enabled)
Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:68
OPENGL_RENDER_LIST * m_padHoles
SMATERIAL m_NonPlatedCopper
OPENGL_RENDER_LIST * m_outerViaThroughHoles
struct RENDER_3D_LEGACY::@5 m_materials