Commit 7c482f68 authored by CHARRAS's avatar CHARRAS
Browse files

Added Jonas Diemer's patch (3D display: enhanced movings from mouse and tools)

parent 56ef4d3b
Loading
Loading
Loading
Loading
+19 −8
Original line number Original line Diff line number Diff line
@@ -282,6 +282,8 @@ void Pcb3D_GLCanvas::OnMouseEvent( wxMouseEvent& event )
    }
    }


    if( event.Dragging() )
    if( event.Dragging() )
    {
        if( event.LeftIsDown() )
        {
        {
            /* drag in progress, simulate trackball */
            /* drag in progress, simulate trackball */
            trackball( spin_quat,
            trackball( spin_quat,
@@ -291,6 +293,15 @@ void Pcb3D_GLCanvas::OnMouseEvent( wxMouseEvent& event )
                       ( size.y - 2.0 * event.GetY() ) / size.y );
                       ( size.y - 2.0 * event.GetY() ) / size.y );


            add_quats( spin_quat, g_Parm_3D_Visu.m_Quat, g_Parm_3D_Visu.m_Quat );
            add_quats( spin_quat, g_Parm_3D_Visu.m_Quat, g_Parm_3D_Visu.m_Quat );
        }
        else if( event.MiddleIsDown() )
        {
            /* middle button drag -> pan */
            /* Current zoom and an additional factor are taken into account for the amount of panning. */
            const float PAN_FACTOR = 8.0 * g_Parm_3D_Visu.m_Zoom;
            g_Draw3d_dx -= PAN_FACTOR * ( g_Parm_3D_Visu.m_Beginx - event.GetX() ) / size.x;
            g_Draw3d_dy -= PAN_FACTOR * (event.GetY() - g_Parm_3D_Visu.m_Beginy) / size.y;
        }


        /* orientation has changed, redraw mesh */
        /* orientation has changed, redraw mesh */
        DisplayStatus();
        DisplayStatus();
+740 −703
Original line number Original line Diff line number Diff line
//////////////////////////////////////
//////////////////////////////////////

// Name:        3d_draw.cpp
// Name:        3d_draw.cpp
//////////////////////////////////////
//////////////////////////////////////


@@ -33,14 +34,20 @@ static void Draw3D_FilledSegment(double startx, double starty,
                                  double endx, double endy, double width, double zpos );
                                  double endx, double endy, double width, double zpos );
static void Draw3D_FilledCylinder( double posx, double posy,
static void Draw3D_FilledCylinder( double posx, double posy,
                                   double rayon, double height, double zpos );
                                   double rayon, double height, double zpos );
static void Draw3D_FilledSegmentWithHole(double startx, double starty,
static void Draw3D_FilledSegmentWithHole( double startx,
				double endx, double endy,double width,
                                          double starty,
				double holex, double holey, double holeradius, double zpos);
                                          double endx,

                                          double endy,

                                          double width,
/**********************************/
                                          double holex,
                                          double holey,
                                          double holeradius,
                                          double zpos );


/******************************************/
void Pcb3D_GLCanvas::Redraw( bool finish )
void Pcb3D_GLCanvas::Redraw( bool finish )
/**********************************/
/******************************************/
{
{
    SetCurrent();
    SetCurrent();


@@ -50,11 +57,12 @@ void Pcb3D_GLCanvas::Redraw( bool finish )
    /* transformations */
    /* transformations */
    GLfloat mat[4][4];
    GLfloat mat[4][4];


    // Translatory motion first, so rotations don't mess up the orientation...
    glTranslatef( g_Draw3d_dx, g_Draw3d_dy, 0.0F );

    build_rotmatrix( mat, g_Parm_3D_Visu.m_Quat );
    build_rotmatrix( mat, g_Parm_3D_Visu.m_Quat );
    glMultMatrixf( &mat[0][0] );
    glMultMatrixf( &mat[0][0] );


	glTranslatef(g_Draw3d_dx, g_Draw3d_dy, 0.0F);

    glRotatef( g_Parm_3D_Visu.m_Rot[0], 1.0, 0.0, 0.0 );
    glRotatef( g_Parm_3D_Visu.m_Rot[0], 1.0, 0.0, 0.0 );
    glRotatef( g_Parm_3D_Visu.m_Rot[1], 0.0, 1.0, 0.0 );
    glRotatef( g_Parm_3D_Visu.m_Rot[1], 0.0, 1.0, 0.0 );
    glRotatef( g_Parm_3D_Visu.m_Rot[2], 0.0, 0.0, 1.0 );
    glRotatef( g_Parm_3D_Visu.m_Rot[2], 0.0, 0.0, 1.0 );
@@ -64,6 +72,7 @@ void Pcb3D_GLCanvas::Redraw( bool finish )
    else
    else
    {
    {
        m_gllist = CreateDrawGL_List();
        m_gllist = CreateDrawGL_List();

//		m_gllist = DisplayCubeforTest();	// Only for test
//		m_gllist = DisplayCubeforTest();	// Only for test
    }
    }


@@ -77,6 +86,7 @@ void Pcb3D_GLCanvas::Redraw( bool finish )
/**********************************************/
/**********************************************/
GLuint Pcb3D_GLCanvas::CreateDrawGL_List()
GLuint Pcb3D_GLCanvas::CreateDrawGL_List()
/**********************************************/
/**********************************************/

/* Creation de la liste des elements a afficher
/* Creation de la liste des elements a afficher
 */
 */
{
{
@@ -94,7 +104,8 @@ int ii;
    g_Parm_3D_Visu.m_BoardPos   = pcb->m_BoundaryBox.Centre();
    g_Parm_3D_Visu.m_BoardPos   = pcb->m_BoundaryBox.Centre();
    g_Parm_3D_Visu.m_BoardPos.y = -g_Parm_3D_Visu.m_BoardPos.y;
    g_Parm_3D_Visu.m_BoardPos.y = -g_Parm_3D_Visu.m_BoardPos.y;
    g_Parm_3D_Visu.m_Layers     = pcb->m_BoardSettings->m_CopperLayerCount;
    g_Parm_3D_Visu.m_Layers     = pcb->m_BoardSettings->m_CopperLayerCount;
	g_Parm_3D_Visu.m_BoardScale = 2.0 / MAX(g_Parm_3D_Visu.m_BoardSize.x, g_Parm_3D_Visu.m_BoardSize.y);
    g_Parm_3D_Visu.m_BoardScale = 2.0 / MAX( g_Parm_3D_Visu.m_BoardSize.x,
                                             g_Parm_3D_Visu.m_BoardSize.y );
    float epoxy_width = 1.6;    // epoxy width in mm
    float epoxy_width = 1.6;    // epoxy width in mm
    g_Parm_3D_Visu.m_Epoxy_Width = epoxy_width / 2.54 * 1000
    g_Parm_3D_Visu.m_Epoxy_Width = epoxy_width / 2.54 * 1000
                                   * g_Parm_3D_Visu.m_BoardScale;
                                   * g_Parm_3D_Visu.m_BoardScale;
@@ -108,6 +119,7 @@ int ii;
        else
        else
            g_Parm_3D_Visu.m_LayerZcoord[ii] = g_Parm_3D_Visu.m_Epoxy_Width;
            g_Parm_3D_Visu.m_LayerZcoord[ii] = g_Parm_3D_Visu.m_Epoxy_Width;
    }
    }

    GLfloat zpos_cu  = 500 * g_Parm_3D_Visu.m_BoardScale;
    GLfloat zpos_cu  = 500 * g_Parm_3D_Visu.m_BoardScale;
    GLfloat zpos_cmp = g_Parm_3D_Visu.m_Epoxy_Width + zpos_cu;
    GLfloat zpos_cmp = g_Parm_3D_Visu.m_Epoxy_Width + zpos_cu;
    g_Parm_3D_Visu.m_LayerZcoord[ADHESIVE_N_CU]    = -zpos_cu * 2;
    g_Parm_3D_Visu.m_LayerZcoord[ADHESIVE_N_CU]    = -zpos_cu * 2;
@@ -141,6 +153,7 @@ int ii;
#if 0
#if 0
    glEnable( GL_FOG );
    glEnable( GL_FOG );
    GLfloat param;
    GLfloat param;

//	param = GL_LINEAR;
//	param = GL_LINEAR;
//	glFogfv(GL_FOG_MODE, & param);
//	glFogfv(GL_FOG_MODE, & param);
    param = 0.2;
    param = 0.2;
@@ -200,6 +213,7 @@ MODULE * Module = (MODULE*) pcb->m_Modules;
    {
    {
        Module->Draw3D( this );
        Module->Draw3D( this );
    }
    }

    glEndList();
    glEndList();


    /* Test for errors */
    /* Test for errors */
@@ -241,6 +255,7 @@ double w;
/********************************************/
/********************************************/
void Pcb3D_GLCanvas::Draw3D_Via( SEGVIA* via )
void Pcb3D_GLCanvas::Draw3D_Via( SEGVIA* via )
/*********************************************/
/*********************************************/

/* 3D drawing for a VIA (cylinder + filled circles)
/* 3D drawing for a VIA (cylinder + filled circles)
 */
 */
{
{
@@ -273,6 +288,7 @@ int color;
        if( layer >= top_layer )
        if( layer >= top_layer )
            break;
            break;
    }
    }

    // Drawing hole:
    // Drawing hole:
    SetGLColor( DARKGRAY );
    SetGLColor( DARKGRAY );
    height = g_Parm_3D_Visu.m_LayerZcoord[top_layer] - g_Parm_3D_Visu.m_LayerZcoord[bottom_layer];
    height = g_Parm_3D_Visu.m_LayerZcoord[top_layer] - g_Parm_3D_Visu.m_LayerZcoord[bottom_layer];
@@ -308,7 +324,6 @@ int color = g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[segment->GetLayer()];
            Draw3D_FilledSegment( x, -y, xf, -yf, w, zpos );
            Draw3D_FilledSegment( x, -y, xf, -yf, w, zpos );
        }
        }
    }
    }

    else
    else
    {
    {
        zpos = g_Parm_3D_Visu.m_LayerZcoord[segment->GetLayer()];
        zpos = g_Parm_3D_Visu.m_LayerZcoord[segment->GetLayer()];
@@ -370,6 +385,7 @@ bool As3dShape = FALSE;
            Struct3D->ReadData();
            Struct3D->ReadData();
        }
        }
    }
    }

    glPopMatrix();
    glPopMatrix();


    if( !As3dShape )
    if( !As3dShape )
@@ -416,6 +432,7 @@ int color = g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[m_Layer];
    dy   = m_End.y;
    dy   = m_End.y;
    zpos = g_Parm_3D_Visu.m_LayerZcoord[m_Layer];
    zpos = g_Parm_3D_Visu.m_LayerZcoord[m_Layer];
    w    = m_Width * g_Parm_3D_Visu.m_BoardScale;
    w    = m_Width * g_Parm_3D_Visu.m_BoardScale;

    switch( m_Shape )
    switch( m_Shape )
    {
    {
    case S_SEGMENT:
    case S_SEGMENT:
@@ -444,6 +461,7 @@ int color = g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[m_Layer];
/***********************************************/
/***********************************************/
void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas )
void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas )
/***********************************************/
/***********************************************/

/* Dessin 3D des pads avec leur trou de percage
/* Dessin 3D des pads avec leur trou de percage
 */
 */
{
{
@@ -494,6 +512,7 @@ int color;
    Oncu  = (m_Masque_Layer & CUIVRE_LAYER) ? TRUE : FALSE;
    Oncu  = (m_Masque_Layer & CUIVRE_LAYER) ? TRUE : FALSE;
    Oncmp = (m_Masque_Layer & CMP_LAYER) ? TRUE : FALSE;
    Oncmp = (m_Masque_Layer & CMP_LAYER) ? TRUE : FALSE;
    Both  = Oncu && Oncmp;
    Both  = Oncu && Oncmp;

    switch( m_PadShape & 0x7F )
    switch( m_PadShape & 0x7F )
    {
    {
    case PAD_CIRCLE:
    case PAD_CIRCLE:
@@ -518,6 +537,7 @@ int color;
            zpos = g_Parm_3D_Visu.m_LayerZcoord[layer];
            zpos = g_Parm_3D_Visu.m_LayerZcoord[layer];
            Draw3D_FilledCircle( x, -y, r, hole, zpos );
            Draw3D_FilledCircle( x, -y, r, hole, zpos );
        }
        }

        break;
        break;


    case PAD_OVAL:
    case PAD_OVAL:
@@ -565,6 +585,7 @@ int color;
        break;
        break;


    case PAD_RECT:
    case PAD_RECT:

//	case SPECIAL_PAD:
//	case SPECIAL_PAD:
    case PAD_TRAPEZOID:
    case PAD_TRAPEZOID:
    {
    {
@@ -635,6 +656,7 @@ int color;
                glVertex3f( f_hole_coord[ii][0], -f_hole_coord[ii][1], zpos );
                glVertex3f( f_hole_coord[ii][0], -f_hole_coord[ii][1], zpos );
                glVertex3f( fcoord[ii][0], -fcoord[ii][1], zpos );
                glVertex3f( fcoord[ii][0], -fcoord[ii][1], zpos );
            }
            }

            glVertex3f( f_hole_coord[0][0], -f_hole_coord[0][1], zpos );
            glVertex3f( f_hole_coord[0][0], -f_hole_coord[0][1], zpos );
            glVertex3f( fcoord[0][0], -fcoord[0][1], zpos );
            glVertex3f( fcoord[0][0], -fcoord[0][1], zpos );
            glEnd();
            glEnd();
@@ -682,6 +704,7 @@ double x, y;
        RotatePoint( &x, &y, ii * 225 );
        RotatePoint( &x, &y, ii * 225 );
        glVertex3f( x + posx, y + posy, zpos );
        glVertex3f( x + posx, y + posy, zpos );
    }
    }

    glEnd();
    glEnd();
}
}


@@ -693,6 +716,7 @@ static void Draw3D_FilledCylinder(double posx, double posy,
{
{
    int        ii;
    int        ii;
    double     x, y;
    double     x, y;

#define NB_SEGM 12
#define NB_SEGM 12
    S3D_Vertex coords[4];
    S3D_Vertex coords[4];
    double     tmp = DataScale3D;
    double     tmp = DataScale3D;
@@ -716,6 +740,7 @@ double tmp = DataScale3D;
        coords[1].x = coords[3].x;
        coords[1].x = coords[3].x;
        coords[1].y = coords[3].y;
        coords[1].y = coords[3].y;
    }
    }

    glNormal3f( 0.0, 0.0, 1.0 ); // Normal is Z axis
    glNormal3f( 0.0, 0.0, 1.0 ); // Normal is Z axis
    DataScale3D = tmp;
    DataScale3D = tmp;
}
}
@@ -725,6 +750,7 @@ double tmp = DataScale3D;
static void Draw3D_FilledSegment( double startx, double starty,
static void Draw3D_FilledSegment( double startx, double starty,
                                  double endx, double endy, double width, double zpos )
                                  double endx, double endy, double width, double zpos )
/*****************************************************************/
/*****************************************************************/

/* trace un polygone semblable a un segment a bouts ronds
/* trace un polygone semblable a un segment a bouts ronds
 */
 */
{
{
@@ -743,6 +769,7 @@ int ii, angle;
    width /= 2;
    width /= 2;


    glBegin( GL_POLYGON );
    glBegin( GL_POLYGON );

    // trac de l'arrondi a droite (1er demi polygone a la fin du segment)
    // trac de l'arrondi a droite (1er demi polygone a la fin du segment)
    for( ii = 0; ii <= 8; ii++ )
    for( ii = 0; ii <= 8; ii++ )
    {
    {
@@ -758,6 +785,7 @@ int ii, angle;
            firsty = starty + y;
            firsty = starty + y;
        }
        }
    }
    }

    // trac de l'arrondi a gauche (2ieme demi polygone a l'origine du segment)
    // trac de l'arrondi a gauche (2ieme demi polygone a l'origine du segment)
    for( ii = 0; ii <= 8; ii++ )
    for( ii = 0; ii <= 8; ii++ )
    {
    {
@@ -774,10 +802,17 @@ int ii, angle;




/*****************************************************************/
/*****************************************************************/
static void Draw3D_FilledSegmentWithHole(double startx, double starty,
static void Draw3D_FilledSegmentWithHole( double startx,
				double endx, double endy, double width,
                                          double starty,
				double holex, double holey, double holeradius, double zpos)
                                          double endx,
                                          double endy,
                                          double width,
                                          double holex,
                                          double holey,
                                          double holeradius,
                                          double zpos )
/*****************************************************************/
/*****************************************************************/

/* trace un polygone semblable a un segment a bouts ronds avec trou
/* trace un polygone semblable a un segment a bouts ronds avec trou
 */
 */
{
{
@@ -801,6 +836,7 @@ int ii, angle, theta;
    width /= 2;
    width /= 2;


    glBegin( GL_QUAD_STRIP );
    glBegin( GL_QUAD_STRIP );

    // trac de l'arrondi a droite (1er demi polygone a la fin du segment)
    // trac de l'arrondi a droite (1er demi polygone a la fin du segment)
    // autour du demi-trou de percage
    // autour du demi-trou de percage
    for( ii = 0; ii <= 8; ii++ )
    for( ii = 0; ii <= 8; ii++ )
@@ -826,6 +862,7 @@ int ii, angle, theta;
            firstyin = starty + yin;
            firstyin = starty + yin;
        }
        }
    }
    }

    // trac de l'arrondi a gauche (2ieme demi polygone a l'origine du segment)
    // trac de l'arrondi a gauche (2ieme demi polygone a l'origine du segment)
    for( ii = 0; ii <= 8; ii++ )
    for( ii = 0; ii <= 8; ii++ )
    {
    {
+6 −0
Original line number Original line Diff line number Diff line
@@ -5,6 +5,12 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
Please add newer entries at the top, list the date and your name with
email address.
email address.



2008-mars-03 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
3d display:
	Added Jonas Diemer's patch (enhanced movings from mouse and tools)

2008-Mar-1 UPDATE   Dick Hollenbeck <dick@softplc.com>
2008-Mar-1 UPDATE   Dick Hollenbeck <dick@softplc.com>
================================================================================
================================================================================
+pcbnew
+pcbnew