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

Fix a few minor coverity warnings.

Fix minor 3D viewer issues (includling change number of segments and its optimization to draw pad holes.)
Fix Bug #1439132 (track and via list on toolbar not always refresh after loading a board).
Remove useless tool in Modedit.
parent 589dd442
Loading
Loading
Loading
Loading
+33 −18
Original line number Diff line number Diff line
@@ -646,14 +646,14 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
    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
    // Boost polygon (at least v1.57 and previous) in very rare cases crashes
    // when using 16 segments to approximate a circle.
    // So using 18 segments is a workaround to try to avoid these crashes
    // ( We already used this trick in plot_board_layers.cpp,
    // see PlotSolderMaskLayer() )
    const int       segcountforcircle   = 18;
    double          correctionFactor    = 1.0 / cos( M_PI / (segcountforcircle * 2.0) );
    const int       segcountLowQuality  =  8;   // segments to draw a circle with low quality
    const int       segcountLowQuality  = 12;   // segments to draw a circle with low quality
                                                // to reduce time calculations
                                                // for holes and items which do not need
                                                // a fine representation
@@ -767,13 +767,28 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,

                for( ; pad; pad = pad->Next() )
                {
                    // Calculate a factor to apply to segcount (bigger pad size -> more segments)
                    wxSize padSize = pad->GetSize();
                    int maxPadSize = glm::max( padSize.x, padSize.y );
                    float segFactor = (float)maxPadSize / (float)Millimeter2iu( 0.6 );
                    // Calculate a factor to apply to segcount for large holes ( > 1 mm)
                    // (bigger pad drill size -> more segments) because holes in pads can have
                    // very different sizes and optimizing this segcount gives a better look
                    // Mainly mounting holes have a size bigger thon 1 mm
                    wxSize padHole = pad->GetDrillSize();

                    pad->BuildPadDrillShapePolygon( allLayerHoles, 0,
                                                    (int)(segcountLowQuality * segFactor) );
                    if( ! padHole.x )       // Not drilled pad like SMD pad
                        continue;

                    // we use the hole diameter to calculate the seg count.
                    // for round holes, padHole.x == padHole.y
                    // for oblong holes, the diameter is the smaller of (padHole.x, padHole.y)
                    int diam = std::min( padHole.x, padHole.y );
                    double segFactor = (double)diam / Millimeter2iu( 1.0 );

                    int segcount = (int)(segcountLowQuality * segFactor);

                    // Clamp segcount between segcountLowQuality and 48.
                    // 48 segm for a circle is a very good approx.
                    segcount = Clamp( segcountLowQuality, segcount, 48 );

                    pad->BuildPadDrillShapePolygon( allLayerHoles, 0, segcount );
                }
            }
        }
+8 −5
Original line number Diff line number Diff line
@@ -256,12 +256,15 @@ int ParseVertex( FILE* File, glm::vec3& dst_vertex )
}


int ParseFloat( FILE* File, float* dst_float )
bool ParseFloat( FILE* aFile, float *aDstFloat, float aDefaultValue )
{
    float   value;
    int     ret = fscanf( File, "%e", &value );
    int     ret = fscanf( aFile, "%e", &value );

    *dst_float = value;
    if( ret == 1 )
        *aDstFloat = value;
    else
        *aDstFloat = aDefaultValue;

    return ret;
    return ret == 1;
}
+5 −4
Original line number Diff line number Diff line
@@ -83,11 +83,12 @@ int ParseVertex( FILE* File, glm::vec3 &dst_vertex );
/**
 * Function ParseFloat
 * parse a float value
 * @param File file to read from
 * @param dst_float destination float
 * @return int - Return the number of floats readed (0 or 1)
 * @param aFile file to read from
 * @param aDstFloat destination float
 * @param aDefaultValue = the default value, when the actual value cannot be read
 * @return bool - Return true if the float was read without error
 */
int ParseFloat( FILE* File, float *dst_float );
bool ParseFloat( FILE* aFile, float *aDstFloat, float aDefaultValue );

/**
 * Function GetNextTag
+3 −3
Original line number Diff line number Diff line
@@ -1283,7 +1283,7 @@ int VRML2_MODEL_PARSER::read_Material()
        else if( strcmp( text, "ambientIntensity" ) == 0 )
        {
            float ambientIntensity;
            ParseFloat( m_file, &ambientIntensity );
            ParseFloat( m_file, &ambientIntensity, 0.8 );

            if( m_Master->m_use_modelfile_ambientIntensity == true )
            {
@@ -1294,7 +1294,7 @@ int VRML2_MODEL_PARSER::read_Material()
        else if( strcmp( text, "transparency" ) == 0 )
        {
            float transparency;
            ParseFloat( m_file, &transparency );
            ParseFloat( m_file, &transparency, 0.0 );

            if( m_Master->m_use_modelfile_transparency == true )
            {
@@ -1304,7 +1304,7 @@ int VRML2_MODEL_PARSER::read_Material()
        else if( strcmp( text, "shininess" ) == 0 )
        {
            float shininess;
            ParseFloat( m_file, &shininess );
            ParseFloat( m_file, &shininess, 1.0 );

            // VRML value is normalized and openGL expects a value 0 - 128
            if( m_Master->m_use_modelfile_shininess == true )
+11 −6
Original line number Diff line number Diff line
@@ -455,7 +455,12 @@ void PDF_PLOTTER::closePdfStream()
    wxASSERT( workFile );

    long stream_len = ftell( workFile );
    wxASSERT( stream_len >= 0 );

    if( stream_len < 0 )
    {
        wxASSERT( false );
        return;
    }

    // Rewind the file, read in the page stream and DEFLATE it
    fseek( workFile, 0, SEEK_SET );
@@ -475,10 +480,10 @@ void PDF_PLOTTER::closePdfStream()

    {
        /* Somewhat standard parameters to compress in DEFLATE. The PDF spec is
           misleading, it says it wants a DEFLATE stream but it really want a ZLIB
           stream! (a DEFLATE stream would be generated with -15 instead of 15)
        rc = deflateInit2( &zstrm, Z_BEST_COMPRESSION, Z_DEFLATED, 15,
                               8, Z_DEFAULT_STRATEGY );
         * misleading, it says it wants a DEFLATE stream but it really want a ZLIB
         * stream! (a DEFLATE stream would be generated with -15 instead of 15)
         * rc = deflateInit2( &zstrm, Z_BEST_COMPRESSION, Z_DEFLATED, 15,
         *                    8, Z_DEFAULT_STRATEGY );
         */

        wxZlibOutputStream      zos( memos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
Loading