Loading 3d-viewer/3d_canvas.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -53,7 +53,8 @@ void CheckGLError(const char *aFileName, int aLineNumber) errLast = err; wxLogError( wxT( "OpenGL error %d At: %s, line: %d" ), err, GetChars( FROM_UTF8( aFileName ) ), aLineNumber ); wxLogError( wxT( "OpenGL error %d At: %s, line: %d" ), err, GetChars( FROM_UTF8( aFileName ) ), aLineNumber ); } } Loading Loading @@ -625,7 +626,7 @@ void EDA_3D_CANVAS::TakeScreenshot( wxCommandEvent& event ) wxYield(); } struct vieport_params struct viewport_params { GLint originx; GLint originy; Loading @@ -633,6 +634,10 @@ void EDA_3D_CANVAS::TakeScreenshot( wxCommandEvent& event ) GLint y; } viewport; // Be sure we have the latest 3D view (remember 3D view is buffered) Refresh(); wxYield(); // Build image from the 3D buffer wxWindowUpdateLocker noUpdates( this ); glGetIntegerv( GL_VIEWPORT, (GLint*) &viewport ); Loading 3d-viewer/3d_canvas.h +50 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ class BOARD_DESIGN_SETTINGS; class EDA_3D_FRAME; class CPOLYGONS_LIST; class VIA; class D_PAD; Loading Loading @@ -134,15 +135,40 @@ public: void CreateDrawGL_List(); void InitGL(); void SetLights(); void SetOffset(double aPosX, double aPosY) { m_draw3dOffset.x = aPosX; m_draw3dOffset.y = aPosY; } private: /** * Helper function SetGLTechLayersColor * Initialize the color to draw the non copper layers * in realistic mode and normal mode. */ 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(); /** * Helper function SetGLEpoxyColor * Initialize the color to draw the epoxy body board in realistic mode. */ 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 ); /** * Function BuildBoard3DView * Called by CreateDrawGL_List() Loading Loading @@ -187,7 +213,31 @@ public: void Draw3DGrid( double aGriSizeMM ); void Draw3DAxis(); /** * 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 */ void Draw3DViaHole( const VIA * aVia ); /** * Helper function Draw3DPadHole: * Draw the pad hole: * Build a vertical hole (round or oblong) between the front and back layers */ void Draw3DPadHole( const D_PAD * aPad ); void GenerateFakeShadowsTextures(); Loading 3d-viewer/3d_draw.cpp +35 −373 Original line number Diff line number Diff line Loading @@ -65,44 +65,9 @@ static bool Is3DLayerEnabled( LAYER_ID aLayer ); */ static GLfloat Get3DLayer_Z_Orientation( LAYER_NUM aLayer ); /* Helper function BuildPadShapeThickOutlineAsPolygon: * Build a pad shape outline as polygon, to draw pads on silkscreen layer * with a line thickness = aWidth * Used only to draw pads outlines on silkscreen layers. */ static void BuildPadShapeThickOutlineAsPolygon( D_PAD* aPad, CPOLYGONS_LIST& aCornerBuffer, int aWidth, int aCircleToSegmentsCount, double aCorrectionFactor ) { if( aPad->GetShape() == PAD_CIRCLE ) // Draw a ring { TransformRingToPolygon( aCornerBuffer, aPad->ShapePos(), aPad->GetSize().x / 2, aCircleToSegmentsCount, aWidth ); return; } // For other shapes, draw polygon outlines CPOLYGONS_LIST corners; aPad->BuildPadShapePolygon( corners, wxSize( 0, 0 ), aCircleToSegmentsCount, aCorrectionFactor ); // Add outlines as thick segments in polygon buffer for( unsigned ii = 0, jj = corners.GetCornersCount() - 1; ii < corners.GetCornersCount(); jj = ii, ii++ ) { TransformRoundedEndsSegmentToPolygon( aCornerBuffer, corners.GetPos( jj ), corners.GetPos( ii ), aCircleToSegmentsCount, aWidth ); } } // Based on the tutorial by http://www.ulrichmierendorff.com/software/opengl_blur.html /* It will blur a openGL texture * /* Based on the tutorial http://www.ulrichmierendorff.com/software/opengl_blur.html * It will blur a openGL texture */ static void blur_tex( GLuint aTex, int aPasses, GLuint aTexture_size ) { Loading Loading @@ -297,20 +262,23 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures() { return; } m_shadow_init = true; // Init info 3d parameters and create gl lists: CreateDrawGL_List(); m_shadow_init = true; glClearColor( 0, 0, 0, 1 ); 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, 0.0, 3500000 * g_Parm_3D_Visu.m_BiuTo3Dunits ); 0.0, ZDIST_MAX ); // Render FRONT shadow glMatrixMode( GL_MODELVIEW ); Loading @@ -336,7 +304,7 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures() 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, 0.0, 6.0f * 3500000 * g_Parm_3D_Visu.m_BiuTo3Dunits ); 0.0, 6.0f * ZDIST_MAX ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); Loading Loading @@ -392,18 +360,29 @@ void EDA_3D_CANVAS::Redraw() glDisable( GL_DEPTH_TEST ); glDisable( GL_TEXTURE_2D ); // Draw the background ( rectangle with color gradient) glBegin( GL_QUADS ); glColor4f( 0.95, 0.95, 1.0, 1.0 ); glVertex2f( -1.0, 0.85 ); 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 ); glVertex2f( -1.0,-1.0 ); glVertex2f( 1.0,-1.0 ); #define BGCOLOR1(x) (x) #define BGCOLOR2(x) (x * 0.3) glColor4f( BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Red ), BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Green ), BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Blue ), 1.0 ); glVertex2f( -1.0, 1.0 ); // Top left corner glColor4f( BGCOLOR2( g_Parm_3D_Visu.m_BgColor.m_Red ), BGCOLOR2( g_Parm_3D_Visu.m_BgColor.m_Green ), BGCOLOR2( g_Parm_3D_Visu.m_BgColor.m_Blue ), 1.0 ); glVertex2f( -1.0,-1.0 ); // bottom left corner glVertex2f( 1.0,-1.0 ); // bottom right corner glColor4f( BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Red ), BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Green ), BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Blue ), 1.0 ); glVertex2f( 1.0, 1.0 ); // top right corner glColor4f( 0.95, 0.95, 1.0, 1.0 ); glVertex2f( 1.0, 0.85 ); glEnd(); glEnable( GL_DEPTH_TEST ); Loading Loading @@ -579,82 +558,8 @@ void EDA_3D_CANVAS::Redraw() glDisable( GL_CULL_FACE ); } } SwapBuffers(); } // Helper function: initialize the copper color to draw the board // in realistic mode. void EDA_3D_CANVAS::SetGLCopperColor() { glDisable( GL_TEXTURE_2D ); // Generates a golden yellow color, near board "copper" color const double lum = 0.7/255.0; glColor4f( 255.0*lum, 223.0*lum, 0.0*lum, 1.0 ); } // Helper function: initialize the color to draw the epoxy // body board in realistic mode. void EDA_3D_CANVAS::SetGLEpoxyColor( double aTransparency ) { // Generates an epoxy color, near board color const double lum = 0.2/255.0; glColor4f( 255.0*lum, 218.0*lum, 110.0*lum, aTransparency ); } // Helper function: initialize the color to draw the // solder mask layers in realistic mode. static inline void SetGLSolderMaskColor( double aTransparency = 1.0 ) { // Generates a solder mask color const double lum = 0.2/255.0; glColor4f( 100.0*lum, 255.0*lum, 180.0*lum, 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 ) { EDA_COLOR_T color; if( g_Parm_3D_Visu.IsRealisticMode() ) { switch( aLayer ) { case B_Paste: case F_Paste: SetGLColor( DARKGRAY, 0.7 ); break; case B_SilkS: case F_SilkS: SetGLColor( LIGHTGRAY, 0.9 ); if( g_Parm_3D_Visu.HightQualityMode() ) { SetGLTexture( m_text_silk, 50.0f ); } break; case B_Mask: case F_Mask: SetGLSolderMaskColor( 0.7 ); if( g_Parm_3D_Visu.HightQualityMode() ) { SetGLTexture( m_text_pcb, 35.0f ); } break; default: color = g_ColorsSettings.GetLayerColor( aLayer ); SetGLColor( color, 0.7 ); break; } } else { color = g_ColorsSettings.GetLayerColor( aLayer ); SetGLColor( color, 0.7 ); } SwapBuffers(); } Loading Loading @@ -1037,12 +942,14 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) glNewList( aBodyOnlyList, GL_COMPILE ); if( bufferPcbOutlines.GetCornersCount() ) { glColor4f( 1.0, 1.0, 1.0, 1.0 ); Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0, board_thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); } glEndList(); } Loading Loading @@ -1481,192 +1388,6 @@ void EDA_3D_CANVAS::BuildFootprintShape3DList( GLuint aOpaqueList, glEndList(); } void EDA_3D_CANVAS::Draw3DAxis() { if( ! m_glLists[GL_ID_AXIS] ) { m_glLists[GL_ID_AXIS] = glGenLists( 1 ); glNewList( m_glLists[GL_ID_AXIS], GL_COMPILE ); glEnable( GL_COLOR_MATERIAL ); SetGLColor( WHITE ); glBegin( GL_LINES ); glNormal3f( 0.0f, 0.0f, 1.0f ); // Normal is Z axis glVertex3f( 0.0f, 0.0f, 0.0f ); glVertex3f( 1.0f, 0.0f, 0.0f ); // X axis glVertex3f( 0.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, -1.0f, 0.0f ); // Y axis glNormal3f( 1.0f, 0.0f, 0.0f ); // Normal is Y axis glVertex3f( 0.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.3f ); // Z axis glEnd(); glEndList(); } } // draw a 3D grid: an horizontal grid (XY plane and Z = 0, // and a vertical grid (XZ plane and Y = 0) 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 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; NEGATE( brd_center_pos.y ); int xsize = std::max( brd_size.x, Millimeter2iu( 100 ) ); int ysize = std::max( brd_size.y, Millimeter2iu( 100 ) ); // Grid limits, in 3D units double xmin = (brd_center_pos.x - xsize / 2) * scale; double xmax = (brd_center_pos.x + xsize / 2) * scale; double ymin = (brd_center_pos.y - ysize / 2) * scale; double ymax = (brd_center_pos.y + ysize / 2) * scale; double zmin = Millimeter2iu( -50 ) * scale; double zmax = Millimeter2iu( 100 ) * scale; // Draw horizontal grid centered on 3D origin (center of the board) for( int ii = 0; ; ii++ ) { if( (ii % 5) ) SetGLColor( gridcolor, transparency ); else SetGLColor( gridcolor_marker, transparency ); int delta = KiROUND( ii * aGriSizeMM * IU_PER_MM ); if( delta <= xsize / 2 ) // Draw grid lines parallel to X axis { glBegin( GL_LINES ); glVertex3f( (brd_center_pos.x + delta) * scale, -ymin, zpos ); glVertex3f( (brd_center_pos.x + delta) * scale, -ymax, zpos ); glEnd(); if( ii != 0 ) { glBegin( GL_LINES ); glVertex3f( (brd_center_pos.x - delta) * scale, -ymin, zpos ); glVertex3f( (brd_center_pos.x - delta) * scale, -ymax, zpos ); glEnd(); } } if( delta <= ysize / 2 ) // Draw grid lines parallel to Y axis { glBegin( GL_LINES ); glVertex3f( xmin, -(brd_center_pos.y + delta) * scale, zpos ); glVertex3f( xmax, -(brd_center_pos.y + delta) * scale, zpos ); glEnd(); if( ii != 0 ) { glBegin( GL_LINES ); glVertex3f( xmin, -(brd_center_pos.y - delta) * scale, zpos ); glVertex3f( xmax, -(brd_center_pos.y - delta) * scale, zpos ); glEnd(); } } if( ( delta > ysize / 2 ) && ( delta > xsize / 2 ) ) break; } // Draw vertical grid n Z axis glNormal3f( 0.0, -1.0, 0.0 ); // Draw vertical grid lines (parallel to Z axis) for( int ii = 0; ; ii++ ) { if( (ii % 5) ) SetGLColor( gridcolor, transparency ); else SetGLColor( gridcolor_marker, transparency ); double delta = ii * aGriSizeMM * IU_PER_MM; glBegin( GL_LINES ); glVertex3f( (brd_center_pos.x + delta) * scale, -brd_center_pos.y * scale, zmin ); glVertex3f( (brd_center_pos.x + delta) * scale, -brd_center_pos.y * scale, zmax ); glEnd(); if( ii != 0 ) { glBegin( GL_LINES ); glVertex3f( (brd_center_pos.x - delta) * scale, -brd_center_pos.y * scale, zmin ); glVertex3f( (brd_center_pos.x - delta) * scale, -brd_center_pos.y * scale, zmax ); glEnd(); } if( delta > xsize / 2 ) break; } // Draw horizontal grid lines on Z axis for( int ii = 0; ; ii++ ) { if( (ii % 5) ) SetGLColor( gridcolor, transparency); else SetGLColor( gridcolor_marker, transparency ); double delta = ii * aGriSizeMM * IU_PER_MM * scale; if( delta <= zmax ) { // Draw grid lines on Z axis (positive Z axis coordinates) glBegin( GL_LINES ); glVertex3f( xmin, -brd_center_pos.y * scale, delta ); glVertex3f( xmax, -brd_center_pos.y * scale, delta ); glEnd(); } if( delta <= -zmin && ( ii != 0 ) ) { // Draw grid lines on Z axis (negative Z axis coordinates) glBegin( GL_LINES ); glVertex3f( xmin, -brd_center_pos.y * scale, -delta ); glVertex3f( xmax, -brd_center_pos.y * scale, -delta ); glEnd(); } if( ( delta > zmax ) && ( delta > -zmin ) ) break; } } 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(); aVia->LayerPair( &top_layer, &bottom_layer ); // Drawing via hole: if( g_Parm_3D_Visu.IsRealisticMode() ) 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; Draw3D_ZaxisCylinder( aVia->GetStart(), inner_radius + thickness / 2, height, thickness, zpos, g_Parm_3D_Visu.m_BiuTo3Dunits ); } void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas, bool aAllowNonTransparentObjects, Loading Loading @@ -1706,65 +1427,6 @@ void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas, } // Draw 3D pads. void EDA_3D_CANVAS::Draw3DPadHole( const D_PAD* aPad ) { // Draw the pad hole wxSize drillsize = aPad->GetDrillSize(); bool hasHole = drillsize.x && drillsize.y; if( !hasHole ) return; // 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 ); if( g_Parm_3D_Visu.IsRealisticMode() ) SetGLCopperColor(); else SetGLColor( DARKGRAY ); int holeZpoz = g_Parm_3D_Visu.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 ); } else // Oblong hole { wxPoint ends_offset; int width; if( drillsize.x > drillsize.y ) // Horizontal oval { ends_offset.x = ( drillsize.x - drillsize.y ) / 2; width = drillsize.y; } else // Vertical oval { ends_offset.y = ( drillsize.y - drillsize.x ) / 2; width = drillsize.x; } RotatePoint( &ends_offset, aPad->GetOrientation() ); wxPoint start = aPad->GetPosition() + ends_offset; wxPoint end = aPad->GetPosition() - ends_offset; int hole_radius = ( width + thickness ) / 2; // Draw the hole Draw3D_ZaxisOblongCylinder( start, end, hole_radius, holeHeight, thickness, holeZpoz, g_Parm_3D_Visu.m_BiuTo3Dunits ); } } static bool Is3DLayerEnabled( LAYER_ID aLayer ) { DISPLAY3D_FLG flg; Loading Loading
3d-viewer/3d_canvas.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -53,7 +53,8 @@ void CheckGLError(const char *aFileName, int aLineNumber) errLast = err; wxLogError( wxT( "OpenGL error %d At: %s, line: %d" ), err, GetChars( FROM_UTF8( aFileName ) ), aLineNumber ); wxLogError( wxT( "OpenGL error %d At: %s, line: %d" ), err, GetChars( FROM_UTF8( aFileName ) ), aLineNumber ); } } Loading Loading @@ -625,7 +626,7 @@ void EDA_3D_CANVAS::TakeScreenshot( wxCommandEvent& event ) wxYield(); } struct vieport_params struct viewport_params { GLint originx; GLint originy; Loading @@ -633,6 +634,10 @@ void EDA_3D_CANVAS::TakeScreenshot( wxCommandEvent& event ) GLint y; } viewport; // Be sure we have the latest 3D view (remember 3D view is buffered) Refresh(); wxYield(); // Build image from the 3D buffer wxWindowUpdateLocker noUpdates( this ); glGetIntegerv( GL_VIEWPORT, (GLint*) &viewport ); Loading
3d-viewer/3d_canvas.h +50 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ class BOARD_DESIGN_SETTINGS; class EDA_3D_FRAME; class CPOLYGONS_LIST; class VIA; class D_PAD; Loading Loading @@ -134,15 +135,40 @@ public: void CreateDrawGL_List(); void InitGL(); void SetLights(); void SetOffset(double aPosX, double aPosY) { m_draw3dOffset.x = aPosX; m_draw3dOffset.y = aPosY; } private: /** * Helper function SetGLTechLayersColor * Initialize the color to draw the non copper layers * in realistic mode and normal mode. */ 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(); /** * Helper function SetGLEpoxyColor * Initialize the color to draw the epoxy body board in realistic mode. */ 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 ); /** * Function BuildBoard3DView * Called by CreateDrawGL_List() Loading Loading @@ -187,7 +213,31 @@ public: void Draw3DGrid( double aGriSizeMM ); void Draw3DAxis(); /** * 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 */ void Draw3DViaHole( const VIA * aVia ); /** * Helper function Draw3DPadHole: * Draw the pad hole: * Build a vertical hole (round or oblong) between the front and back layers */ void Draw3DPadHole( const D_PAD * aPad ); void GenerateFakeShadowsTextures(); Loading
3d-viewer/3d_draw.cpp +35 −373 Original line number Diff line number Diff line Loading @@ -65,44 +65,9 @@ static bool Is3DLayerEnabled( LAYER_ID aLayer ); */ static GLfloat Get3DLayer_Z_Orientation( LAYER_NUM aLayer ); /* Helper function BuildPadShapeThickOutlineAsPolygon: * Build a pad shape outline as polygon, to draw pads on silkscreen layer * with a line thickness = aWidth * Used only to draw pads outlines on silkscreen layers. */ static void BuildPadShapeThickOutlineAsPolygon( D_PAD* aPad, CPOLYGONS_LIST& aCornerBuffer, int aWidth, int aCircleToSegmentsCount, double aCorrectionFactor ) { if( aPad->GetShape() == PAD_CIRCLE ) // Draw a ring { TransformRingToPolygon( aCornerBuffer, aPad->ShapePos(), aPad->GetSize().x / 2, aCircleToSegmentsCount, aWidth ); return; } // For other shapes, draw polygon outlines CPOLYGONS_LIST corners; aPad->BuildPadShapePolygon( corners, wxSize( 0, 0 ), aCircleToSegmentsCount, aCorrectionFactor ); // Add outlines as thick segments in polygon buffer for( unsigned ii = 0, jj = corners.GetCornersCount() - 1; ii < corners.GetCornersCount(); jj = ii, ii++ ) { TransformRoundedEndsSegmentToPolygon( aCornerBuffer, corners.GetPos( jj ), corners.GetPos( ii ), aCircleToSegmentsCount, aWidth ); } } // Based on the tutorial by http://www.ulrichmierendorff.com/software/opengl_blur.html /* It will blur a openGL texture * /* Based on the tutorial http://www.ulrichmierendorff.com/software/opengl_blur.html * It will blur a openGL texture */ static void blur_tex( GLuint aTex, int aPasses, GLuint aTexture_size ) { Loading Loading @@ -297,20 +262,23 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures() { return; } m_shadow_init = true; // Init info 3d parameters and create gl lists: CreateDrawGL_List(); m_shadow_init = true; glClearColor( 0, 0, 0, 1 ); 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, 0.0, 3500000 * g_Parm_3D_Visu.m_BiuTo3Dunits ); 0.0, ZDIST_MAX ); // Render FRONT shadow glMatrixMode( GL_MODELVIEW ); Loading @@ -336,7 +304,7 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures() 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, 0.0, 6.0f * 3500000 * g_Parm_3D_Visu.m_BiuTo3Dunits ); 0.0, 6.0f * ZDIST_MAX ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); Loading Loading @@ -392,18 +360,29 @@ void EDA_3D_CANVAS::Redraw() glDisable( GL_DEPTH_TEST ); glDisable( GL_TEXTURE_2D ); // Draw the background ( rectangle with color gradient) glBegin( GL_QUADS ); glColor4f( 0.95, 0.95, 1.0, 1.0 ); glVertex2f( -1.0, 0.85 ); 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 ); glVertex2f( -1.0,-1.0 ); glVertex2f( 1.0,-1.0 ); #define BGCOLOR1(x) (x) #define BGCOLOR2(x) (x * 0.3) glColor4f( BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Red ), BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Green ), BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Blue ), 1.0 ); glVertex2f( -1.0, 1.0 ); // Top left corner glColor4f( BGCOLOR2( g_Parm_3D_Visu.m_BgColor.m_Red ), BGCOLOR2( g_Parm_3D_Visu.m_BgColor.m_Green ), BGCOLOR2( g_Parm_3D_Visu.m_BgColor.m_Blue ), 1.0 ); glVertex2f( -1.0,-1.0 ); // bottom left corner glVertex2f( 1.0,-1.0 ); // bottom right corner glColor4f( BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Red ), BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Green ), BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Blue ), 1.0 ); glVertex2f( 1.0, 1.0 ); // top right corner glColor4f( 0.95, 0.95, 1.0, 1.0 ); glVertex2f( 1.0, 0.85 ); glEnd(); glEnable( GL_DEPTH_TEST ); Loading Loading @@ -579,82 +558,8 @@ void EDA_3D_CANVAS::Redraw() glDisable( GL_CULL_FACE ); } } SwapBuffers(); } // Helper function: initialize the copper color to draw the board // in realistic mode. void EDA_3D_CANVAS::SetGLCopperColor() { glDisable( GL_TEXTURE_2D ); // Generates a golden yellow color, near board "copper" color const double lum = 0.7/255.0; glColor4f( 255.0*lum, 223.0*lum, 0.0*lum, 1.0 ); } // Helper function: initialize the color to draw the epoxy // body board in realistic mode. void EDA_3D_CANVAS::SetGLEpoxyColor( double aTransparency ) { // Generates an epoxy color, near board color const double lum = 0.2/255.0; glColor4f( 255.0*lum, 218.0*lum, 110.0*lum, aTransparency ); } // Helper function: initialize the color to draw the // solder mask layers in realistic mode. static inline void SetGLSolderMaskColor( double aTransparency = 1.0 ) { // Generates a solder mask color const double lum = 0.2/255.0; glColor4f( 100.0*lum, 255.0*lum, 180.0*lum, 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 ) { EDA_COLOR_T color; if( g_Parm_3D_Visu.IsRealisticMode() ) { switch( aLayer ) { case B_Paste: case F_Paste: SetGLColor( DARKGRAY, 0.7 ); break; case B_SilkS: case F_SilkS: SetGLColor( LIGHTGRAY, 0.9 ); if( g_Parm_3D_Visu.HightQualityMode() ) { SetGLTexture( m_text_silk, 50.0f ); } break; case B_Mask: case F_Mask: SetGLSolderMaskColor( 0.7 ); if( g_Parm_3D_Visu.HightQualityMode() ) { SetGLTexture( m_text_pcb, 35.0f ); } break; default: color = g_ColorsSettings.GetLayerColor( aLayer ); SetGLColor( color, 0.7 ); break; } } else { color = g_ColorsSettings.GetLayerColor( aLayer ); SetGLColor( color, 0.7 ); } SwapBuffers(); } Loading Loading @@ -1037,12 +942,14 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) glNewList( aBodyOnlyList, GL_COMPILE ); if( bufferPcbOutlines.GetCornersCount() ) { glColor4f( 1.0, 1.0, 1.0, 1.0 ); Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0, board_thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); } glEndList(); } Loading Loading @@ -1481,192 +1388,6 @@ void EDA_3D_CANVAS::BuildFootprintShape3DList( GLuint aOpaqueList, glEndList(); } void EDA_3D_CANVAS::Draw3DAxis() { if( ! m_glLists[GL_ID_AXIS] ) { m_glLists[GL_ID_AXIS] = glGenLists( 1 ); glNewList( m_glLists[GL_ID_AXIS], GL_COMPILE ); glEnable( GL_COLOR_MATERIAL ); SetGLColor( WHITE ); glBegin( GL_LINES ); glNormal3f( 0.0f, 0.0f, 1.0f ); // Normal is Z axis glVertex3f( 0.0f, 0.0f, 0.0f ); glVertex3f( 1.0f, 0.0f, 0.0f ); // X axis glVertex3f( 0.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, -1.0f, 0.0f ); // Y axis glNormal3f( 1.0f, 0.0f, 0.0f ); // Normal is Y axis glVertex3f( 0.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.3f ); // Z axis glEnd(); glEndList(); } } // draw a 3D grid: an horizontal grid (XY plane and Z = 0, // and a vertical grid (XZ plane and Y = 0) 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 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; NEGATE( brd_center_pos.y ); int xsize = std::max( brd_size.x, Millimeter2iu( 100 ) ); int ysize = std::max( brd_size.y, Millimeter2iu( 100 ) ); // Grid limits, in 3D units double xmin = (brd_center_pos.x - xsize / 2) * scale; double xmax = (brd_center_pos.x + xsize / 2) * scale; double ymin = (brd_center_pos.y - ysize / 2) * scale; double ymax = (brd_center_pos.y + ysize / 2) * scale; double zmin = Millimeter2iu( -50 ) * scale; double zmax = Millimeter2iu( 100 ) * scale; // Draw horizontal grid centered on 3D origin (center of the board) for( int ii = 0; ; ii++ ) { if( (ii % 5) ) SetGLColor( gridcolor, transparency ); else SetGLColor( gridcolor_marker, transparency ); int delta = KiROUND( ii * aGriSizeMM * IU_PER_MM ); if( delta <= xsize / 2 ) // Draw grid lines parallel to X axis { glBegin( GL_LINES ); glVertex3f( (brd_center_pos.x + delta) * scale, -ymin, zpos ); glVertex3f( (brd_center_pos.x + delta) * scale, -ymax, zpos ); glEnd(); if( ii != 0 ) { glBegin( GL_LINES ); glVertex3f( (brd_center_pos.x - delta) * scale, -ymin, zpos ); glVertex3f( (brd_center_pos.x - delta) * scale, -ymax, zpos ); glEnd(); } } if( delta <= ysize / 2 ) // Draw grid lines parallel to Y axis { glBegin( GL_LINES ); glVertex3f( xmin, -(brd_center_pos.y + delta) * scale, zpos ); glVertex3f( xmax, -(brd_center_pos.y + delta) * scale, zpos ); glEnd(); if( ii != 0 ) { glBegin( GL_LINES ); glVertex3f( xmin, -(brd_center_pos.y - delta) * scale, zpos ); glVertex3f( xmax, -(brd_center_pos.y - delta) * scale, zpos ); glEnd(); } } if( ( delta > ysize / 2 ) && ( delta > xsize / 2 ) ) break; } // Draw vertical grid n Z axis glNormal3f( 0.0, -1.0, 0.0 ); // Draw vertical grid lines (parallel to Z axis) for( int ii = 0; ; ii++ ) { if( (ii % 5) ) SetGLColor( gridcolor, transparency ); else SetGLColor( gridcolor_marker, transparency ); double delta = ii * aGriSizeMM * IU_PER_MM; glBegin( GL_LINES ); glVertex3f( (brd_center_pos.x + delta) * scale, -brd_center_pos.y * scale, zmin ); glVertex3f( (brd_center_pos.x + delta) * scale, -brd_center_pos.y * scale, zmax ); glEnd(); if( ii != 0 ) { glBegin( GL_LINES ); glVertex3f( (brd_center_pos.x - delta) * scale, -brd_center_pos.y * scale, zmin ); glVertex3f( (brd_center_pos.x - delta) * scale, -brd_center_pos.y * scale, zmax ); glEnd(); } if( delta > xsize / 2 ) break; } // Draw horizontal grid lines on Z axis for( int ii = 0; ; ii++ ) { if( (ii % 5) ) SetGLColor( gridcolor, transparency); else SetGLColor( gridcolor_marker, transparency ); double delta = ii * aGriSizeMM * IU_PER_MM * scale; if( delta <= zmax ) { // Draw grid lines on Z axis (positive Z axis coordinates) glBegin( GL_LINES ); glVertex3f( xmin, -brd_center_pos.y * scale, delta ); glVertex3f( xmax, -brd_center_pos.y * scale, delta ); glEnd(); } if( delta <= -zmin && ( ii != 0 ) ) { // Draw grid lines on Z axis (negative Z axis coordinates) glBegin( GL_LINES ); glVertex3f( xmin, -brd_center_pos.y * scale, -delta ); glVertex3f( xmax, -brd_center_pos.y * scale, -delta ); glEnd(); } if( ( delta > zmax ) && ( delta > -zmin ) ) break; } } 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(); aVia->LayerPair( &top_layer, &bottom_layer ); // Drawing via hole: if( g_Parm_3D_Visu.IsRealisticMode() ) 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; Draw3D_ZaxisCylinder( aVia->GetStart(), inner_radius + thickness / 2, height, thickness, zpos, g_Parm_3D_Visu.m_BiuTo3Dunits ); } void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas, bool aAllowNonTransparentObjects, Loading Loading @@ -1706,65 +1427,6 @@ void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas, } // Draw 3D pads. void EDA_3D_CANVAS::Draw3DPadHole( const D_PAD* aPad ) { // Draw the pad hole wxSize drillsize = aPad->GetDrillSize(); bool hasHole = drillsize.x && drillsize.y; if( !hasHole ) return; // 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 ); if( g_Parm_3D_Visu.IsRealisticMode() ) SetGLCopperColor(); else SetGLColor( DARKGRAY ); int holeZpoz = g_Parm_3D_Visu.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 ); } else // Oblong hole { wxPoint ends_offset; int width; if( drillsize.x > drillsize.y ) // Horizontal oval { ends_offset.x = ( drillsize.x - drillsize.y ) / 2; width = drillsize.y; } else // Vertical oval { ends_offset.y = ( drillsize.y - drillsize.x ) / 2; width = drillsize.x; } RotatePoint( &ends_offset, aPad->GetOrientation() ); wxPoint start = aPad->GetPosition() + ends_offset; wxPoint end = aPad->GetPosition() - ends_offset; int hole_radius = ( width + thickness ) / 2; // Draw the hole Draw3D_ZaxisOblongCylinder( start, end, hole_radius, holeHeight, thickness, holeZpoz, g_Parm_3D_Visu.m_BiuTo3Dunits ); } } static bool Is3DLayerEnabled( LAYER_ID aLayer ) { DISPLAY3D_FLG flg; Loading