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

3d-viewer: code cleaning; bitmap2component: minor fix and code cleanup

parent eec819a2
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -488,7 +488,7 @@ void EDA_3D_CANVAS::Redraw()
    glMateriali ( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value );
    glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.x );

    if( isEnabled( FL_RENDER_TEXTURES ) && isRealisticMode() )
    if( isRealisticMode() && isEnabled( FL_RENDER_TEXTURES ) )
    {
    	glEnable( GL_TEXTURE_2D );
	}
@@ -684,6 +684,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
    bool remove_Holes = isEnabled( FL_RENDER_SHOW_HOLES_IN_ZONES );

    bool realistic_mode = isRealisticMode();
    bool useTextures = isRealisticMode() && isEnabled( FL_RENDER_TEXTURES );

    // Number of segments to convert a circle to polygon
    // Boost polygon (at least v 1.54, v1.55 and previous) in very rare cases crashes
@@ -886,7 +887,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
        bufferPolys.ImportFrom( currLayerPolyset );
        Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos,
                                            thickness,
                                            GetPrm3DVisu().m_BiuTo3Dunits );
                                            GetPrm3DVisu().m_BiuTo3Dunits, useTextures );

        if( isEnabled( FL_USE_COPPER_THICKNESS ) == true )
        {
@@ -898,7 +899,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
        if( bufferZonesPolys.GetCornersCount() )
            Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos,
                                                thickness,
                                                GetPrm3DVisu().m_BiuTo3Dunits );
                                                GetPrm3DVisu().m_BiuTo3Dunits, useTextures );
        throughHolesListBuilt = true;
    }

@@ -973,7 +974,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
    if( bufferPcbOutlines.GetCornersCount() )
    {
        Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0,
                                            board_thickness, GetPrm3DVisu().m_BiuTo3Dunits );
                                            board_thickness, GetPrm3DVisu().m_BiuTo3Dunits, useTextures );
    }

    glEndList();
@@ -983,6 +984,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
void EDA_3D_CANVAS::BuildTechLayers3DView()
{
    BOARD* pcb = GetBoard();
    bool useTextures = isRealisticMode() && isEnabled( FL_RENDER_TEXTURES );

    // Number of segments to draw a circle using segments
    const int       segcountforcircle   = 18;
@@ -1185,7 +1187,7 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
        setGLTechLayersColor( layer );
        glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) );
        Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos,
                                            thickness, GetPrm3DVisu().m_BiuTo3Dunits );
                thickness, GetPrm3DVisu().m_BiuTo3Dunits, useTextures );
    }
}

@@ -1287,7 +1289,7 @@ void EDA_3D_CANVAS::BuildBoard3DAuxLayers()
        setGLTechLayersColor( layer );
        glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) );
        Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos,
                                            thickness, GetPrm3DVisu().m_BiuTo3Dunits );
                                            thickness, GetPrm3DVisu().m_BiuTo3Dunits, false );
    }
}

+27 −20
Original line number Diff line number Diff line
@@ -42,6 +42,12 @@
#define CALLBACK
#endif

// Variables used to pass a value to call back openGL functions
static float s_textureScale;
static double s_currentZpos;
static double s_biuTo3Dunits;
bool s_useTextures;

// CALLBACK functions for GLU_TESS
static void CALLBACK    tessBeginCB( GLenum which );
static void CALLBACK    tessEndCB();
@@ -136,13 +142,11 @@ void SetGLColor( S3D_COLOR& aColor, float aTransparency )
}


static float m_texture_scale;

void SetGLTexture( GLuint text_id, float scale )
{
    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, text_id );
    m_texture_scale = scale;
    s_textureScale = scale;     // for Tess callback functions
}


@@ -155,8 +159,13 @@ void SetGLTexture( GLuint text_id, float scale )
 *  The bottom side is located at aZpos - aThickness / 2
 */
void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
                                         int aZpos, int aThickness, double aBiuTo3DUnits )
                                         int aZpos, int aThickness, double aBiuTo3DUnits,
                                         bool aUseTextures )
{
    // for Tess callback functions:
    s_biuTo3Dunits = aBiuTo3DUnits;
    s_useTextures = aUseTextures;

    GLUtesselator* tess = gluNewTess();

    gluTessCallback( tess, GLU_TESS_BEGIN, ( void (CALLBACK*) () )tessBeginCB );
@@ -166,7 +175,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,

    GLdouble    v_data[3];
    double      zpos = ( aZpos + (aThickness / 2.0) ) * aBiuTo3DUnits;
    g_Parm_3D_Visu.m_CurrentZpos = zpos;
    s_currentZpos = zpos;     // for Tess callback functions
    v_data[2] = aZpos + (aThickness / 2.0);

    // Set normal toward positive Z axis, for a solid object on the top side
@@ -219,7 +228,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,

        // Prepare the bottom side of solid areas
        zpos = ( aZpos - (aThickness / 2.0) ) * aBiuTo3DUnits;
        g_Parm_3D_Visu.m_CurrentZpos = zpos;
        s_currentZpos = zpos;     // for Tess callback functions
        v_data[2] = zpos;
        // Set normal toward negative Z axis, for a solid object on bottom side
        SetNormalZneg();
@@ -249,12 +258,12 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
 */
void Draw3D_SolidHorizontalPolygonWithHoles( const CPOLYGONS_LIST& aPolysList,
                                             int aZpos, int aThickness,
                                             double aBiuTo3DUnits )
                                             double aBiuTo3DUnits, bool aUseTextures )
{
    CPOLYGONS_LIST polygon;

    ConvertPolysListWithHolesToOnePolygon( aPolysList, polygon );
    Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, aThickness, aBiuTo3DUnits );
    Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, aThickness, aBiuTo3DUnits, aUseTextures );
}


@@ -301,13 +310,13 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius,

        ConvertPolysListWithHolesToOnePolygon( outer_cornerBuffer, polygon );
        // draw top (front) horizontal ring
        Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits );
        Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits, false );

        if( aHeight )
        {
            // draw bottom (back) horizontal ring
            SetNormalZneg();
            Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits );
            Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits, false );
        }
    }

@@ -361,13 +370,13 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,

        // draw top (front) horizontal side (ring)
        SetNormalZpos();
        Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits );
        Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits, false );

        if( aHeight )
        {
            // draw bottom (back) horizontal side (ring)
            SetNormalZneg();
            Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits );
            Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits, false );
        }
    }

@@ -389,7 +398,7 @@ void Draw3D_SolidSegment( const wxPoint& aStart, const wxPoint& aEnd,

    TransformRoundedEndsSegmentToPolygon( cornerBuffer, aStart, aEnd, slice, aWidth );

    Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits );
    Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits, false );
}


@@ -403,7 +412,7 @@ void Draw3D_ArcSegment( const wxPoint& aCenterPos, const wxPoint& aStartPoint,
    TransformArcToPolygon( cornerBuffer, aCenterPos, aStartPoint, aArcAngle,
                           slice, aWidth );

    Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits );
    Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits, false );
}


@@ -428,15 +437,13 @@ void CALLBACK tessCPolyPt2Vertex( const GLvoid* data )
    // cast back to double type
    const CPolyPt* ptr = (const CPolyPt*) data;

    if( g_Parm_3D_Visu.IsRealisticMode() && g_Parm_3D_Visu.GetFlag( FL_RENDER_TEXTURES ) )
    if( s_useTextures )
    {
        glTexCoord2f( ptr->x* g_Parm_3D_Visu.m_BiuTo3Dunits * m_texture_scale,
                      -ptr->y * g_Parm_3D_Visu.m_BiuTo3Dunits * m_texture_scale);
        glTexCoord2f( ptr->x * s_biuTo3Dunits * s_textureScale,
                      -ptr->y * s_biuTo3Dunits * s_textureScale);
    }

    glVertex3d( ptr->x * g_Parm_3D_Visu.m_BiuTo3Dunits,
                -ptr->y * g_Parm_3D_Visu.m_BiuTo3Dunits,
                g_Parm_3D_Visu.m_CurrentZpos );
    glVertex3d( ptr->x * s_biuTo3Dunits, -ptr->y * s_biuTo3Dunits, s_currentZpos );
}


+6 −2
Original line number Diff line number Diff line
@@ -36,13 +36,15 @@
 * @param aZpos = z position in board internal units
 * @param aThickness = thickness in board internal units
 * @param aBiuTo3DUnits = board internal units to 3D units scaling value
 * @param aUseTextures = true to use textxures for the polygons
 * If aThickness = 0, a polygon area is drawn in a XY plane at Z position = aZpos.
 * If aThickness > 0, a solid object is drawn.
 *  The top side is located at aZpos + aThickness / 2
 *  The bottom side is located at aZpos - aThickness / 2
 */
void    Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
                                            int aZpos, int aThickness, double aBiuTo3DUnits );
                                            int aZpos, int aThickness, double aBiuTo3DUnits,
                                            bool aUseTextures );

/** draw the solid polygon found in aPolysList
 * The first polygonj is the main polygon, others are holes
@@ -50,13 +52,15 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
 * @param aZpos = z position in board internal units
 * @param aThickness = thickness in board internal units
 * @param aBiuTo3DUnits = board internal units to 3D units scaling value
 * @param aUseTextures = true to use textxures for the polygons
 * If aThickness = 0, a polygon area is drawn in a XY plane at Z position = aZpos.
 * If aThickness > 0, a solid object is drawn.
 *  The top side is located at aZpos + aThickness / 2
 *  The bottom side is located at aZpos - aThickness / 2
 */
void    Draw3D_SolidHorizontalPolygonWithHoles( const CPOLYGONS_LIST& aPolysList,
                                                int aZpos, int aThickness, double aBiuTo3DUnits );
                                                int aZpos, int aThickness, double aBiuTo3DUnits,
                                                bool aUseTextures );

/** draw a thick segment using 3D primitives, in a XY plane
 * @param aStart = YX position of start point in board units
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@

#ifdef USE_OPENMP
#include <omp.h>
#endif /* USE_OPENMP */
#endif  // USE_OPENMP

S3D_MESH::S3D_MESH()
{
+1 −3
Original line number Diff line number Diff line
@@ -104,9 +104,7 @@ public:

    double  m_BiuTo3Dunits;                         // Normalization scale to convert board
                                                    // internal units to 3D units
                                                    // to scale 3D units between -1.0 and +1.0
    double  m_CurrentZpos;                          // temporary storage of current value of Z position,
                                                    // used in some calculation
                                                    // to normalize 3D units between -1.0 and +1.0

    double zpos_offset;

Loading