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

Add patch from Mario Luzeiro to 3D viewer. Fix a serious issue due to...

Add patch from Mario Luzeiro to 3D viewer. Fix a serious issue due to duplicate ID used in menus and toolbars between sub-applications, related to wxUpdateUIEvent events loop.
wxUpdateUIEvent events can be sent to parent frames, when opening a menu in a child frame, if parent and child frame share same ID fro menuitems (or tools)
The wrong menuitem can be used in some cases ( because there are more than one menuitem with the same identifier), by a wxUpdateUIEvent event function run in a parent frame.
parent 12229246
Loading
Loading
Loading
Loading
+16 −9
Original line number Original line Diff line number Diff line
@@ -520,8 +520,8 @@ GLuint load_and_generate_texture( tsImage *image )


    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    return texture;
    return texture;
@@ -547,7 +547,7 @@ void EDA_3D_CANVAS::InitGL()
        glEnable( GL_ALPHA_TEST );
        glEnable( GL_ALPHA_TEST );
        glEnable( GL_LINE_SMOOTH );
        glEnable( GL_LINE_SMOOTH );
//        glEnable(GL_POLYGON_SMOOTH);  // creates issues with some graphic cards
//        glEnable(GL_POLYGON_SMOOTH);  // creates issues with some graphic cards
        glShadeModel( GL_SMOOTH );
        glEnable( GL_NORMALIZE );
        glEnable( GL_COLOR_MATERIAL );
        glEnable( GL_COLOR_MATERIAL );
        glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
        glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );


@@ -569,7 +569,7 @@ void EDA_3D_CANVAS::SetLights()
{
{
    /* set viewing projection */
    /* set viewing projection */
    GLfloat Z_axis_pos[4]    = { 0.0, 0.0, 30.0, 0.0 };
    GLfloat Z_axis_pos[4]    = { 0.0, 0.0, 30.0, 0.0 };
    GLfloat lowZ_axis_pos[4] = { 0.0, 0.0, -30.0, 0.5 };
//    GLfloat lowZ_axis_pos[4] = { 0.0, 0.0, -30.0, 0.5 };


    // activate lights. 2 lights are used:
    // activate lights. 2 lights are used:
    // One is above the xy plane, the other is below the xy plane
    // One is above the xy plane, the other is below the xy plane
@@ -577,14 +577,21 @@ void EDA_3D_CANVAS::SetLights()
    light_color[3] = 1.0;
    light_color[3] = 1.0;


    // Light above the xy plane
    // Light above the xy plane
    // The default setting for GL_AMBIENT light intensity is (0.0, 0.0, 0.0, 1.0)
    light_color[0] = light_color[1] = light_color[2] = 0.1;
    glLightfv( GL_LIGHT0, GL_POSITION, Z_axis_pos );
    glLightfv( GL_LIGHT0, GL_AMBIENT, light_color );

    light_color[0] = light_color[1] = light_color[2] = 1.0;
    light_color[0] = light_color[1] = light_color[2] = 1.0;
    glLightfv( GL_LIGHT0, GL_DIFFUSE, light_color );
    glLightfv( GL_LIGHT0, GL_DIFFUSE, light_color );


    light_color[0] = light_color[1] = light_color[2] = 0.2;
    light_color[0] = light_color[1] = light_color[2] = 1.0;
    glLightfv( GL_LIGHT0, GL_SPECULAR, light_color );
    glLightfv( GL_LIGHT0, GL_SPECULAR, light_color );


    glLightfv( GL_LIGHT0, GL_POSITION, Z_axis_pos );

    light_color[0] = light_color[1] = light_color[2] = 0.1;
    glLightModelfv( GL_LIGHT_MODEL_AMBIENT, light_color );

/*
    // Light below the xy plane
    // Light below the xy plane
    glLightfv( GL_LIGHT1, GL_POSITION, lowZ_axis_pos );
    glLightfv( GL_LIGHT1, GL_POSITION, lowZ_axis_pos );
    light_color[0] = light_color[1] = light_color[2] = 0.4;
    light_color[0] = light_color[1] = light_color[2] = 0.4;
@@ -592,9 +599,9 @@ void EDA_3D_CANVAS::SetLights()


    light_color[0] = light_color[1] = light_color[2] = 0.1;
    light_color[0] = light_color[1] = light_color[2] = 0.1;
    glLightfv( GL_LIGHT1, GL_SPECULAR, light_color );
    glLightfv( GL_LIGHT1, GL_SPECULAR, light_color );

*/
    glEnable( GL_LIGHT0 );      // White spot on Z axis ( top )
    glEnable( GL_LIGHT0 );      // White spot on Z axis ( top )
//    glEnable( GL_LIGHT1 );      // White spot on Z axis ( bottom )
    glDisable( GL_LIGHT1 );      // White spot on Z axis ( bottom )
    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHTING );
}
}


+100 −59
Original line number Original line Diff line number Diff line
@@ -109,8 +109,8 @@ static void blur_tex( GLuint aTex, int aPasses, GLuint aTexture_size )


    glEnable( GL_TEXTURE_2D );
    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, aTex );
    glBindTexture( GL_TEXTURE_2D, aTex );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );


    while (aPasses > 0)
    while (aPasses > 0)
    {
    {
@@ -172,7 +172,7 @@ void EDA_3D_CANVAS::Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture,
    {
    {
        if( m_glLists[GL_ID_BODY] )
        if( m_glLists[GL_ID_BODY] )
        {
        {
            glCallList( m_glLists[GL_ID_BOARD] );
            glCallList( m_glLists[GL_ID_BODY] );
        }
        }
    }
    }


@@ -311,7 +311,7 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures()
    glTranslatef( 0, 0, -0.4f );
    glTranslatef( 0, 0, -0.4f );
    glRotatef( 180.0, 0.0, 1.0, 0.0 );
    glRotatef( 180.0, 0.0, 1.0, 0.0 );


    Create_and_Render_Shadow_Buffer( &m_text_fake_shadow_board, 512, true, 10 );
    Create_and_Render_Shadow_Buffer( &m_text_fake_shadow_board, 512, true, 20 );
}
}




@@ -334,7 +334,7 @@ void EDA_3D_CANVAS::Redraw()
    InitGL();
    InitGL();


    if( g_Parm_3D_Visu.GetFlag( FL_MODULE ) && g_Parm_3D_Visu.IsRealisticMode() &&
    if( g_Parm_3D_Visu.GetFlag( FL_MODULE ) && g_Parm_3D_Visu.IsRealisticMode() &&
        g_Parm_3D_Visu.HightQualityMode() )
        g_Parm_3D_Visu.GetFlag( FL_RENDER_SHADOWS ) )
    {
    {
        GenerateFakeShadowsTextures();
        GenerateFakeShadowsTextures();
    }
    }
@@ -348,6 +348,15 @@ void EDA_3D_CANVAS::Redraw()
    glClearDepth( 1.0 );
    glClearDepth( 1.0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );


	if( g_Parm_3D_Visu.GetFlag( FL_RENDER_SMOOTH ) )
	{
		glShadeModel( GL_SMOOTH );
	}
	else
	{
		glShadeModel( GL_FLAT );
	}

    // Draw background
    // Draw background
    glMatrixMode( GL_PROJECTION );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glLoadIdentity();
@@ -362,24 +371,22 @@ void EDA_3D_CANVAS::Redraw()


    // Draw the background ( rectangle with color gradient)
    // Draw the background ( rectangle with color gradient)
    glBegin( GL_QUADS );
    glBegin( GL_QUADS );
    #define BGCOLOR1(x) (x)
    glColor4f( g_Parm_3D_Visu.m_BgColor_Top.m_Red,
    #define BGCOLOR2(x) (x * 0.3)
               g_Parm_3D_Visu.m_BgColor_Top.m_Green,
    glColor4f( BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Red ),
               g_Parm_3D_Visu.m_BgColor_Top.m_Blue,
               BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Green ),
               BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Blue  ),
               1.0 );
               1.0 );
    glVertex2f( -1.0, 1.0 );    // Top left corner
    glVertex2f( -1.0, 1.0 );    // Top left corner


    glColor4f( BGCOLOR2( g_Parm_3D_Visu.m_BgColor.m_Red ),
    glColor4f( g_Parm_3D_Visu.m_BgColor.m_Red,
               BGCOLOR2( g_Parm_3D_Visu.m_BgColor.m_Green ),
               g_Parm_3D_Visu.m_BgColor.m_Green,
               BGCOLOR2( g_Parm_3D_Visu.m_BgColor.m_Blue ),
               g_Parm_3D_Visu.m_BgColor.m_Blue,
               1.0 );
               1.0 );
    glVertex2f( -1.0,-1.0 );    // bottom left corner
    glVertex2f( -1.0,-1.0 );    // bottom left corner
    glVertex2f( 1.0,-1.0 );     // bottom right corner
    glVertex2f( 1.0,-1.0 );     // bottom right corner


    glColor4f( BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Red ),
    glColor4f( g_Parm_3D_Visu.m_BgColor_Top.m_Red,
               BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Green ),
               g_Parm_3D_Visu.m_BgColor_Top.m_Green,
               BGCOLOR1( g_Parm_3D_Visu.m_BgColor.m_Blue  ),
               g_Parm_3D_Visu.m_BgColor_Top.m_Blue,
               1.0 );
               1.0 );
    glVertex2f( 1.0, 1.0 );     // top right corner
    glVertex2f( 1.0, 1.0 );     // top right corner


@@ -403,7 +410,7 @@ void EDA_3D_CANVAS::Redraw()


         // Initialize Projection Matrix for Ortographic View
         // Initialize Projection Matrix for Ortographic View
         glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor,
         glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor,
                  -size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 10 );
                  -size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 100 );
     }
     }
     else
     else
     {
     {
@@ -411,7 +418,7 @@ void EDA_3D_CANVAS::Redraw()
         double ratio_HV = (double) size.x / size.y;
         double ratio_HV = (double) size.x / size.y;


         // Initialize Projection Matrix for Perspective View
         // Initialize Projection Matrix for Perspective View
         gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 10 );
         gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 100 );
     }
     }


    // position viewer
    // position viewer
@@ -460,17 +467,56 @@ void EDA_3D_CANVAS::Redraw()
            CreateDrawGL_List();
            CreateDrawGL_List();
    }
    }


    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );


	if( g_Parm_3D_Visu.GetFlag( FL_SHOW_BOARD_BODY ) )
	{
		if( g_Parm_3D_Visu.GetFlag( FL_SOLDERMASK ) )
		{
			glDisable( GL_TEXTURE_2D );
			glDisable( GL_TEXTURE_2D );
		}
		else
		{
			glEnable( GL_TEXTURE_2D );
		}

		glDisable( GL_LIGHTING );

		if( m_glLists[GL_ID_BODY] )
		{
			glCallList( m_glLists[GL_ID_BODY] );
		}

		glEnable( GL_LIGHTING );
	}

	glEnable( GL_COLOR_MATERIAL );
	glEnable( GL_COLOR_MATERIAL );
	SetOpenGlDefaultMaterial();
	SetOpenGlDefaultMaterial();
    glColor4f( 1.0, 1.0, 1.0, 1.0 );
    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 );
    GLint shininess_value = 8;

    glMateriali ( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value );
    glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.x );

    if( g_Parm_3D_Visu.GetFlag( FL_RENDER_TEXTURES ) )
    {
    	glEnable( GL_TEXTURE_2D );
	}
	else
	{
		glDisable( GL_TEXTURE_2D );
	}


    if( m_glLists[GL_ID_BOARD] )
    if( m_glLists[GL_ID_BOARD] )
    {
    {
        glCallList( m_glLists[GL_ID_BOARD] );
        glCallList( m_glLists[GL_ID_BOARD] );
    }
    }


	SetOpenGlDefaultMaterial();

    if( m_glLists[GL_ID_TECH_LAYERS] )
    if( m_glLists[GL_ID_TECH_LAYERS] )
    {
    {
        glCallList( m_glLists[GL_ID_TECH_LAYERS] );
        glCallList( m_glLists[GL_ID_TECH_LAYERS] );
@@ -485,7 +531,9 @@ void EDA_3D_CANVAS::Redraw()
    }
    }


    // Draw Component Shadow
    // Draw Component Shadow
    if( g_Parm_3D_Visu.GetFlag( FL_MODULE )  && g_Parm_3D_Visu.IsRealisticMode() && g_Parm_3D_Visu.HightQualityMode() )
    if( g_Parm_3D_Visu.GetFlag( FL_MODULE )  &&
        g_Parm_3D_Visu.IsRealisticMode() &&
        g_Parm_3D_Visu.GetFlag( FL_RENDER_SHADOWS ) )
    {
    {
        glEnable( GL_CULL_FACE );
        glEnable( GL_CULL_FACE );
        glDisable( GL_DEPTH_TEST );
        glDisable( GL_DEPTH_TEST );
@@ -546,7 +594,9 @@ void EDA_3D_CANVAS::Redraw()
        glCallList( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] );
        glCallList( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] );


    // Draw Board Shadow
    // Draw Board Shadow
    if( g_Parm_3D_Visu.GetFlag( FL_MODULE ) && g_Parm_3D_Visu.IsRealisticMode() && g_Parm_3D_Visu.HightQualityMode() )
    if( g_Parm_3D_Visu.GetFlag( FL_MODULE ) &&
        g_Parm_3D_Visu.IsRealisticMode() &&
        g_Parm_3D_Visu.GetFlag( FL_RENDER_SHADOWS ) )
    {
    {
        if( m_glLists[GL_ID_SHADOW_BOARD] )
        if( m_glLists[GL_ID_SHADOW_BOARD] )
        {
        {
@@ -643,10 +693,10 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
{
{
    BOARD* pcb = GetBoard();
    BOARD* pcb = GetBoard();


    // If hightQualityMode is true, holes are correctly removed from copper zones areas.
    // If FL_RENDER_SHOW_HOLES_IN_ZONES is true, holes are correctly removed from copper zones areas.
    // If hightQualityMode is false, holes are not removed from copper zones areas,
    // If FL_RENDER_SHOW_HOLES_IN_ZONES is false, holes are not removed from copper zones areas,
    // but the calculation time is twice shorter.
    // but the calculation time is twice shorter.
    bool hightQualityMode = g_Parm_3D_Visu.HightQualityMode();
    bool remove_Holes = g_Parm_3D_Visu.GetFlag( FL_RENDER_SHOW_HOLES_IN_ZONES );


    bool realistic_mode = g_Parm_3D_Visu.IsRealisticMode();
    bool realistic_mode = g_Parm_3D_Visu.IsRealisticMode();


@@ -783,7 +833,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
                if( zonelayer == layer )
                if( zonelayer == layer )
                {
                {
                    zone->TransformSolidAreasShapesToPolygonSet(
                    zone->TransformSolidAreasShapesToPolygonSet(
                        hightQualityMode ? bufferPolys : bufferZonesPolys,
                        remove_Holes ? bufferPolys : bufferZonesPolys,
                        segcountLowQuality, correctionFactorLQ );
                        segcountLowQuality, correctionFactorLQ );
                }
                }
            }
            }
@@ -853,6 +903,13 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
                                            thickness,
                                            thickness,
                                            g_Parm_3D_Visu.m_BiuTo3Dunits );
                                            g_Parm_3D_Visu.m_BiuTo3Dunits );


        if( g_Parm_3D_Visu.GetFlag( FL_USE_COPPER_THICKNESS ) == true )
        {
        	thickness -= ( 0.04 * IU_PER_MM );
        }

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

        if( bufferZonesPolys.GetCornersCount() )
        if( bufferZonesPolys.GetCornersCount() )
            Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos,
            Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos,
                                                thickness,
                                                thickness,
@@ -881,13 +938,14 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
        }
        }
    }
    }


	glEndList();


	glNewList( aBodyOnlyList, GL_COMPILE );

    if( g_Parm_3D_Visu.IsRealisticMode() )
    if( g_Parm_3D_Visu.IsRealisticMode() )
    {
    {
        SetGLEpoxyColor( 1.0 );
    	SetGLEpoxyColor( 0.95 );
        if( g_Parm_3D_Visu.HightQualityMode() )
        {
            SetGLTexture( m_text_pcb, 35.0f );
        }
    }
    }
    else
    else
    {
    {
@@ -927,25 +985,8 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
    bufferPcbOutlines.RemoveAllContours();
    bufferPcbOutlines.RemoveAllContours();
    bufferPcbOutlines.ImportFrom( currLayerPolyset );
    bufferPcbOutlines.ImportFrom( currLayerPolyset );


    // Draw board substrate:
    if( bufferPcbOutlines.GetCornersCount() &&
        ( g_Parm_3D_Visu.GetFlag( FL_SHOW_BOARD_BODY ) ) )
    {

        // for Draw3D_SolidHorizontalPolyPolygons, zpos it the middle between bottom and top
        // sides
        Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0,
                                            board_thickness, g_Parm_3D_Visu.m_BiuTo3Dunits );
    }

    glEndList();


    glNewList( aBodyOnlyList, GL_COMPILE );

    if( bufferPcbOutlines.GetCornersCount() )
    if( bufferPcbOutlines.GetCornersCount() )
    {
    {
        glColor4f( 1.0, 1.0, 1.0, 1.0 );
        Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0,
        Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0,
                                            board_thickness, g_Parm_3D_Visu.m_BiuTo3Dunits );
                                            board_thickness, g_Parm_3D_Visu.m_BiuTo3Dunits );
    }
    }
@@ -1017,7 +1058,7 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
    KI_POLYGON_SET  brdpolysetHoles;
    KI_POLYGON_SET  brdpolysetHoles;
    allLayerHoles.ExportTo( brdpolysetHoles );
    allLayerHoles.ExportTo( brdpolysetHoles );


    static const LAYER_ID sequence[] = {
    static const LAYER_ID teckLayerList[] = {
        B_Adhes,
        B_Adhes,
        F_Adhes,
        F_Adhes,
        B_Paste,
        B_Paste,
@@ -1028,13 +1069,13 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
        F_Mask,
        F_Mask,
    };
    };


    for( LSEQ seq = pcb->GetEnabledLayers().Seq( sequence, DIM( sequence ) );  seq;  ++seq )
    for( LSEQ seq = LSET::AllTechMask().Seq( teckLayerList, DIM( teckLayerList ) );  seq;  ++seq )
    {
    {
        LAYER_ID layer = *seq;
        LAYER_ID layer = *seq;


        // Skip user layers, which are not drawn here
        // Skip user layers, which are not drawn here
        if( IsUserLayer( layer) )
//        if( IsUserLayer( layer) )
            continue;
//            continue;


        if( !Is3DLayerEnabled( layer ) )
        if( !Is3DLayerEnabled( layer ) )
            continue;
            continue;
@@ -1479,16 +1520,16 @@ static bool Is3DLayerEnabled( LAYER_ID aLayer )
        break;
        break;


    default:
    default:
        // the layer is an internal copper layer
        // the layer is an internal copper layer, used the visibility
        //
        if( realistic_mode )
        if( realistic_mode )
            return false;
            return false;


        return g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( aLayer );
        return g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( aLayer );
    }
    }


    // if the layer has a flag, return the flag
    // The layer has a flag, return the flag
    return g_Parm_3D_Visu.GetFlag( flg ) &&
    return g_Parm_3D_Visu.GetFlag( flg );
           g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( aLayer );
}
}




+1 −1
Original line number Original line Diff line number Diff line
@@ -422,7 +422,7 @@ void CALLBACK tessCPolyPt2Vertex( const GLvoid* data )
    // cast back to double type
    // cast back to double type
    const CPolyPt* ptr = (const CPolyPt*) data;
    const CPolyPt* ptr = (const CPolyPt*) data;


    if( g_Parm_3D_Visu.IsRealisticMode() && g_Parm_3D_Visu.HightQualityMode() )
    if( g_Parm_3D_Visu.IsRealisticMode() && g_Parm_3D_Visu.GetFlag( FL_RENDER_TEXTURES ) )
    {
    {
        glTexCoord2f( ptr->x* g_Parm_3D_Visu.m_BiuTo3Dunits * m_texture_scale,
        glTexCoord2f( ptr->x* g_Parm_3D_Visu.m_BiuTo3Dunits * m_texture_scale,
                    -ptr->y * g_Parm_3D_Visu.m_BiuTo3Dunits * m_texture_scale);
                    -ptr->y * g_Parm_3D_Visu.m_BiuTo3Dunits * m_texture_scale);
+42 −16
Original line number Original line Diff line number Diff line
@@ -40,16 +40,17 @@
#include <info3d_visu.h>
#include <info3d_visu.h>
#include <3d_draw_basic_functions.h>
#include <3d_draw_basic_functions.h>


#define TEXTURE_PCB_SCALE 5.0


// Helper function: initialize the copper color to draw the board
// Helper function: initialize the copper color to draw the board
// in realistic mode.
// in realistic mode.
void EDA_3D_CANVAS::SetGLCopperColor()
void EDA_3D_CANVAS::SetGLCopperColor()
{
{
    glDisable( GL_TEXTURE_2D );
    glDisable( GL_TEXTURE_2D );

    glColor4f( g_Parm_3D_Visu.m_CopperColor.m_Red,
    // Generates a golden yellow color, near board "copper" color
               g_Parm_3D_Visu.m_CopperColor.m_Green,
    const double lum = 0.7/255.0;
               g_Parm_3D_Visu.m_CopperColor.m_Blue,
    glColor4f( 255.0*lum, 223.0*lum, 0.0*lum, 1.0 );
               1.0 );
}
}


// Helper function: initialize the color to draw the epoxy
// Helper function: initialize the color to draw the epoxy
@@ -57,8 +58,15 @@ void EDA_3D_CANVAS::SetGLCopperColor()
void EDA_3D_CANVAS::SetGLEpoxyColor( double aTransparency )
void EDA_3D_CANVAS::SetGLEpoxyColor( double aTransparency )
{
{
    // Generates an epoxy color, near board color
    // Generates an epoxy color, near board color
    const double lum = 0.2/255.0;
    glColor4f( 0.45 * 0.85 - (1.0 - g_Parm_3D_Visu.m_BoardColor.m_Red)   * 0.32,
    glColor4f( 255.0*lum, 218.0*lum, 110.0*lum, aTransparency );
               0.39 * 0.85 - (1.0 - g_Parm_3D_Visu.m_BoardColor.m_Green) * 0.28,
               0.33 * 0.85 - (1.0 - g_Parm_3D_Visu.m_BoardColor.m_Blue)  * 0.23,
               aTransparency );

    if( g_Parm_3D_Visu.GetFlag( FL_RENDER_TEXTURES ) )
    {
        SetGLTexture( m_text_pcb, TEXTURE_PCB_SCALE );
    }
}
}


// Helper function: initialize the color to draw the
// Helper function: initialize the color to draw the
@@ -66,8 +74,15 @@ void EDA_3D_CANVAS::SetGLEpoxyColor( double aTransparency )
void EDA_3D_CANVAS::SetGLSolderMaskColor( double aTransparency )
void EDA_3D_CANVAS::SetGLSolderMaskColor( double aTransparency )
{
{
    // Generates a solder mask color
    // Generates a solder mask color
    const double lum = 0.2/255.0;
    glColor4f( g_Parm_3D_Visu.m_BoardColor.m_Red,
    glColor4f( 100.0*lum, 255.0*lum, 180.0*lum, aTransparency );
               g_Parm_3D_Visu.m_BoardColor.m_Green,
               g_Parm_3D_Visu.m_BoardColor.m_Blue,
               aTransparency );

    if( g_Parm_3D_Visu.GetFlag( FL_RENDER_TEXTURES ) )
    {
        SetGLTexture( m_text_pcb, TEXTURE_PCB_SCALE );
    }
}
}


// Helper function: initialize the color to draw the non copper layers
// Helper function: initialize the color to draw the non copper layers
@@ -87,20 +102,31 @@ void EDA_3D_CANVAS::SetGLTechLayersColor( LAYER_NUM aLayer )


        case B_SilkS:
        case B_SilkS:
        case F_SilkS:
        case F_SilkS:
            SetGLColor( LIGHTGRAY, 0.9 );
            if( g_Parm_3D_Visu.HightQualityMode() )
            {
            {
                SetGLTexture( m_text_silk, 50.0f );
            	// http://en.wikipedia.org/wiki/Luminance_(relative)
                double luminance =  g_Parm_3D_Visu.m_BoardColor.m_Red   * 0.2126 +
                                    g_Parm_3D_Visu.m_BoardColor.m_Green * 0.7152 +
                                    g_Parm_3D_Visu.m_BoardColor.m_Blue  * 0.0722;

                if( luminance < 0.5 )
                {
                    glColor4f(  0.9,  0.9,  0.9, 0.96 );
                }
                else
                {
                    glColor4f( 0.1, 0.1, 0.1, 0.96 );
                }

                if( g_Parm_3D_Visu.GetFlag( FL_RENDER_TEXTURES ) )
                {
                    SetGLTexture( m_text_silk, 10.0f );
                }
            }
            }
            break;
            break;


        case B_Mask:
        case B_Mask:
        case F_Mask:
        case F_Mask:
            SetGLSolderMaskColor( 0.7 );
            SetGLSolderMaskColor( 0.90 );
            if( g_Parm_3D_Visu.HightQualityMode() )
            {
                SetGLTexture( m_text_pcb, 35.0f );
            }
            break;
            break;


        default:
        default:
+136 −35
Original line number Original line Diff line number Diff line
@@ -45,8 +45,26 @@ INFO3D_VISU g_Parm_3D_Visu;
static const wxChar keyBgColor_Red[] =          wxT( "BgColor_Red" );
static const wxChar keyBgColor_Red[] =          wxT( "BgColor_Red" );
static const wxChar keyBgColor_Green[] =        wxT( "BgColor_Green" );
static const wxChar keyBgColor_Green[] =        wxT( "BgColor_Green" );
static const wxChar keyBgColor_Blue[] =         wxT( "BgColor_Blue" );
static const wxChar keyBgColor_Blue[] =         wxT( "BgColor_Blue" );

static const wxChar keyBgColor_Red_Top[] =      wxT( "BgColor_Red_Top" );
static const wxChar keyBgColor_Green_Top[] =    wxT( "BgColor_Green_Top" );
static const wxChar keyBgColor_Blue_Top[] =     wxT( "BgColor_Blue_Top" );

static const wxChar keyBoardColor_Red[] =       wxT( "BoardColor_Red" );
static const wxChar keyBoardColor_Green[] =     wxT( "BoardColor_Green" );
static const wxChar keyBoardColor_Blue[] =      wxT( "BoardColor_Blue" );

static const wxChar keyCopperColor_Red[] =      wxT( "CopperColor_Red" );
static const wxChar keyCopperColor_Green[] =    wxT( "CopperColor_Green" );
static const wxChar keyCopperColor_Blue[] =     wxT( "CopperColor_Blue" );

static const wxChar keyShowRealisticMode[] =    wxT( "ShowRealisticMode" );
static const wxChar keyShowRealisticMode[] =    wxT( "ShowRealisticMode" );
static const wxChar keyUseHQinRealisticMode[] = wxT( "UseHQinRealisticMode" );
static const wxChar keyRenderShadows[] =        wxT( "Render_Shadows" );
static const wxChar keyRenderRemoveHoles[] =    wxT( "Render_RemoveHoles" );
static const wxChar keyRenderTextures[] =       wxT( "Render_Textures" );
static const wxChar keyRenderSmooth[] =         wxT( "Render_Smooth" );
static const wxChar keyRenderMaterial[] =       wxT( "Render_Material" );

static const wxChar keyShowAxis[] =             wxT( "ShowAxis" );
static const wxChar keyShowAxis[] =             wxT( "ShowAxis" );
static const wxChar keyShowGrid[] =             wxT( "ShowGrid3D" );
static const wxChar keyShowGrid[] =             wxT( "ShowGrid3D" );
static const wxChar keyShowGridSize[] =         wxT( "Grid3DSize" );
static const wxChar keyShowGridSize[] =         wxT( "Grid3DSize" );
@@ -216,16 +234,40 @@ void EDA_3D_FRAME::LoadSettings( wxConfigBase* aCfg )


    INFO3D_VISU& prms = g_Parm_3D_Visu;
    INFO3D_VISU& prms = g_Parm_3D_Visu;


    aCfg->Read( keyBgColor_Red, &g_Parm_3D_Visu.m_BgColor.m_Red, 0.0 );
    aCfg->Read( keyBgColor_Red, &g_Parm_3D_Visu.m_BgColor.m_Red, 0.4 );
    aCfg->Read( keyBgColor_Green, &g_Parm_3D_Visu.m_BgColor.m_Green, 0.0 );
    aCfg->Read( keyBgColor_Green, &g_Parm_3D_Visu.m_BgColor.m_Green, 0.4 );
    aCfg->Read( keyBgColor_Blue, &g_Parm_3D_Visu.m_BgColor.m_Blue, 0.0 );
    aCfg->Read( keyBgColor_Blue, &g_Parm_3D_Visu.m_BgColor.m_Blue, 0.5 );

    aCfg->Read( keyBgColor_Red_Top, &g_Parm_3D_Visu.m_BgColor_Top.m_Red, 0.8 );
    aCfg->Read( keyBgColor_Green_Top, &g_Parm_3D_Visu.m_BgColor_Top.m_Green, 0.8 );
    aCfg->Read( keyBgColor_Blue_Top, &g_Parm_3D_Visu.m_BgColor_Top.m_Blue, 0.9 );

    aCfg->Read( keyBoardColor_Red, &g_Parm_3D_Visu.m_BoardColor.m_Red, 0.0 );
    aCfg->Read( keyBoardColor_Green, &g_Parm_3D_Visu.m_BoardColor.m_Green, 0.5 );
    aCfg->Read( keyBoardColor_Blue, &g_Parm_3D_Visu.m_BoardColor.m_Blue, 0.0 );

    aCfg->Read( keyCopperColor_Red, &g_Parm_3D_Visu.m_CopperColor.m_Red, 0.8 );
    aCfg->Read( keyCopperColor_Green, &g_Parm_3D_Visu.m_CopperColor.m_Green, 0.75 );
    aCfg->Read( keyCopperColor_Blue, &g_Parm_3D_Visu.m_CopperColor.m_Blue, 0.0 );


    bool tmp;
    bool tmp;
    aCfg->Read( keyShowRealisticMode, &tmp, false );
    aCfg->Read( keyShowRealisticMode, &tmp, false );
    prms.SetFlag( FL_USE_REALISTIC_MODE, tmp );
    prms.SetFlag( FL_USE_REALISTIC_MODE, tmp );


    aCfg->Read( keyUseHQinRealisticMode, &tmp, false );
    aCfg->Read( keyRenderShadows, &tmp, false );
    prms.SetFlag( FL_USE_MAXQUALITY_IN_REALISTIC_MODE, tmp );
    prms.SetFlag( FL_RENDER_SHADOWS, tmp );

    aCfg->Read( keyRenderRemoveHoles, &tmp, false );
    prms.SetFlag( FL_RENDER_SHOW_HOLES_IN_ZONES, tmp );

    aCfg->Read( keyRenderTextures, &tmp, false );
    prms.SetFlag( FL_RENDER_TEXTURES, tmp );

    aCfg->Read( keyRenderSmooth, &tmp, false );
    prms.SetFlag( FL_RENDER_SMOOTH, tmp );

    aCfg->Read( keyRenderMaterial, &tmp, false );
    prms.SetFlag( FL_RENDER_MATERIAL, tmp );


    aCfg->Read( keyShowAxis, &tmp, true );
    aCfg->Read( keyShowAxis, &tmp, true );
    prms.SetFlag( FL_AXIS, tmp );
    prms.SetFlag( FL_AXIS, tmp );
@@ -234,7 +276,6 @@ void EDA_3D_FRAME::LoadSettings( wxConfigBase* aCfg )
    prms.SetFlag( FL_GRID, tmp );
    prms.SetFlag( FL_GRID, tmp );


    aCfg->Read( keyShowGridSize, &prms.m_3D_Grid, 10.0 );
    aCfg->Read( keyShowGridSize, &prms.m_3D_Grid, 10.0 );
    prms.SetFlag( FL_MODULE, tmp );


    aCfg->Read( keyShowFootprints, &tmp, true );
    aCfg->Read( keyShowFootprints, &tmp, true );
    prms.SetFlag( FL_MODULE, tmp );
    prms.SetFlag( FL_MODULE, tmp );
@@ -277,8 +318,27 @@ void EDA_3D_FRAME::SaveSettings( wxConfigBase* aCfg )
    aCfg->Write( keyBgColor_Red, g_Parm_3D_Visu.m_BgColor.m_Red );
    aCfg->Write( keyBgColor_Red, g_Parm_3D_Visu.m_BgColor.m_Red );
    aCfg->Write( keyBgColor_Green, g_Parm_3D_Visu.m_BgColor.m_Green );
    aCfg->Write( keyBgColor_Green, g_Parm_3D_Visu.m_BgColor.m_Green );
    aCfg->Write( keyBgColor_Blue, g_Parm_3D_Visu.m_BgColor.m_Blue );
    aCfg->Write( keyBgColor_Blue, g_Parm_3D_Visu.m_BgColor.m_Blue );

    aCfg->Write( keyBgColor_Red_Top, g_Parm_3D_Visu.m_BgColor_Top.m_Red );
    aCfg->Write( keyBgColor_Green_Top, g_Parm_3D_Visu.m_BgColor_Top.m_Green );
    aCfg->Write( keyBgColor_Blue_Top, g_Parm_3D_Visu.m_BgColor_Top.m_Blue );

    aCfg->Write( keyBoardColor_Red, g_Parm_3D_Visu.m_BoardColor.m_Red );
    aCfg->Write( keyBoardColor_Green, g_Parm_3D_Visu.m_BoardColor.m_Green );
    aCfg->Write( keyBoardColor_Blue, g_Parm_3D_Visu.m_BoardColor.m_Blue );

    aCfg->Write( keyCopperColor_Red, g_Parm_3D_Visu.m_CopperColor.m_Red );
    aCfg->Write( keyCopperColor_Green, g_Parm_3D_Visu.m_CopperColor.m_Green );
    aCfg->Write( keyCopperColor_Blue, g_Parm_3D_Visu.m_CopperColor.m_Blue );

    aCfg->Write( keyShowRealisticMode, prms.GetFlag( FL_USE_REALISTIC_MODE ) );
    aCfg->Write( keyShowRealisticMode, prms.GetFlag( FL_USE_REALISTIC_MODE ) );
    aCfg->Write( keyUseHQinRealisticMode, prms.GetFlag( FL_USE_MAXQUALITY_IN_REALISTIC_MODE )  );

    aCfg->Write( keyRenderShadows, prms.GetFlag( FL_RENDER_SHADOWS ) );
    aCfg->Write( keyRenderRemoveHoles, prms.GetFlag( FL_RENDER_SHOW_HOLES_IN_ZONES ) );
    aCfg->Write( keyRenderTextures, prms.GetFlag( FL_RENDER_TEXTURES ) );
    aCfg->Write( keyRenderSmooth, prms.GetFlag( FL_RENDER_SMOOTH ) );
    aCfg->Write( keyRenderMaterial, prms.GetFlag( FL_RENDER_MATERIAL ) );

    aCfg->Write( keyShowAxis, prms.GetFlag( FL_AXIS ) );
    aCfg->Write( keyShowAxis, prms.GetFlag( FL_AXIS ) );
    aCfg->Write( keyShowGrid, prms.GetFlag( FL_GRID ) );
    aCfg->Write( keyShowGrid, prms.GetFlag( FL_GRID ) );
    aCfg->Write( keyShowGridSize, prms.m_3D_Grid );
    aCfg->Write( keyShowGridSize, prms.m_3D_Grid );
@@ -424,7 +484,26 @@ void EDA_3D_FRAME::Process_Special_Functions( wxCommandEvent& event )
        break;
        break;


    case ID_MENU3D_BGCOLOR_SELECTION:
    case ID_MENU3D_BGCOLOR_SELECTION:
        Set3DBgColor();
        Set3DBgColor( g_Parm_3D_Visu.m_BgColor );
        return;

    case ID_MENU3D_BGCOLOR_TOP_SELECTION:
        Set3DBgColor( g_Parm_3D_Visu.m_BgColor_Top );
        return;

    case ID_MENU3D_BOARDCOLOR_SELECTION:
        if( Set3DBgColor( g_Parm_3D_Visu.m_BoardColor ) == true )
        {
        	NewDisplay(GL_ID_TECH_LAYERS);
        	NewDisplay(GL_ID_BOARD);
    	}
        return;

    case ID_MENU3D_COPPERCOLOR_SELECTION:
        if( Set3DBgColor( g_Parm_3D_Visu.m_CopperColor ) == true )
        {
        	NewDisplay(GL_ID_BOARD);
    	}
        return;
        return;


    case ID_MENU3D_REALISTIC_MODE:
    case ID_MENU3D_REALISTIC_MODE:
@@ -432,8 +511,29 @@ void EDA_3D_FRAME::Process_Special_Functions( wxCommandEvent& event )
        NewDisplay();
        NewDisplay();
        return;
        return;


    case ID_MENU3D_MAX_QUALITY_FOR_REALISTIC_MODE:
    case ID_MENU3D_FL_RENDER_SHADOWS:
        g_Parm_3D_Visu.SetFlag( FL_USE_MAXQUALITY_IN_REALISTIC_MODE, isChecked );
        g_Parm_3D_Visu.SetFlag( FL_RENDER_SHADOWS, isChecked );
        NewDisplay();
        return;

    case ID_MENU3D_FL_RENDER_SHOW_HOLES_IN_ZONES:
        g_Parm_3D_Visu.SetFlag( FL_RENDER_SHOW_HOLES_IN_ZONES, isChecked );
        NewDisplay();
        return;

    case ID_MENU3D_FL_RENDER_TEXTURES:
        g_Parm_3D_Visu.SetFlag( FL_RENDER_TEXTURES, isChecked );
        NewDisplay(GL_ID_BOARD);
        NewDisplay(GL_ID_TECH_LAYERS);
        return;

    case ID_MENU3D_FL_RENDER_SMOOTH:
        g_Parm_3D_Visu.SetFlag( FL_RENDER_SMOOTH, isChecked );
        NewDisplay();
        return;

    case ID_MENU3D_FL_RENDER_MATERIAL:
        g_Parm_3D_Visu.SetFlag( FL_RENDER_MATERIAL, isChecked );
        NewDisplay();
        NewDisplay();
        return;
        return;


@@ -455,6 +555,7 @@ void EDA_3D_FRAME::Process_Special_Functions( wxCommandEvent& event )
    case ID_MENU3D_USE_COPPER_THICKNESS:
    case ID_MENU3D_USE_COPPER_THICKNESS:
        g_Parm_3D_Visu.SetFlag( FL_USE_COPPER_THICKNESS, isChecked );
        g_Parm_3D_Visu.SetFlag( FL_USE_COPPER_THICKNESS, isChecked );
        NewDisplay(GL_ID_BOARD);
        NewDisplay(GL_ID_BOARD);
        NewDisplay(GL_ID_TECH_LAYERS);
        return;
        return;


    case ID_MENU3D_ZONE_ONOFF:
    case ID_MENU3D_ZONE_ONOFF:
@@ -506,7 +607,7 @@ void EDA_3D_FRAME::On3DGridSelection( wxCommandEvent& event )
{
{
    int id = event.GetId();
    int id = event.GetId();


    for( int ii = ID_MENU3D_GRID; ii < ID_MENU3D_GRID_END; ii++ )
    for( int ii = ID_MENU3D_GRID_NOGRID; ii < ID_MENU3D_GRID_END; ii++ )
    {
    {
        if( event.GetId() == ii )
        if( event.GetId() == ii )
            continue;
            continue;
@@ -574,27 +675,27 @@ void EDA_3D_FRAME::OnActivate( wxActivateEvent& event )


/* called to set the background color of the 3D scene
/* called to set the background color of the 3D scene
 */
 */
void EDA_3D_FRAME::Set3DBgColor()
bool EDA_3D_FRAME::Set3DBgColor( S3D_COLOR &color )
{
{
    S3D_COLOR   color;
    wxColour    newcolor, oldcolor;
    wxColour    newcolor, oldcolor;


    oldcolor.Set( KiROUND( g_Parm_3D_Visu.m_BgColor.m_Red * 255 ),
    oldcolor.Set( KiROUND( color.m_Red * 255 ),
                  KiROUND( g_Parm_3D_Visu.m_BgColor.m_Green * 255 ),
                  KiROUND( color.m_Green * 255 ),
                  KiROUND( g_Parm_3D_Visu.m_BgColor.m_Blue * 255 ) );
                  KiROUND( color.m_Blue * 255 ) );


    newcolor = wxGetColourFromUser( this, oldcolor );
    newcolor = wxGetColourFromUser( this, oldcolor );


    if( !newcolor.IsOk() )     // Cancel command
    if( !newcolor.IsOk() )     // Cancel command
        return;
        return false;


    if( newcolor != oldcolor )
    if( newcolor != oldcolor )
    {
    {
        g_Parm_3D_Visu.m_BgColor.m_Red      = (double) newcolor.Red() / 255.0;
        color.m_Red      = (double) newcolor.Red() / 255.0;
        g_Parm_3D_Visu.m_BgColor.m_Green    = (double) newcolor.Green() / 255.0;
        color.m_Green    = (double) newcolor.Green() / 255.0;
        g_Parm_3D_Visu.m_BgColor.m_Blue     = (double) newcolor.Blue() / 255.0;
        color.m_Blue     = (double) newcolor.Blue() / 255.0;
        m_canvas->Redraw();
        m_canvas->Redraw();
    }
    }
    return true;
}
}


BOARD* EDA_3D_FRAME::GetBoard()
BOARD* EDA_3D_FRAME::GetBoard()
Loading