2012-12-15 08:52:02 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file 3d_viewer.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _3D_CANVAS_H_
|
|
|
|
#define _3D_CANVAS_H_
|
|
|
|
|
|
|
|
#include <wx/glcanvas.h>
|
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
# ifdef __DARWIN__
|
|
|
|
# include <OpenGL/glu.h>
|
|
|
|
# else
|
|
|
|
# include <glu.h>
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# include <GL/glu.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <3d_struct.h>
|
2014-07-30 15:39:55 +00:00
|
|
|
|
2012-12-15 08:52:02 +00:00
|
|
|
class BOARD_DESIGN_SETTINGS;
|
|
|
|
class EDA_3D_FRAME;
|
2014-08-04 11:28:29 +00:00
|
|
|
class CPOLYGONS_LIST;
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
class VIA;
|
2014-01-30 08:18:47 +00:00
|
|
|
class D_PAD;
|
2012-12-15 08:52:02 +00:00
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
// We are using GL lists to store layers and other items
|
|
|
|
// to draw or not
|
|
|
|
// GL_LIST_ID are the GL lists indexes in m_glLists
|
|
|
|
enum GL_LIST_ID
|
|
|
|
{
|
|
|
|
GL_ID_BEGIN = 0,
|
|
|
|
GL_ID_AXIS = GL_ID_BEGIN, // list id for 3D axis
|
|
|
|
GL_ID_GRID, // list id for 3D grid
|
|
|
|
GL_ID_BOARD, // List id for copper layers
|
|
|
|
GL_ID_TECH_LAYERS, // List id for non copper layers (masks...)
|
|
|
|
GL_ID_AUX_LAYERS, // List id for user layers (draw, eco, comment)
|
2014-07-30 09:01:25 +00:00
|
|
|
GL_ID_3DSHAPES_SOLID_FRONT, // List id for 3D shapes, non transparent entities
|
|
|
|
GL_ID_3DSHAPES_TRANSP_FRONT,// List id for 3D shapes, transparent entities
|
2014-08-21 11:59:57 +00:00
|
|
|
GL_ID_3DSHAPES_SOLID_BACK, // List id for 3D shapes, non transparent entities
|
|
|
|
GL_ID_3DSHAPES_TRANSP_BACK, // List id for 3D shapes, transparent entities
|
2014-07-30 09:01:25 +00:00
|
|
|
GL_ID_SHADOW_FRONT,
|
|
|
|
GL_ID_SHADOW_BACK,
|
|
|
|
GL_ID_SHADOW_BOARD,
|
2014-08-21 11:59:57 +00:00
|
|
|
GL_ID_BODY, // Body only list
|
2014-03-08 19:04:23 +00:00
|
|
|
GL_ID_END
|
|
|
|
};
|
2012-12-15 08:52:02 +00:00
|
|
|
|
|
|
|
class EDA_3D_CANVAS : public wxGLCanvas
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
bool m_init;
|
2014-03-08 19:04:23 +00:00
|
|
|
GLuint m_glLists[GL_ID_END]; // GL lists
|
2012-12-15 08:52:02 +00:00
|
|
|
wxGLContext* m_glRC;
|
2014-03-08 19:04:23 +00:00
|
|
|
wxRealPoint m_draw3dOffset; // offset to draw the 3D mesh.
|
2012-12-15 08:52:02 +00:00
|
|
|
double m_ZBottom; // position of the back layer
|
|
|
|
double m_ZTop; // position of the front layer
|
|
|
|
|
2015-02-26 10:33:15 +00:00
|
|
|
GLuint m_text_pcb; // an index to the texture generated for pcb texts
|
|
|
|
GLuint m_text_silk; // an index to the texture generated for silk layers
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-02-26 10:33:15 +00:00
|
|
|
// Index to the textures generated for shadows
|
2014-07-30 09:01:25 +00:00
|
|
|
bool m_shadow_init;
|
|
|
|
GLuint m_text_fake_shadow_front;
|
|
|
|
GLuint m_text_fake_shadow_back;
|
|
|
|
GLuint m_text_fake_shadow_board;
|
|
|
|
|
2014-07-30 15:39:55 +00:00
|
|
|
void Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture,
|
|
|
|
GLuint aTexture_size, bool aDraw_body, int aBlurPasses );
|
|
|
|
|
2012-12-15 08:52:02 +00:00
|
|
|
public:
|
|
|
|
EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 );
|
|
|
|
~EDA_3D_CANVAS();
|
|
|
|
|
2014-05-04 17:08:36 +00:00
|
|
|
EDA_3D_FRAME* Parent() const { return static_cast<EDA_3D_FRAME*>( GetParent() ); }
|
2012-12-15 08:52:02 +00:00
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
BOARD* GetBoard() { return Parent()->GetBoard(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ClearLists
|
|
|
|
* Clear the display list.
|
|
|
|
* @param aGlList = the list to clear.
|
|
|
|
* if 0 (default) all lists are cleared
|
|
|
|
*/
|
2014-07-30 15:39:55 +00:00
|
|
|
void ClearLists( int aGlList = 0 );
|
2012-12-15 08:52:02 +00:00
|
|
|
|
|
|
|
// Event functions:
|
|
|
|
void OnPaint( wxPaintEvent& event );
|
|
|
|
void OnEraseBackground( wxEraseEvent& event );
|
|
|
|
void OnChar( wxKeyEvent& event );
|
|
|
|
void OnMouseWheel( wxMouseEvent& event );
|
|
|
|
void OnMouseMove( wxMouseEvent& event );
|
|
|
|
void OnRightClick( wxMouseEvent& event );
|
|
|
|
void OnPopUpMenu( wxCommandEvent& event );
|
|
|
|
void TakeScreenshot( wxCommandEvent& event );
|
|
|
|
void OnEnterWindow( wxMouseEvent& event );
|
|
|
|
|
|
|
|
// Display functions
|
|
|
|
void SetView3D( int keycode );
|
|
|
|
void DisplayStatus();
|
2014-03-05 17:40:23 +00:00
|
|
|
void Redraw();
|
2012-12-15 08:52:02 +00:00
|
|
|
void Render();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function CreateDrawGL_List
|
2013-05-01 19:01:14 +00:00
|
|
|
* Prepares the parameters of the OpenGL draw list
|
|
|
|
* creates the OpenGL draw list items (board, grid ...
|
2012-12-15 08:52:02 +00:00
|
|
|
*/
|
2014-03-08 19:04:23 +00:00
|
|
|
void CreateDrawGL_List();
|
2012-12-15 08:52:02 +00:00
|
|
|
void InitGL();
|
|
|
|
void SetLights();
|
2014-08-04 11:28:29 +00:00
|
|
|
|
2012-12-15 08:52:02 +00:00
|
|
|
void SetOffset(double aPosX, double aPosY)
|
|
|
|
{
|
|
|
|
m_draw3dOffset.x = aPosX;
|
|
|
|
m_draw3dOffset.y = aPosY;
|
|
|
|
}
|
2014-08-04 11:28:29 +00:00
|
|
|
|
2014-08-21 11:59:57 +00:00
|
|
|
/** @return the INFO3D_VISU which contains the current parameters
|
|
|
|
* to draw the 3D view og the board
|
|
|
|
*/
|
2014-08-20 17:53:09 +00:00
|
|
|
INFO3D_VISU& GetPrm3DVisu() const;
|
|
|
|
|
|
|
|
|
2014-08-04 11:28:29 +00:00
|
|
|
private:
|
2014-08-20 17:53:09 +00:00
|
|
|
|
2014-08-20 08:39:19 +00:00
|
|
|
/**
|
|
|
|
* return true if we are in realistic mode render
|
|
|
|
*/
|
|
|
|
bool isRealisticMode() const;
|
|
|
|
|
|
|
|
/**
|
2014-08-20 17:53:09 +00:00
|
|
|
* @return true if aItem should be displayed
|
2014-08-20 08:39:19 +00:00
|
|
|
* @param aItem = an item of DISPLAY3D_FLG enum
|
|
|
|
*/
|
|
|
|
bool isEnabled( DISPLAY3D_FLG aItem ) const;
|
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
/** Helper function
|
2014-08-20 08:39:19 +00:00
|
|
|
* @return true if aLayer should be displayed, false otherwise
|
|
|
|
*/
|
|
|
|
bool is3DLayerEnabled( LAYER_ID aLayer ) const;
|
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
/**
|
|
|
|
* @return the size of the board in pcb units
|
|
|
|
*/
|
|
|
|
wxSize getBoardSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the position of the board center in pcb units
|
|
|
|
*/
|
|
|
|
wxPoint getBoardCenter() const;
|
|
|
|
|
2014-08-04 11:28:29 +00:00
|
|
|
/**
|
|
|
|
* Helper function SetGLTechLayersColor
|
|
|
|
* Initialize the color to draw the non copper layers
|
|
|
|
* in realistic mode and normal mode.
|
|
|
|
*/
|
2014-08-20 17:53:09 +00:00
|
|
|
void setGLTechLayersColor( LAYER_NUM aLayer );
|
2014-08-04 11:28:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function SetGLCopperColor
|
|
|
|
* Initialize the copper color to draw the board
|
|
|
|
* in realistic mode (a golden yellow color )
|
|
|
|
*/
|
2014-08-20 17:53:09 +00:00
|
|
|
void setGLCopperColor();
|
2014-08-04 11:28:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function SetGLEpoxyColor
|
|
|
|
* Initialize the color to draw the epoxy body board in realistic mode.
|
|
|
|
*/
|
2014-08-20 17:53:09 +00:00
|
|
|
void setGLEpoxyColor( double aTransparency = 1.0 );
|
2012-12-15 08:52:02 +00:00
|
|
|
|
2014-08-04 11:28:29 +00:00
|
|
|
/**
|
|
|
|
* Helper function SetGLSolderMaskColor
|
|
|
|
* Initialize the color to draw the solder mask layers in realistic mode.
|
|
|
|
*/
|
2014-08-20 17:53:09 +00:00
|
|
|
void setGLSolderMaskColor( double aTransparency = 1.0 );
|
2014-08-04 11:28:29 +00:00
|
|
|
|
2012-12-15 08:52:02 +00:00
|
|
|
/**
|
2013-05-01 19:01:14 +00:00
|
|
|
* Function BuildBoard3DView
|
|
|
|
* Called by CreateDrawGL_List()
|
2014-03-08 19:04:23 +00:00
|
|
|
* Populates the OpenGL GL_ID_BOARD draw list with board items only on copper layers.
|
|
|
|
* 3D footprint shapes, tech layers and aux layers are not on this list
|
2012-12-15 08:52:02 +00:00
|
|
|
*/
|
2014-07-30 09:01:25 +00:00
|
|
|
void BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList);
|
2012-12-15 08:52:02 +00:00
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
/**
|
|
|
|
* Function BuildTechLayers3DView
|
|
|
|
* Called by CreateDrawGL_List()
|
2014-07-30 15:39:55 +00:00
|
|
|
* Populates the OpenGL GL_ID_TECH_LAYERS draw list with items on tech layers
|
2014-03-08 19:04:23 +00:00
|
|
|
*/
|
|
|
|
void BuildTechLayers3DView();
|
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
/**
|
|
|
|
* Function BuildShadowList
|
|
|
|
* Called by CreateDrawGL_List()
|
|
|
|
*/
|
|
|
|
void BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList );
|
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
/**
|
|
|
|
* Function BuildFootprintShape3DList
|
|
|
|
* Called by CreateDrawGL_List()
|
|
|
|
* Fills the OpenGL GL_ID_3DSHAPES_SOLID and GL_ID_3DSHAPES_TRANSP
|
|
|
|
* draw lists with 3D footprint shapes
|
|
|
|
* @param aOpaqueList is the gl list for non transparent items
|
|
|
|
* @param aTransparentList is the gl list for non transparent items,
|
|
|
|
* which need to be drawn after all other items
|
|
|
|
*/
|
|
|
|
void BuildFootprintShape3DList( GLuint aOpaqueList,
|
2014-07-30 09:01:25 +00:00
|
|
|
GLuint aTransparentList,
|
|
|
|
bool aSideToLoad );
|
2014-03-08 19:04:23 +00:00
|
|
|
/**
|
|
|
|
* Function BuildBoard3DAuxLayers
|
|
|
|
* Called by CreateDrawGL_List()
|
|
|
|
* Fills the OpenGL GL_ID_AUX_LAYERS draw list
|
|
|
|
* with items on aux layers only
|
|
|
|
*/
|
|
|
|
void BuildBoard3DAuxLayers();
|
|
|
|
|
|
|
|
void Draw3DGrid( double aGriSizeMM );
|
|
|
|
void Draw3DAxis();
|
|
|
|
|
2014-08-04 11:28:29 +00:00
|
|
|
/**
|
|
|
|
* Helper function BuildPadShapeThickOutlineAsPolygon:
|
|
|
|
* Build a pad outline as non filled polygon, to draw pads on silkscreen layer
|
|
|
|
* with a line thickness = aWidth
|
|
|
|
* Used only to draw pads outlines on silkscreen layers.
|
|
|
|
*/
|
|
|
|
void BuildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
|
|
|
|
CPOLYGONS_LIST& aCornerBuffer,
|
|
|
|
int aWidth,
|
|
|
|
int aCircleToSegmentsCount,
|
|
|
|
double aCorrectionFactor );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function Draw3DViaHole:
|
|
|
|
* Draw the via hole:
|
|
|
|
* Build a vertical hole (a cylinder) between the first and the last via layers
|
|
|
|
*/
|
2014-04-25 06:00:04 +00:00
|
|
|
void Draw3DViaHole( const VIA * aVia );
|
2014-08-04 11:28:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function Draw3DPadHole:
|
|
|
|
* Draw the pad hole:
|
|
|
|
* Build a vertical hole (round or oblong) between the front and back layers
|
|
|
|
*/
|
2014-04-25 06:00:04 +00:00
|
|
|
void Draw3DPadHole( const D_PAD * aPad );
|
2012-12-15 08:52:02 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
void GenerateFakeShadowsTextures();
|
|
|
|
|
2012-12-15 08:52:02 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
void CheckGLError(const char *aFileName, int aLineNumber);
|
|
|
|
|
2012-12-15 08:52:02 +00:00
|
|
|
#endif /* _3D_CANVAS_H_ */
|