Commit dd64b2f2 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

3D board display: better rendering of the board: the board polygon outlines...

3D board display: better rendering of the board: the board polygon outlines (generated by the specctra function) is now used to create the 3D body of the board.
parent 964933db
Loading
Loading
Loading
Loading
+77 −25
Original line number Original line Diff line number Diff line
@@ -49,7 +49,6 @@
#include <3d_draw_basic_functions.h>
#include <3d_draw_basic_functions.h>


// Imported function:
// Imported function:
extern void     SetGLColor( EDA_COLOR_T color );
extern void     Set_Object_Data( std::vector<S3D_VERTEX>& aVertices, double aBiuTo3DUnits );
extern void     Set_Object_Data( std::vector<S3D_VERTEX>& aVertices, double aBiuTo3DUnits );
extern void     CheckGLError();
extern void     CheckGLError();


@@ -161,14 +160,28 @@ void EDA_3D_CANVAS::BuildBoard3DView()
                                                // for holes and items which do not need
                                                // for holes and items which do not need
                                                // a fine representation
                                                // a fine representation
    double          correctionFactorLQ = 1.0 / cos( M_PI / (segcountLowQuality * 2) );
    double          correctionFactorLQ = 1.0 / cos( M_PI / (segcountLowQuality * 2) );
    CPOLYGONS_LIST  bufferPolys;


    CPOLYGONS_LIST  bufferPolys;
    bufferPolys.reserve( 200000 );              // Reserve for large board (tracks mainly)
    bufferPolys.reserve( 200000 );              // Reserve for large board (tracks mainly)
    CPOLYGONS_LIST  bufferZonesPolys;

    bufferPolys.reserve( 500000 );                  // Reserve for large board ( copper zones mainly )
    CPOLYGONS_LIST  bufferPcbOutlines;          // stores the board main outlines
    CPOLYGONS_LIST  currLayerHoles;                 // Contains holes for the current layer
    CPOLYGONS_LIST  allLayerHoles;              // Contains through holes, calculated only once
    CPOLYGONS_LIST  allLayerHoles;              // Contains through holes, calculated only once
    allLayerHoles.reserve( 20000 );
    allLayerHoles.reserve( 20000 );

    // Build a polygon from edge cut items
    wxString msg;
    if( ! pcb->GetBoardPolygonOutlines( bufferPcbOutlines,
                                        allLayerHoles, &msg ) )
    {
        msg << wxT("\n\n") <<
            _("Unable to calculate the board outlines, will use the outlines boundary box");
        wxMessageBox( msg );
    }

    CPOLYGONS_LIST  bufferZonesPolys;
    bufferZonesPolys.reserve( 500000 );             // Reserve for large board ( copper zones mainly )

    CPOLYGONS_LIST  currLayerHoles;                 // Contains holes for the current layer
    bool            throughHolesListBuilt = false;  // flag to build the through hole polygon list only once
    bool            throughHolesListBuilt = false;  // flag to build the through hole polygon list only once
    bool            hightQualityMode = false;
    bool            hightQualityMode = false;


@@ -282,7 +295,8 @@ void EDA_3D_CANVAS::BuildBoard3DView()
            }
            }
        }
        }


        // bufferPolys contains polygons to merge. Many overlaps . Calculate merged polygons
        // bufferPolys contains polygons to merge. Many overlaps .
        // Calculate merged polygons
        if( bufferPolys.GetCornersCount() == 0 )
        if( bufferPolys.GetCornersCount() == 0 )
            continue;
            continue;


@@ -346,6 +360,9 @@ void EDA_3D_CANVAS::BuildBoard3DView()
        if( !g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) )
        if( !g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) )
            continue;
            continue;


        if( layer == EDGE_N )
            continue;

        bufferPolys.RemoveAllContours();
        bufferPolys.RemoveAllContours();


        for( BOARD_ITEM* item = pcb->m_Drawings; item; item = item->Next() )
        for( BOARD_ITEM* item = pcb->m_Drawings; item; item = item->Next() )
@@ -407,26 +424,29 @@ void EDA_3D_CANVAS::BuildBoard3DView()
        // Calculate merged polygons and remove pads and vias holes
        // Calculate merged polygons and remove pads and vias holes
        if( bufferPolys.GetCornersCount() == 0 )
        if( bufferPolys.GetCornersCount() == 0 )
            continue;
            continue;

        KI_POLYGON_SET  currLayerPolyset;
        KI_POLYGON_SET  currLayerPolyset;
        KI_POLYGON_SET  polyset;
        KI_POLYGON_SET  polyset;

        // Solder mask layers are "negative" layers.
        // Shapes should be removed from the full board area.
        if( layer == SOLDERMASK_N_BACK || layer == SOLDERMASK_N_FRONT )
        {
            bufferPcbOutlines.ExportTo( currLayerPolyset );
            bufferPolys.Append( allLayerHoles );
            bufferPolys.ExportTo( polyset );
            currLayerPolyset -= polyset;
        }
        else    // usuall layers, merge polys built from each item shape:
        {
            bufferPolys.ExportTo( polyset );
            bufferPolys.ExportTo( polyset );
        // merge polys:
            currLayerPolyset += polyset;
            currLayerPolyset += polyset;
        }


        EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer );
        EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer );
        int         thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer );
        int         thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer );
        int         zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer );
        int         zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer );


        if( layer == EDGE_N )
        SetGLColor( color, 0.7 );
        {
            thickness = g_Parm_3D_Visu.GetLayerZcoordBIU( LAYER_N_FRONT )
                        - g_Parm_3D_Visu.GetLayerZcoordBIU( LAYER_N_BACK );
            zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( LAYER_N_BACK )
                   + (thickness / 2);
        }

        SetGLColor( color );
        glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) );
        glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) );


        bufferPolys.RemoveAllContours();
        bufferPolys.RemoveAllContours();
@@ -435,6 +455,37 @@ void EDA_3D_CANVAS::BuildBoard3DView()
                                            thickness, g_Parm_3D_Visu.m_BiuTo3Dunits );
                                            thickness, g_Parm_3D_Visu.m_BiuTo3Dunits );
    }
    }


    // Draw board substrate:
    if( bufferPcbOutlines.GetCornersCount() )
    {
        int copper_thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( LAYER_N_BACK );
        int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( LAYER_N_BACK );
        int thickness = g_Parm_3D_Visu.GetLayerZcoordBIU( LAYER_N_FRONT )
                        - g_Parm_3D_Visu.GetLayerZcoordBIU( LAYER_N_BACK );
        zpos += (thickness/2) + (copper_thickness/2);
        thickness -= copper_thickness;
        EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( EDGE_N );
        SetGLColor( color, 0.8 );
        glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( LAYER_N_FRONT ) );
        KI_POLYGON_SET  currLayerPolyset;
        KI_POLYGON_SET  polysetHoles;

        // Add polygons, without holes
        bufferPcbOutlines.ExportTo( currLayerPolyset );

        // Build holes list
        allLayerHoles.ExportTo( polysetHoles );

        // remove holes
        currLayerPolyset -= polysetHoles;

        bufferPcbOutlines.RemoveAllContours();
        bufferPcbOutlines.ImportFrom( currLayerPolyset );

        Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos,
                                            thickness, g_Parm_3D_Visu.m_BiuTo3Dunits );
    }

    // draw modules 3D shapes
    // draw modules 3D shapes
    for( MODULE* module = pcb->m_Modules; module != NULL; module = module->Next() )
    for( MODULE* module = pcb->m_Modules; module != NULL; module = module->Next() )
        module->ReadAndInsert3DComponentShape( this );
        module->ReadAndInsert3DComponentShape( this );
@@ -517,6 +568,7 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM )
    EDA_COLOR_T gridcolor = DARKGRAY;           // Color of grid lines
    EDA_COLOR_T gridcolor = DARKGRAY;           // Color of grid lines
    EDA_COLOR_T gridcolor_marker = LIGHTGRAY;   // Color of grid lines every 5 lines
    EDA_COLOR_T gridcolor_marker = LIGHTGRAY;   // Color of grid lines every 5 lines
    double      scale = g_Parm_3D_Visu.m_BiuTo3Dunits;
    double      scale = g_Parm_3D_Visu.m_BiuTo3Dunits;
    double transparency = 0.4;


    glNormal3f( 0.0, 0.0, 1.0 );
    glNormal3f( 0.0, 0.0, 1.0 );


@@ -539,9 +591,9 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM )
    for( int ii = 0; ; ii++ )
    for( int ii = 0; ; ii++ )
    {
    {
        if( (ii % 5) )
        if( (ii % 5) )
            SetGLColor( gridcolor );
            SetGLColor( gridcolor, transparency );
        else
        else
            SetGLColor( gridcolor_marker );
            SetGLColor( gridcolor_marker, transparency );


        int delta = KiROUND( ii * aGriSizeMM * IU_PER_MM );
        int delta = KiROUND( ii * aGriSizeMM * IU_PER_MM );


@@ -588,9 +640,9 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM )
    for( int ii = 0; ; ii++ )
    for( int ii = 0; ; ii++ )
    {
    {
        if( (ii % 5) )
        if( (ii % 5) )
            SetGLColor( gridcolor );
            SetGLColor( gridcolor, transparency );
        else
        else
            SetGLColor( gridcolor_marker );
            SetGLColor( gridcolor_marker, transparency );


        double delta = ii * aGriSizeMM * IU_PER_MM;
        double delta = ii * aGriSizeMM * IU_PER_MM;


@@ -615,9 +667,9 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM )
    for( int ii = 0; ; ii++ )
    for( int ii = 0; ; ii++ )
    {
    {
        if( (ii % 5) )
        if( (ii % 5) )
            SetGLColor( gridcolor );
            SetGLColor( gridcolor, transparency);
        else
        else
            SetGLColor( gridcolor_marker );
            SetGLColor( gridcolor_marker, transparency );


        double delta = ii * aGriSizeMM * IU_PER_MM * scale;
        double delta = ii * aGriSizeMM * IU_PER_MM * scale;


+2 −3
Original line number Original line Diff line number Diff line
@@ -34,7 +34,6 @@
#include <info3d_visu.h>
#include <info3d_visu.h>
#include <3d_draw_basic_functions.h>
#include <3d_draw_basic_functions.h>



// Imported function:
// Imported function:
extern void Set_Object_Data( std::vector<S3D_VERTEX>& aVertices, double aBiuTo3DUnits );
extern void Set_Object_Data( std::vector<S3D_VERTEX>& aVertices, double aBiuTo3DUnits );
extern void CheckGLError();
extern void CheckGLError();
@@ -122,7 +121,7 @@ static void Draw3D_VerticalPolygonalCylinder( const CPOLYGONS_LIST& aPolysList,
}
}




void SetGLColor( EDA_COLOR_T color )
void SetGLColor( EDA_COLOR_T color, double alpha )
{
{
    double              red, green, blue;
    double              red, green, blue;
    const StructColors &colordata = g_ColorRefs[ColorGetBase( color )];
    const StructColors &colordata = g_ColorRefs[ColorGetBase( color )];
@@ -130,7 +129,7 @@ void SetGLColor( EDA_COLOR_T color )
    red     = colordata.m_Red / 255.0;
    red     = colordata.m_Red / 255.0;
    blue    = colordata.m_Blue / 255.0;
    blue    = colordata.m_Blue / 255.0;
    green   = colordata.m_Green / 255.0;
    green   = colordata.m_Green / 255.0;
    glColor3f( red, green, blue );
    glColor4f( red, green, blue, alpha );
}
}




+7 −0
Original line number Original line Diff line number Diff line
@@ -118,5 +118,12 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius,
void    Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,
void    Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,
                                    int aRadius, int aHeight, int aThickness,
                                    int aRadius, int aHeight, int aThickness,
                                    int aZpos, double aBiuTo3DUnits  );
                                    int aZpos, double aBiuTo3DUnits  );
/**
 * Set the current 3D color from a Kicad  color, with optional transparency
 * @param aColor = a EDA_COLOR_T kicad color index
 * @param aTransparency = the color transparency (default = 1.0 = no transparency)
 */
void SetGLColor( EDA_COLOR_T aColor, double aTransparency = 1.0 );



#endif      // _3D_DRAW_BASIC_FUNCTIONS_H_
#endif      // _3D_DRAW_BASIC_FUNCTIONS_H_
+4 −4
Original line number Original line Diff line number Diff line
@@ -67,6 +67,10 @@ bool GERBER_PLOTTER::StartPlot()
    if( outputFile == NULL )
    if( outputFile == NULL )
        return false;
        return false;


    /* Set coordinate format to 3.4 absolute, leading zero omitted */
    fputs( "%FSLAX34Y34*%\n", outputFile );
    fputs( "G04 Gerber Fmt 3.4, Leading zero omitted, Abs format*\n", outputFile );

    wxString Title = creator + wxT( " " ) + GetBuildVersion();
    wxString Title = creator + wxT( " " ) + GetBuildVersion();
    fprintf( outputFile, "G04 (created by %s) date %s*\n",
    fprintf( outputFile, "G04 (created by %s) date %s*\n",
             TO_UTF8( Title ), TO_UTF8( DateAndTime() ) );
             TO_UTF8( Title ), TO_UTF8( DateAndTime() ) );
@@ -74,10 +78,6 @@ bool GERBER_PLOTTER::StartPlot()
    /* Mass parameter: unit = INCHES */
    /* Mass parameter: unit = INCHES */
    fputs( "%MOIN*%\n", outputFile );
    fputs( "%MOIN*%\n", outputFile );


    /* Set coordinate format to 3.4 absolute, leading zero omitted */
    fputs( "G04 Gerber Fmt 3.4, Leading zero omitted, Abs format*\n%FSLAX34Y34*%\n",
           outputFile );

    /* Specify linear interpol (G01), unit = INCH (G70), abs format (G90) */
    /* Specify linear interpol (G01), unit = INCH (G70), abs format (G90) */
    fputs( "G01*\nG70*\nG90*\n", outputFile );
    fputs( "G01*\nG70*\nG90*\n", outputFile );
    fputs( "G04 APERTURE LIST*\n", outputFile );
    fputs( "G04 APERTURE LIST*\n", outputFile );
+3 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,9 @@ set( CVPCB_SRCS
    ../common/base_units.cpp
    ../common/base_units.cpp
    ../pcbnew/board_items_to_polygon_shape_transform.cpp
    ../pcbnew/board_items_to_polygon_shape_transform.cpp
    ../pcbnew/class_drc_item.cpp
    ../pcbnew/class_drc_item.cpp
    ../pcbnew/specctra.cpp
    ../pcbnew/specctra_export.cpp
    ../pcbnew/specctra_keywords.cpp
    autosel.cpp
    autosel.cpp
    cfg.cpp
    cfg.cpp
    class_components_listbox.cpp
    class_components_listbox.cpp
Loading