Commit 5e032ef0 authored by jean-pierre charras's avatar jean-pierre charras

3d-viewer: code cleaning and minor bug fix.

parent 259425a2
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2014 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_canvas.cpp
*/
......@@ -26,8 +49,8 @@
#include <trackball.h>
#include <3d_viewer_id.h>
#include <textures/text_silk.c>
#include <textures/text_pcb.c>
#include <textures/text_silk.h>
#include <textures/text_pcb.h>
// -----------------
// helper function (from wxWidgets, opengl/cube.cpp sample
......
......@@ -142,48 +142,62 @@ public:
m_draw3dOffset.y = aPosY;
}
INFO3D_VISU& GetPrm3DVisu() const;
private:
/**
* return true if we are in realistic mode render
*/
bool isRealisticMode() const;
/**
* return true if aItem should be displayed
* @return true if aItem should be displayed
* @param aItem = an item of DISPLAY3D_FLG enum
*/
bool isEnabled( DISPLAY3D_FLG aItem ) const;
/* Helper function
/** Helper function
* @return true if aLayer should be displayed, false otherwise
*/
bool is3DLayerEnabled( LAYER_ID aLayer ) const;
/**
* @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;
/**
* Helper function SetGLTechLayersColor
* Initialize the color to draw the non copper layers
* in realistic mode and normal mode.
*/
void SetGLTechLayersColor( LAYER_NUM aLayer );
void setGLTechLayersColor( LAYER_NUM aLayer );
/**
* Helper function SetGLCopperColor
* Initialize the copper color to draw the board
* in realistic mode (a golden yellow color )
*/
void SetGLCopperColor();
void setGLCopperColor();
/**
* Helper function SetGLEpoxyColor
* Initialize the color to draw the epoxy body board in realistic mode.
*/
void SetGLEpoxyColor( double aTransparency = 1.0 );
void setGLEpoxyColor( double aTransparency = 1.0 );
/**
* Helper function SetGLSolderMaskColor
* Initialize the color to draw the solder mask layers in realistic mode.
*/
void SetGLSolderMaskColor( double aTransparency = 1.0 );
void setGLSolderMaskColor( double aTransparency = 1.0 );
/**
* Function BuildBoard3DView
......
......@@ -159,8 +159,8 @@ void EDA_3D_CANVAS::Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture,
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// move the board in order to draw it with its center at 0,0 3D coordinates
glTranslatef( -g_Parm_3D_Visu.m_BoardPos.x * g_Parm_3D_Visu.m_BiuTo3Dunits,
-g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BiuTo3Dunits,
glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits,
-GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits,
0.0F );
if( aDraw_body )
......@@ -268,11 +268,11 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures()
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
const double ZDIST_MAX = Millimeter2iu( 3.5 ) * g_Parm_3D_Visu.m_BiuTo3Dunits;
glOrtho( -g_Parm_3D_Visu.m_BoardSize.x * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f,
g_Parm_3D_Visu.m_BoardSize.x * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f,
-g_Parm_3D_Visu.m_BoardSize.y * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f,
g_Parm_3D_Visu.m_BoardSize.y * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f,
const double ZDIST_MAX = Millimeter2iu( 3.5 ) * GetPrm3DVisu().m_BiuTo3Dunits;
glOrtho( -GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
-GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
0.0, ZDIST_MAX );
// Render FRONT shadow
......@@ -295,10 +295,10 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures()
// Render ALL BOARD shadow
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( -g_Parm_3D_Visu.m_BoardSize.x * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f,
g_Parm_3D_Visu.m_BoardSize.x * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f,
-g_Parm_3D_Visu.m_BoardSize.y * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f,
g_Parm_3D_Visu.m_BoardSize.y * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f,
glOrtho( -GetPrm3DVisu().m_BoardSize.x * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
GetPrm3DVisu().m_BoardSize.x * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
-GetPrm3DVisu().m_BoardSize.y * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
GetPrm3DVisu().m_BoardSize.y * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
0.0, 6.0f * ZDIST_MAX );
glMatrixMode( GL_MODELVIEW );
......@@ -366,23 +366,14 @@ void EDA_3D_CANVAS::Redraw()
// Draw the background ( rectangle with color gradient)
glBegin( GL_QUADS );
glColor4f( g_Parm_3D_Visu.m_BgColor_Top.m_Red,
g_Parm_3D_Visu.m_BgColor_Top.m_Green,
g_Parm_3D_Visu.m_BgColor_Top.m_Blue,
1.0 );
SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 );
glVertex2f( -1.0, 1.0 ); // Top left corner
glColor4f( g_Parm_3D_Visu.m_BgColor.m_Red,
g_Parm_3D_Visu.m_BgColor.m_Green,
g_Parm_3D_Visu.m_BgColor.m_Blue,
1.0 );
SetGLColor( GetPrm3DVisu().m_BgColor, 1.0 );
glVertex2f( -1.0,-1.0 ); // bottom left corner
glVertex2f( 1.0,-1.0 ); // bottom right corner
glColor4f( g_Parm_3D_Visu.m_BgColor_Top.m_Red,
g_Parm_3D_Visu.m_BgColor_Top.m_Green,
g_Parm_3D_Visu.m_BgColor_Top.m_Blue,
1.0 );
SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 );
glVertex2f( 1.0, 1.0 ); // top right corner
glEnd();
......@@ -394,14 +385,14 @@ void EDA_3D_CANVAS::Redraw()
glLoadIdentity();
#define MAX_VIEW_ANGLE 160.0 / 45.0
if( g_Parm_3D_Visu.m_Zoom > MAX_VIEW_ANGLE )
g_Parm_3D_Visu.m_Zoom = MAX_VIEW_ANGLE;
if( GetPrm3DVisu().m_Zoom > MAX_VIEW_ANGLE )
GetPrm3DVisu().m_Zoom = MAX_VIEW_ANGLE;
if( Parent()->ModeIsOrtho() )
{
// OrthoReductionFactor is chosen to provide roughly the same size as
// Perspective View
const double orthoReductionFactor = 400 / g_Parm_3D_Visu.m_Zoom;
const double orthoReductionFactor = 400 / GetPrm3DVisu().m_Zoom;
// Initialize Projection Matrix for Ortographic View
glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor,
......@@ -413,7 +404,7 @@ void EDA_3D_CANVAS::Redraw()
double ratio_HV = (double) size.x / size.y;
// Initialize Projection Matrix for Perspective View
gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 100 );
gluPerspective( 45.0 * GetPrm3DVisu().m_Zoom, ratio_HV, 1, 100 );
}
// position viewer
......@@ -434,12 +425,12 @@ void EDA_3D_CANVAS::Redraw()
// Translate motion first, so rotations don't mess up the orientation...
glTranslatef( m_draw3dOffset.x, m_draw3dOffset.y, 0.0F );
build_rotmatrix( mat, g_Parm_3D_Visu.m_Quat );
build_rotmatrix( mat, GetPrm3DVisu().m_Quat );
glMultMatrixf( &mat[0][0] );
glRotatef( g_Parm_3D_Visu.m_Rot[0], 1.0, 0.0, 0.0 );
glRotatef( g_Parm_3D_Visu.m_Rot[1], 0.0, 1.0, 0.0 );
glRotatef( g_Parm_3D_Visu.m_Rot[2], 0.0, 0.0, 1.0 );
glRotatef( GetPrm3DVisu().m_Rot[0], 1.0, 0.0, 0.0 );
glRotatef( GetPrm3DVisu().m_Rot[1], 0.0, 1.0, 0.0 );
glRotatef( GetPrm3DVisu().m_Rot[2], 0.0, 0.0, 1.0 );
if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] )
......@@ -449,8 +440,8 @@ void EDA_3D_CANVAS::Redraw()
glCallList( m_glLists[GL_ID_AXIS] );
// move the board in order to draw it with its center at 0,0 3D coordinates
glTranslatef( -g_Parm_3D_Visu.m_BoardPos.x * g_Parm_3D_Visu.m_BiuTo3Dunits,
-g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BiuTo3Dunits,
glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits,
-GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits,
0.0F );
// draw all objects in lists
......@@ -467,7 +458,8 @@ void EDA_3D_CANVAS::Redraw()
if( isEnabled( FL_SHOW_BOARD_BODY ) )
{
if( isEnabled( FL_SOLDERMASK ) || !isRealisticMode() )
if( !isEnabled( FL_RENDER_TEXTURES ) ||
isEnabled( FL_SOLDERMASK ) || !isRealisticMode() )
{
glDisable( GL_TEXTURE_2D );
}
......@@ -488,9 +480,9 @@ void EDA_3D_CANVAS::Redraw()
glEnable( GL_COLOR_MATERIAL );
SetOpenGlDefaultMaterial();
glm::vec4 specular( g_Parm_3D_Visu.m_CopperColor.m_Red * 0.3,
g_Parm_3D_Visu.m_CopperColor.m_Green * 0.3,
g_Parm_3D_Visu.m_CopperColor.m_Blue * 0.3, 1.0 );
glm::vec4 specular( GetPrm3DVisu().m_CopperColor.m_Red * 0.3,
GetPrm3DVisu().m_CopperColor.m_Green * 0.3,
GetPrm3DVisu().m_CopperColor.m_Blue * 0.3, 1.0 );
GLint shininess_value = 8;
glMateriali ( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value );
......@@ -609,20 +601,20 @@ void EDA_3D_CANVAS::Redraw()
void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList )
{
// Use similar calculation as Grid limits, in 3D units
wxSize brd_size = g_Parm_3D_Visu.m_BoardSize;
wxPoint brd_center_pos = g_Parm_3D_Visu.m_BoardPos;
wxSize brd_size = getBoardSize();
wxPoint brd_center_pos = getBoardCenter();
float xsize = brd_size.x;
float ysize = brd_size.y;
float scale = g_Parm_3D_Visu.m_BiuTo3Dunits;
float scale = GetPrm3DVisu().m_BiuTo3Dunits;
float xmin = (brd_center_pos.x - xsize / 2.0) * scale;
float xmax = (brd_center_pos.x + xsize / 2.0) * scale;
float ymin = (brd_center_pos.y - ysize / 2.0) * scale;
float ymax = (brd_center_pos.y + ysize / 2.0) * scale;
float zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Paste );
zpos *= g_Parm_3D_Visu.m_BiuTo3Dunits;
float zpos = GetPrm3DVisu().GetLayerZcoordBIU( F_Paste );
zpos *= GetPrm3DVisu().m_BiuTo3Dunits;
// Shadow FRONT
glNewList( aFrontList, GL_COMPILE );
......@@ -640,8 +632,8 @@ void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint
// Shadow BACK
zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Paste );
zpos *= g_Parm_3D_Visu.m_BiuTo3Dunits;
zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Paste );
zpos *= GetPrm3DVisu().m_BiuTo3Dunits;
glNewList( aBacklist, GL_COMPILE );
......@@ -661,7 +653,7 @@ void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint
xsize = brd_size.x * SHADOW_BOARD_SCALE;
ysize = brd_size.y * SHADOW_BOARD_SCALE;
scale = g_Parm_3D_Visu.m_BiuTo3Dunits;
scale = GetPrm3DVisu().m_BiuTo3Dunits;
xmin = (brd_center_pos.x - xsize / 2.0) * scale;
xmax = (brd_center_pos.x + xsize / 2.0) * scale;
ymin = (brd_center_pos.y - ysize / 2.0) * scale;
......@@ -731,7 +723,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
CPOLYGONS_LIST currLayerHoles; // Contains holes for the current layer
bool throughHolesListBuilt = false; // flag to build the through hole polygon list only once
LSET cu_set = LSET::AllCuMask( g_Parm_3D_Visu.m_CopperLayersCount );
LSET cu_set = LSET::AllCuMask( GetPrm3DVisu().m_CopperLayersCount );
#if 1
LAYER_ID cu_seq[MAX_CU_LAYERS]; // preferred sequence, could have called CuStack()
......@@ -774,7 +766,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
VIA *via = static_cast<VIA*>( track );
VIATYPE_T viatype = via->GetViaType();
int holediameter = via->GetDrillValue();
int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU();
int thickness = GetPrm3DVisu().GetCopperThicknessBIU();
int hole_outer_radius = (holediameter + thickness) / 2;
if( viatype != VIA_THROUGH )
......@@ -875,12 +867,12 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
// Merge polygons, remove holes
currLayerPolyset -= polysetHoles;
int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer );
int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer );
int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer );
int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer );
if( realistic_mode )
{
SetGLCopperColor();
setGLCopperColor();
}
else
{
......@@ -894,7 +886,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
bufferPolys.ImportFrom( currLayerPolyset );
Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos,
thickness,
g_Parm_3D_Visu.m_BiuTo3Dunits );
GetPrm3DVisu().m_BiuTo3Dunits );
if( isEnabled( FL_USE_COPPER_THICKNESS ) == true )
{
......@@ -906,13 +898,13 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
if( bufferZonesPolys.GetCornersCount() )
Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos,
thickness,
g_Parm_3D_Visu.m_BiuTo3Dunits );
GetPrm3DVisu().m_BiuTo3Dunits );
throughHolesListBuilt = true;
}
if ( !isEnabled( FL_SHOW_BOARD_BODY ) )
{
SetGLCopperColor();
setGLCopperColor();
// Draw vias holes (vertical cylinders)
for( const TRACK* track = pcb->m_Track; track; track = track->Next() )
......@@ -938,7 +930,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
if( isRealisticMode() )
{
SetGLEpoxyColor( 0.95 );
setGLEpoxyColor( 0.95 );
}
else
{
......@@ -946,14 +938,14 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
SetGLColor( color, 0.7 );
}
float copper_thickness = g_Parm_3D_Visu.GetCopperThicknessBIU();
float copper_thickness = GetPrm3DVisu().GetCopperThicknessBIU();
// a small offset between substrate and external copper layer to avoid artifacts
// when drawing copper items on board
float epsilon = Millimeter2iu( 0.01 );
float zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu );
float board_thickness = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Cu )
- g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu );
float zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Cu );
float board_thickness = GetPrm3DVisu().GetLayerZcoordBIU( F_Cu )
- GetPrm3DVisu().GetLayerZcoordBIU( B_Cu );
// items on copper layers and having a thickness = copper_thickness
// are drawn from zpos - copper_thickness/2 to zpos + copper_thickness
......@@ -981,7 +973,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
if( bufferPcbOutlines.GetCornersCount() )
{
Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0,
board_thickness, g_Parm_3D_Visu.m_BiuTo3Dunits );
board_thickness, GetPrm3DVisu().m_BiuTo3Dunits );
}
glEndList();
......@@ -1019,7 +1011,7 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
wxMessageBox( msg );
}
int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU();
int thickness = GetPrm3DVisu().GetCopperThicknessBIU();
// Add via holes
for( VIA* via = GetFirstVia( pcb->m_Track ); via;
......@@ -1165,14 +1157,14 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
currLayerPolyset += polyset;
}
int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer );
int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer );
int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer );
int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer );
if( layer == Edge_Cuts )
{
thickness = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Cu )
- g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu );
zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu )
thickness = GetPrm3DVisu().GetLayerZcoordBIU( F_Cu )
- GetPrm3DVisu().GetLayerZcoordBIU( B_Cu );
zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Cu )
+ (thickness / 2);
}
else
......@@ -1190,10 +1182,10 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
bufferPolys.RemoveAllContours();
bufferPolys.ImportFrom( currLayerPolyset );
SetGLTechLayersColor( layer );
setGLTechLayersColor( layer );
glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) );
Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos,
thickness, g_Parm_3D_Visu.m_BiuTo3Dunits );
thickness, GetPrm3DVisu().m_BiuTo3Dunits );
}
}
......@@ -1278,8 +1270,8 @@ void EDA_3D_CANVAS::BuildBoard3DAuxLayers()
bufferPolys.ExportTo( polyset );
currLayerPolyset += polyset;
int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer );
int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer );
int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer );
int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer );
// for Draw3D_SolidHorizontalPolyPolygons,
// zpos it the middle between bottom and top sides.
// However for top layers, zpos should be the bottom layer pos,
......@@ -1292,10 +1284,10 @@ void EDA_3D_CANVAS::BuildBoard3DAuxLayers()
bufferPolys.RemoveAllContours();
bufferPolys.ImportFrom( currLayerPolyset );
SetGLTechLayersColor( layer );
setGLTechLayersColor( layer );
glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) );
Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos,
thickness, g_Parm_3D_Visu.m_BiuTo3Dunits );
thickness, GetPrm3DVisu().m_BiuTo3Dunits );
}
}
......@@ -1306,7 +1298,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
wxBusyCursor dummy;
// Build 3D board parameters:
g_Parm_3D_Visu.InitSettings( pcb );
GetPrm3DVisu().InitSettings( pcb );
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
......@@ -1319,7 +1311,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
m_glLists[GL_ID_GRID] = glGenLists( 1 );
glNewList( m_glLists[GL_ID_GRID], GL_COMPILE );
Draw3DGrid( g_Parm_3D_Visu.m_3D_Grid );
Draw3DGrid( GetPrm3DVisu().m_3D_Grid );
glEndList();
}
......@@ -1428,12 +1420,12 @@ void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas,
// Read from disk and draws the footprint 3D shapes if exists
S3D_MASTER* shape3D = m_3D_Drawings;
double zpos = g_Parm_3D_Visu.GetModulesZcoord3DIU( IsFlipped() );
double zpos = glcanvas->GetPrm3DVisu().GetModulesZcoord3DIU( IsFlipped() );
glPushMatrix();
glTranslatef( m_Pos.x * g_Parm_3D_Visu.m_BiuTo3Dunits,
-m_Pos.y * g_Parm_3D_Visu.m_BiuTo3Dunits,
glTranslatef( m_Pos.x * glcanvas->GetPrm3DVisu().m_BiuTo3Dunits,
-m_Pos.y * glcanvas->GetPrm3DVisu().m_BiuTo3Dunits,
zpos );
if( m_Orient )
......@@ -1504,7 +1496,7 @@ bool EDA_3D_CANVAS::is3DLayerEnabled( LAYER_ID aLayer ) const
case B_Cu:
case F_Cu:
return g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( aLayer )
return GetPrm3DVisu().m_BoardSettings->IsLayerVisible( aLayer )
|| isRealisticMode();
break;
......@@ -1514,7 +1506,7 @@ bool EDA_3D_CANVAS::is3DLayerEnabled( LAYER_ID aLayer ) const
if( isRealisticMode() )
return false;
return g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( aLayer );
return GetPrm3DVisu().m_BoardSettings->IsLayerVisible( aLayer );
}
// The layer has a flag, return the flag
......
......@@ -130,6 +130,13 @@ void SetGLColor( EDA_COLOR_T color, double alpha )
glColor4f( red, green, blue, alpha );
}
void SetGLColor( S3D_COLOR& aColor, float aTransparency )
{
glColor4f( aColor.m_Red, aColor.m_Green, aColor.m_Blue, aTransparency );
}
static float m_texture_scale;
void SetGLTexture( GLuint text_id, float scale )
......
......@@ -125,6 +125,13 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,
*/
void SetGLColor( EDA_COLOR_T aColor, double aTransparency = 1.0 );
/**
* Set the current 3D color from a S3D_COLOR color, with optional transparency
* @param aColor = a S3D_COLOR RGB color index
* @param aTransparency = the color transparency (default = 1.0 = no transparency)
*/
void SetGLColor( S3D_COLOR& aColor, float aTransparency );
/**
* Set a texture id and a scale to apply when rendering the polygons
......
......@@ -42,41 +42,54 @@
#define TEXTURE_PCB_SCALE 5.0
INFO3D_VISU& EDA_3D_CANVAS::GetPrm3DVisu() const
{
return g_Parm_3D_Visu;
}
wxSize EDA_3D_CANVAS::getBoardSize() const
{
// return the size of the board in pcb units
return GetPrm3DVisu().m_BoardSize;
}
wxPoint EDA_3D_CANVAS::getBoardCenter() const
{
// return the position of the board center in pcb units
return GetPrm3DVisu().m_BoardPos;
}
// return true if we are in realistic mode render
bool EDA_3D_CANVAS::isRealisticMode() const
{
return g_Parm_3D_Visu.IsRealisticMode();
return GetPrm3DVisu().IsRealisticMode();
}
// return true if aItem should be displayed
bool EDA_3D_CANVAS::isEnabled( DISPLAY3D_FLG aItem ) const
{
return g_Parm_3D_Visu.GetFlag( aItem );
return GetPrm3DVisu().GetFlag( aItem );
}
// Helper function: initialize the copper color to draw the board
// in realistic mode.
void EDA_3D_CANVAS::SetGLCopperColor()
void EDA_3D_CANVAS::setGLCopperColor()
{
glDisable( GL_TEXTURE_2D );
glColor4f( g_Parm_3D_Visu.m_CopperColor.m_Red,
g_Parm_3D_Visu.m_CopperColor.m_Green,
g_Parm_3D_Visu.m_CopperColor.m_Blue,
1.0 );
SetGLColor( GetPrm3DVisu().m_CopperColor, 1.0 );
}
// Helper function: initialize the color to draw the epoxy
// body board in realistic mode.
void EDA_3D_CANVAS::SetGLEpoxyColor( double aTransparency )
void EDA_3D_CANVAS::setGLEpoxyColor( double aTransparency )
{
// Generates an epoxy color, near board color
glColor4f( g_Parm_3D_Visu.m_BoardBodyColor.m_Red,
g_Parm_3D_Visu.m_BoardBodyColor.m_Green,
g_Parm_3D_Visu.m_BoardBodyColor.m_Blue,
aTransparency );
SetGLColor( GetPrm3DVisu().m_BoardBodyColor, aTransparency );
if( g_Parm_3D_Visu.GetFlag( FL_RENDER_TEXTURES ) )
if( isEnabled( FL_RENDER_TEXTURES ) )
{
SetGLTexture( m_text_pcb, TEXTURE_PCB_SCALE );
}
......@@ -84,15 +97,12 @@ void EDA_3D_CANVAS::SetGLEpoxyColor( double aTransparency )
// Helper function: initialize the color to draw the
// solder mask layers in realistic mode.
void EDA_3D_CANVAS::SetGLSolderMaskColor( double aTransparency )
void EDA_3D_CANVAS::setGLSolderMaskColor( double aTransparency )
{
// Generates a solder mask color
glColor4f( g_Parm_3D_Visu.m_SolderMaskColor.m_Red,
g_Parm_3D_Visu.m_SolderMaskColor.m_Green,
g_Parm_3D_Visu.m_SolderMaskColor.m_Blue,
aTransparency );
SetGLColor( GetPrm3DVisu().m_SolderMaskColor, aTransparency );
if( g_Parm_3D_Visu.GetFlag( FL_RENDER_TEXTURES ) )
if( isEnabled( FL_RENDER_TEXTURES ) )
{
SetGLTexture( m_text_pcb, TEXTURE_PCB_SCALE );
}
......@@ -100,7 +110,7 @@ void EDA_3D_CANVAS::SetGLSolderMaskColor( double aTransparency )
// Helper function: initialize the color to draw the non copper layers
// in realistic mode and normal mode.
void EDA_3D_CANVAS::SetGLTechLayersColor( LAYER_NUM aLayer )
void EDA_3D_CANVAS::setGLTechLayersColor( LAYER_NUM aLayer )
{
EDA_COLOR_T color;
......@@ -115,11 +125,9 @@ void EDA_3D_CANVAS::SetGLTechLayersColor( LAYER_NUM aLayer )
case B_SilkS:
case F_SilkS:
glColor4f( g_Parm_3D_Visu.m_SilkScreenColor.m_Red,
g_Parm_3D_Visu.m_SilkScreenColor.m_Green,
g_Parm_3D_Visu.m_SilkScreenColor.m_Blue, 0.96 );
SetGLColor( GetPrm3DVisu().m_SilkScreenColor, 0.96 );
if( g_Parm_3D_Visu.GetFlag( FL_RENDER_TEXTURES ) )
if( isEnabled( FL_RENDER_TEXTURES ) )
{
SetGLTexture( m_text_silk, 10.0f );
}
......@@ -128,7 +136,7 @@ void EDA_3D_CANVAS::SetGLTechLayersColor( LAYER_NUM aLayer )
case B_Mask:
case F_Mask:
SetGLSolderMaskColor( 0.90 );
setGLSolderMaskColor( 0.90 );
break;
default:
......@@ -175,13 +183,13 @@ void EDA_3D_CANVAS::Draw3DGrid( double aGriSizeMM )
double zpos = 0.0;
EDA_COLOR_T gridcolor = DARKGRAY; // Color of grid lines
EDA_COLOR_T gridcolor_marker = LIGHTGRAY; // Color of grid lines every 5 lines
const double scale = g_Parm_3D_Visu.m_BiuTo3Dunits;
const double scale = GetPrm3DVisu().m_BiuTo3Dunits;
const double transparency = 0.3;
glNormal3f( 0.0, 0.0, 1.0 );
wxSize brd_size = g_Parm_3D_Visu.m_BoardSize;
wxPoint brd_center_pos = g_Parm_3D_Visu.m_BoardPos;
wxSize brd_size = getBoardSize();
wxPoint brd_center_pos = getBoardCenter();
NEGATE( brd_center_pos.y );
int xsize = std::max( brd_size.x, Millimeter2iu( 100 ) );
......@@ -317,23 +325,23 @@ void EDA_3D_CANVAS::Draw3DPadHole( const D_PAD* aPad )
// Store here the points to approximate hole by segments
CPOLYGONS_LIST holecornersBuffer;
int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU();
int height = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Cu ) -
g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu );
int thickness = GetPrm3DVisu().GetCopperThicknessBIU();
int height = GetPrm3DVisu().GetLayerZcoordBIU( F_Cu ) -
GetPrm3DVisu().GetLayerZcoordBIU( B_Cu );
if( isRealisticMode() )
SetGLCopperColor();
setGLCopperColor();
else
SetGLColor( DARKGRAY );
int holeZpoz = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu ) + thickness / 2;
int holeZpoz = GetPrm3DVisu().GetLayerZcoordBIU( B_Cu ) + thickness / 2;
int holeHeight = height - thickness;
if( drillsize.x == drillsize.y ) // usual round hole
{
Draw3D_ZaxisCylinder( aPad->GetPosition(),
(drillsize.x + thickness) / 2, holeHeight,
thickness, holeZpoz, g_Parm_3D_Visu.m_BiuTo3Dunits );
thickness, holeZpoz, GetPrm3DVisu().m_BiuTo3Dunits );
}
else // Oblong hole
{
......@@ -359,7 +367,7 @@ void EDA_3D_CANVAS::Draw3DPadHole( const D_PAD* aPad )
// Draw the hole
Draw3D_ZaxisOblongCylinder( start, end, hole_radius, holeHeight,
thickness, holeZpoz, g_Parm_3D_Visu.m_BiuTo3Dunits );
thickness, holeZpoz, GetPrm3DVisu().m_BiuTo3Dunits );
}
}
......@@ -368,25 +376,25 @@ void EDA_3D_CANVAS::Draw3DViaHole( const VIA* aVia )
{
LAYER_ID top_layer, bottom_layer;
int inner_radius = aVia->GetDrillValue() / 2;
int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU();
int thickness = GetPrm3DVisu().GetCopperThicknessBIU();
aVia->LayerPair( &top_layer, &bottom_layer );
// Drawing via hole:
if( isRealisticMode() )
SetGLCopperColor();
setGLCopperColor();
else
{
EDA_COLOR_T color = g_ColorsSettings.GetItemColor( VIAS_VISIBLE + aVia->GetViaType() );
SetGLColor( color );
}
int height = g_Parm_3D_Visu.GetLayerZcoordBIU( top_layer ) -
g_Parm_3D_Visu.GetLayerZcoordBIU( bottom_layer ) - thickness;
int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( bottom_layer ) + thickness / 2;
int height = GetPrm3DVisu().GetLayerZcoordBIU( top_layer ) -
GetPrm3DVisu().GetLayerZcoordBIU( bottom_layer ) - thickness;
int zpos = GetPrm3DVisu().GetLayerZcoordBIU( bottom_layer ) + thickness / 2;
Draw3D_ZaxisCylinder( aVia->GetStart(), inner_radius + thickness / 2, height,
thickness, zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
thickness, zpos, GetPrm3DVisu().m_BiuTo3Dunits );
}
/* Build a pad outline as non filled polygon, to draw pads on silkscreen layer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment