Commit cc7e7fc5 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Memory allocation improvements and other minor fixes.

* Replace C malloc() and free() functions with C++ new and delete
  operators or the appropriate STL container.
* Add option to end mouse capture function to skip executing the end
  mouse capture callback.
* Lots of coding policy and Doxygen comment goodness.
parent 7bd82846
Loading
Loading
Loading
Loading
+57 −38
Original line number Original line Diff line number Diff line
/////////////////////////////////////////////////////////////////////////////
/*
// Name:        3d_aux.cpp
 * This program source code file is part of KiCad, a free EDA CAD application.
/////////////////////////////////////////////////////////////////////////////
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file 3d_aux.cpp
 */


#include "fctsys.h"
#include "fctsys.h"


@@ -23,54 +48,53 @@
#include "trackball.h"
#include "trackball.h"




void S3D_MASTER::Set_Object_Coords( S3D_Vertex* coord, int nbcoord )
void S3D_MASTER::Set_Object_Coords( std::vector< S3D_Vertex >& aVertices )
{
{
    int ii;
    unsigned ii;



    /* adjust object scale, rotation and offset position */
    /* adjust object scale, rotation and offset position */
    for( ii = 0; ii < nbcoord; ii++ )
    for( ii = 0; ii < aVertices.size(); ii++ )
    {
    {
        coord[ii].x *= m_MatScale.x;
        aVertices[ii].x *= m_MatScale.x;
        coord[ii].y *= m_MatScale.y;
        aVertices[ii].y *= m_MatScale.y;
        coord[ii].z *= m_MatScale.z;
        aVertices[ii].z *= m_MatScale.z;


        /* adjust rotation */
        /* adjust rotation */
        if( m_MatRotation.x )
        if( m_MatRotation.x )
            RotatePoint( &coord[ii].y, &coord[ii].z, (int) (m_MatRotation.x * 10) );
            RotatePoint( &aVertices[ii].y, &aVertices[ii].z, (int) (m_MatRotation.x * 10) );


        if( m_MatRotation.y )
        if( m_MatRotation.y )
            RotatePoint( &coord[ii].z, &coord[ii].x, (int) (m_MatRotation.y * 10) );
            RotatePoint( &aVertices[ii].z, &aVertices[ii].x, (int) (m_MatRotation.y * 10) );


        if( m_MatRotation.z )
        if( m_MatRotation.z )
            RotatePoint( &coord[ii].x, &coord[ii].y, (int) (m_MatRotation.z * 10) );
            RotatePoint( &aVertices[ii].x, &aVertices[ii].y, (int) (m_MatRotation.z * 10) );


        /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */
        /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */
#define SCALE_3D_CONV (PCB_INTERNAL_UNIT / UNITS3D_TO_UNITSPCB)
#define SCALE_3D_CONV (PCB_INTERNAL_UNIT / UNITS3D_TO_UNITSPCB)
        coord[ii].x += m_MatPosition.x * SCALE_3D_CONV;
        aVertices[ii].x += m_MatPosition.x * SCALE_3D_CONV;
        coord[ii].y += m_MatPosition.y * SCALE_3D_CONV;
        aVertices[ii].y += m_MatPosition.y * SCALE_3D_CONV;
        coord[ii].z += m_MatPosition.z * SCALE_3D_CONV;
        aVertices[ii].z += m_MatPosition.z * SCALE_3D_CONV;
    }
    }
}
}




void Set_Object_Data( const S3D_Vertex* coord, int nbcoord )
void Set_Object_Data( std::vector< S3D_Vertex >& aVertices )
{
{
    int     ii;
    unsigned ii;
    GLfloat ax, ay, az, bx, by, bz, nx, ny, nz, r;
    GLfloat ax, ay, az, bx, by, bz, nx, ny, nz, r;


    /* ignore faces with less than 3 points */
    /* ignore faces with less than 3 points */
    if( nbcoord < 3 )
    if( aVertices.size() < 3 )
        return;
        return;


    /* calculate normal direction */
    /* calculate normal direction */
    ax = coord[1].x - coord[0].x;
    ax = aVertices[1].x - aVertices[0].x;
    ay = coord[1].y - coord[0].y;
    ay = aVertices[1].y - aVertices[0].y;
    az = coord[1].z - coord[0].z;
    az = aVertices[1].z - aVertices[0].z;


    bx = coord[nbcoord - 1].x - coord[0].x;
    bx = aVertices[aVertices.size() - 1].x - aVertices[0].x;
    by = coord[nbcoord - 1].y - coord[0].y;
    by = aVertices[aVertices.size() - 1].y - aVertices[0].y;
    bz = coord[nbcoord - 1].z - coord[0].z;
    bz = aVertices[aVertices.size() - 1].z - aVertices[0].z;


    nx = ay * bz - az * by;
    nx = ay * bz - az * by;
    ny = az * bx - ax * bz;
    ny = az * bx - ax * bz;
@@ -80,12 +104,14 @@ void Set_Object_Data( const S3D_Vertex* coord, int nbcoord )


    if( r >= 0.000001 ) /* avoid division by zero */
    if( r >= 0.000001 ) /* avoid division by zero */
    {
    {
        nx /= r; ny /= r; nz /= r;
        nx /= r;
        ny /= r;
        nz /= r;
        glNormal3f( nx, ny, nz );
        glNormal3f( nx, ny, nz );
    }
    }


    /* glBegin/glEnd */
    /* glBegin/glEnd */
    switch( nbcoord )
    switch( aVertices.size() )
    {
    {
    case 3:
    case 3:
        glBegin( GL_TRIANGLES );
        glBegin( GL_TRIANGLES );
@@ -101,11 +127,11 @@ void Set_Object_Data( const S3D_Vertex* coord, int nbcoord )
    }
    }


    /* draw polygon/triangle/quad */
    /* draw polygon/triangle/quad */
    for( ii = 0; ii < nbcoord; ii++ )
    for( ii = 0; ii < aVertices.size(); ii++ )
    {
    {
        glVertex3f( coord[ii].x * DataScale3D,
        glVertex3f( aVertices[ii].x * DataScale3D,
                    coord[ii].y * DataScale3D,
                    aVertices[ii].y * DataScale3D,
                    coord[ii].z * DataScale3D );
                    aVertices[ii].z * DataScale3D );
    }
    }


    glEnd();
    glEnd();
@@ -150,10 +176,6 @@ GLuint EDA_3D_CANVAS::DisplayCubeforTest()
}
}




/**********************/
/* class Info_3D_Visu */
/**********************/

Info_3D_Visu::Info_3D_Visu()
Info_3D_Visu::Info_3D_Visu()
{
{
    int ii;
    int ii;
@@ -182,8 +204,6 @@ Info_3D_Visu::~Info_3D_Visu()
}
}




/* Display and edit a Vertex (triplet of values) in INCHES or MM or without
 * units */
WinEDA_VertexCtrl::WinEDA_VertexCtrl( wxWindow* parent, const wxString& title,
WinEDA_VertexCtrl::WinEDA_VertexCtrl( wxWindow* parent, const wxString& title,
                                      wxBoxSizer* BoxSizer,
                                      wxBoxSizer* BoxSizer,
                                      EDA_UNITS_T units, int internal_unit )
                                      EDA_UNITS_T units, int internal_unit )
@@ -262,7 +282,6 @@ WinEDA_VertexCtrl::~WinEDA_VertexCtrl()
}
}




/* Returns (in internal units) to coordinate between (in user units) */
S3D_Vertex WinEDA_VertexCtrl::GetValue()
S3D_Vertex WinEDA_VertexCtrl::GetValue()
{
{
    S3D_Vertex value;
    S3D_Vertex value;
+30 −26
Original line number Original line Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
/**
 * @file 3d_draw.cpp
 * @file 3d_draw.cpp
*/
*/
@@ -62,6 +87,7 @@ static void CALLBACK tessErrorCB( GLenum errorCode );
static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data );
static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data );
static void CALLBACK tesswxPoint2Vertex( const GLvoid* data );
static void CALLBACK tesswxPoint2Vertex( const GLvoid* data );



void EDA_3D_CANVAS::Redraw( bool finish )
void EDA_3D_CANVAS::Redraw( bool finish )
{
{
    /* SwapBuffer requires the window to be shown before calling */
    /* SwapBuffer requires the window to be shown before calling */
@@ -118,8 +144,6 @@ void EDA_3D_CANVAS::Redraw( bool finish )
}
}




/* Create the draw list items
 */
GLuint EDA_3D_CANVAS::CreateDrawGL_List()
GLuint EDA_3D_CANVAS::CreateDrawGL_List()
{
{
    PCB_BASE_FRAME* pcbframe = m_Parent->m_Parent;
    PCB_BASE_FRAME* pcbframe = m_Parent->m_Parent;
@@ -410,11 +434,6 @@ void EDA_3D_CANVAS::Draw3D_Track( TRACK* track )
}
}




/**
 * Function Draw3D_SolidPolygonsInZones
 * draw all solid polygons used as filles areas in a zone
 * @param aZone = the zone to draw
 */
void EDA_3D_CANVAS::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone )
void EDA_3D_CANVAS::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone )
{
{
    double zpos;
    double zpos;
@@ -474,8 +493,6 @@ void EDA_3D_CANVAS::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone )
}
}




/* 3D drawing for a VIA (cylinder + filled circles)
 */
void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via )
void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via )
{
{
    double x, y, r, hole;
    double x, y, r, hole;
@@ -603,15 +620,6 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment )
}
}




/* function to draw 3D segments, called by DrawGraphicText
 * When DrawGraphicText is called to draw a text to an OpenGL DC
 * it calls Draw3dTextSegm to each segment to draw.
 * 2 parameters used by Draw3D_FilledSegment are not handled by DrawGraphicText
 * but are used in Draw3D_FilledSegment().
 * they are 2 local variables. This is an ugly, but trivial code.
 * Using DrawGraphicText to draw all texts ensure texts have the same shape
 * in all contexts
 */
static double s_Text3DWidth, s_Text3DZPos;
static double s_Text3DWidth, s_Text3DZPos;
static void Draw3dTextSegm( int x0, int y0, int xf, int yf )
static void Draw3dTextSegm( int x0, int y0, int xf, int yf )
{
{
@@ -1152,7 +1160,9 @@ static void Draw3D_FilledCylinder( double posx, double posy, double rayon,
    double     x, y;
    double     x, y;


#define NB_SEGM 12
#define NB_SEGM 12
    S3D_Vertex coords[4];
    std::vector< S3D_Vertex > coords;
    coords.resize( 4 );

    double     tmp = DataScale3D;
    double     tmp = DataScale3D;


    DataScale3D = 1.0; // Coordinate is already in range for Set_Object_Data();
    DataScale3D = 1.0; // Coordinate is already in range for Set_Object_Data();
@@ -1168,7 +1178,7 @@ static void Draw3D_FilledCylinder( double posx, double posy, double rayon,
        RotatePoint( &x, &y, ii * (3600 / NB_SEGM) );
        RotatePoint( &x, &y, ii * (3600 / NB_SEGM) );
        coords[2].x = coords[3].x = posx + x;
        coords[2].x = coords[3].x = posx + x;
        coords[2].y = coords[3].y = posy + y;
        coords[2].y = coords[3].y = posy + y;
        Set_Object_Data( coords, 4 );
        Set_Object_Data( coords );
        coords[0].x = coords[2].x;
        coords[0].x = coords[2].x;
        coords[0].y = coords[2].y;
        coords[0].y = coords[2].y;
        coords[1].x = coords[3].x;
        coords[1].x = coords[3].x;
@@ -1377,12 +1387,6 @@ static void Draw3D_CircleSegment( double startx, double starty, double endx,
}
}




/**
 * Function Draw3D_Polygon
 * draw one solid polygon
 * @param aCornersList = a std::vector<wxPoint> list of corners, in physical coordinates
 * @param aZpos = the z position in 3D units
 */
void EDA_3D_CANVAS::Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos )
void EDA_3D_CANVAS::Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos )
{
{
    g_Parm_3D_Visu.m_ActZpos = aZpos;
    g_Parm_3D_Visu.m_ActZpos = aZpos;
+86 −80
Original line number Original line Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
/**
 * @file 3d_read_mesh.cpp
 * @file 3d_read_mesh.cpp
 */
 */
@@ -48,8 +73,7 @@ int S3D_MASTER::ReadData()
        return -1;
        return -1;
    }
    }


    // Switch the locale to standard C (needed to print floating point
    // Switch the locale to standard C (needed to print floating point numbers like 1.3)
    // numbers like 1.3)
    SetLocaleTo_C_standard();
    SetLocaleTo_C_standard();


    while( GetLine( file, line, &LineNum, 512 ) )
    while( GetLine( file, line, &LineNum, 512 ) )
@@ -82,19 +106,6 @@ int S3D_MASTER::ReadData()
}
}




/*
 * Analyzes the description of the type:
 * DEF yellow material Material (
 * DiffuseColor 1.00000 1.00000 0.00000e 0
 * EmissiveColor 0.00000e 0 0.00000e 0 0.00000e 0
 * SpecularColor 1.00000 1.00000 1.00000
 * AmbientIntensity 1.00000
 * Transparency 0.00000e 0
 * Shininess 1.00000
 *)
 * Or type:
 * USE yellow material
 */
int S3D_MASTER::ReadMaterial( FILE* file, int* LineNum )
int S3D_MASTER::ReadMaterial( FILE* file, int* LineNum )
{
{
    char          line[512], * text, * command;
    char          line[512], * text, * command;
@@ -282,7 +293,9 @@ int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum )


#define BUFSIZE 2000
#define BUFSIZE 2000


/* Read a coordinate list like:
/**
 * Function ReadCoordList
 * reads 3D coordinate lists like:
 *      coord Coordinate { point [
 *      coord Coordinate { point [
 *        -5.24489 6.57640e-3 -9.42129e-2,
 *        -5.24489 6.57640e-3 -9.42129e-2,
 *        -5.11821 6.57421e-3 0.542654,
 *        -5.11821 6.57421e-3 0.542654,
@@ -294,14 +307,12 @@ int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum )
 *        0.707107 -9.38186e-7 0.707107]
 *        0.707107 -9.38186e-7 0.707107]
 *      }
 *      }
 *
 *
 *  Return the coordinate list
 *  text_buffer contains the first line of this node :
 *  text_buffer contains the first line of this node :
 *     "coord Coordinate { point ["
 *     "coord Coordinate { point ["
 */
 */
double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNum )
void ReadCoordsList( FILE* file, char* text_buffer, std::vector< double >& aList, int* LineNum )
{
{
    double*      data_list = NULL;
    unsigned int ii = 0, jj = 0;
    unsigned int ii = 0, jj = 0, nn = BUFSIZE;
    char*        text;
    char*        text;
    bool         HasData   = false;
    bool         HasData   = false;
    bool         StartData = false;
    bool         StartData = false;
@@ -324,8 +335,8 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu
            {
            {
            case '[':
            case '[':
                StartData = true;
                StartData = true;
                jj = 0; string_num[jj] = 0;
                jj = 0;
                data_list = (double*) MyZMalloc( nn * sizeof(double) );
                string_num[jj] = 0;
                break;
                break;


            case '}':
            case '}':
@@ -341,22 +352,17 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu
                if( !StartData || !HasData )
                if( !StartData || !HasData )
                    break;
                    break;


                data_list[ii]  = atof( string_num );
                aList.push_back( atof( string_num ) );
                string_num[jj] = 0;
                string_num[jj] = 0;
                ii++;
                ii++;


                if( ii >= nn )
                {
                    nn *= 2;
                    data_list = (double*) realloc( data_list, ( nn * sizeof(double) ) );
                }

                HasData = false;
                HasData = false;


                if( *text == ']' )
                if( *text == ']' )
                {
                {
                    StartData = false;
                    StartData = false;
                }
                }

                break;
                break;


            default:
            default:
@@ -367,7 +373,8 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu
                    break;
                    break;


                string_num[jj] = *text;
                string_num[jj] = *text;
                jj++; string_num[jj] = 0;
                jj++;
                string_num[jj] = 0;
                HasData = true;
                HasData = true;
                break;
                break;
            }
            }
@@ -375,14 +382,6 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu
            text++;
            text++;
        }
        }
    }
    }

    if( data_list )
        data_list = (double*) realloc( data_list, ( ii * sizeof(double) ) );

    if( bufsize )
        *bufsize = ii;

    return data_list;
}
}




@@ -390,9 +389,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )
{
{
    char    line[1024], buffer[1024], * text;
    char    line[1024], buffer[1024], * text;
    int     err    = 1;
    int     err    = 1;
    int     nn     = BUFSIZE;
    std::vector< double > points;
    double* points = NULL;
    std::vector< double > list;
    int*    index  = NULL;


    while( GetLine( file, line, LineNum, 512 ) )
    while( GetLine( file, line, LineNum, 512 ) )
    {
    {
@@ -401,7 +399,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )


        if( *text == '}' )
        if( *text == '}' )
        {
        {
            err = 0; break;
            err = 0;
            break;
        }
        }


        if( stricmp( text, "normalPerVertex" ) == 0 )
        if( stricmp( text, "normalPerVertex" ) == 0 )
@@ -432,13 +431,11 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )


        if( stricmp( text, "normal" ) == 0 )
        if( stricmp( text, "normal" ) == 0 )
        {
        {
            int     coord_number;
            ReadCoordsList( file, line, list, LineNum );
            double* buf_points = ReadCoordsList( file, line, &coord_number, LineNum );
            list.clear();

            // Do something if needed
            free( buf_points );
            continue;
            continue;
        }
        }

        if( stricmp( text, "normalIndex" ) == 0 )
        if( stricmp( text, "normalIndex" ) == 0 )
        {
        {
            while( GetLine( file, line, LineNum, 512 ) )
            while( GetLine( file, line, LineNum, 512 ) )
@@ -462,11 +459,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )


        if( stricmp( text, "color" ) == 0 )
        if( stricmp( text, "color" ) == 0 )
        {
        {
            int     coord_number;
            ReadCoordsList( file, line, list, LineNum );
            double* buf_points = ReadCoordsList( file, line, &coord_number, LineNum );
            list.clear();

            // Do something if needed
            free( buf_points );
            continue;
            continue;
        }
        }


@@ -493,17 +487,24 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )


        if( stricmp( text, "coord" ) == 0 )
        if( stricmp( text, "coord" ) == 0 )
        {
        {
            int coord_number;
            ReadCoordsList( file, line, points, LineNum );
            points = ReadCoordsList( file, line, &coord_number, LineNum );
        }
        }
        else if( stricmp( text, "coordIndex" ) == 0 )
        else if( stricmp( text, "coordIndex" ) == 0 )
        {
        {
            index = (int*) MyMalloc( nn * sizeof(int) );
            if( points.size() < 3 || points.size() % 3 != 0 )
            S3D_Vertex* coords = (S3D_Vertex*) MyMalloc( nn * sizeof(S3D_Vertex) );
            {
                wxLogError( wxT( "3D geometry read error <%s> at line %d." ),
                            GetChars( FROM_UTF8( text ) ), *LineNum );
                err = 1;
                break;
            }

            std::vector< int > coordIndex;
            std::vector< S3D_Vertex > vertices;


            while( GetLine( file, line, LineNum, 512 ) )
            while( GetLine( file, line, LineNum, 512 ) )
            {
            {
                int coord_count = 0, jj;
                int jj;
                text = strtok( line, " ,\t\n\r" );
                text = strtok( line, " ,\t\n\r" );


                while( text )
                while( text )
@@ -515,24 +516,33 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )


                    if( jj < 0 )
                    if( jj < 0 )
                    {
                    {
                        S3D_Vertex* curr_coord = coords;
                        for( jj = 0; jj < (int) coordIndex.size(); jj++ )
                        {
                            int kk = coordIndex[jj] * 3;


                        for( jj = 0; jj < coord_count; jj++ )
                            if( (kk < 0) || ((kk + 3) > points.size()) )
                            {
                            {
                            int kk = index[jj] * 3;
                                wxLogError( wxT( "3D geometry index read error <%s> at line %d." ),
                            curr_coord->x = points[kk];
                                            GetChars( FROM_UTF8( text ) ), *LineNum );
                            curr_coord->y = points[kk + 1];
                                err = 1;
                            curr_coord->z = points[kk + 2];
                                break;
                            curr_coord++;
                            }
                            }


                        Set_Object_Coords( coords, coord_count );
                            S3D_Vertex vertex;
                        Set_Object_Data( coords, coord_count );
                            vertex.x = points[kk];
                        coord_count = 0;
                            vertex.y = points[kk + 1];
                            vertex.z = points[kk + 2];
                            vertices.push_back( vertex );
                        }

                        Set_Object_Coords( vertices );
                        Set_Object_Data( vertices );
                        vertices.clear();
                        coordIndex.clear();
                    }
                    }
                    else
                    else
                    {
                    {
                        index[coord_count++] = jj;
                        coordIndex.push_back( jj );
                    }
                    }


                    text = strtok( NULL, " ,\t\n\r" );
                    text = strtok( NULL, " ,\t\n\r" );
@@ -541,20 +551,16 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )
                if( text && (*text == ']') )
                if( text && (*text == ']') )
                    break;
                    break;
            }
            }

            free( index );
            free( coords );
        }
        }
        else
        else
        {
        {
            printf( "ReadGeometry error line %d <%s> \n", *LineNum, text );
            wxLogError( wxT( "3D geometry read error <%s> at line %d." ),
                        GetChars( FROM_UTF8( text ) ), *LineNum );
            err = 1;
            break;
            break;
        }
        }
    }
    }


    if( points )
        free( points );

    return err;
    return err;
}
}


+61 −10
Original line number Original line Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
/**
 * @file 3d_struct.h
 * @file 3d_struct.h
 */
 */
@@ -32,7 +57,9 @@ class S3D_Vertex /* 3D coordinate (3 float numbers: x,y,z coordinates)*/
{
{
public:
public:
    double x, y, z;
    double x, y, z;
public: S3D_Vertex();

public:
    S3D_Vertex();
};
};


class S3D_MATERIAL : public EDA_ITEM       /* openGL "material" data*/
class S3D_MATERIAL : public EDA_ITEM       /* openGL "material" data*/
@@ -46,7 +73,8 @@ public:
    float      m_Transparency;
    float      m_Transparency;
    float      m_Shininess;
    float      m_Shininess;


public: S3D_MATERIAL( S3D_MASTER* father, const wxString& name );
public:
    S3D_MATERIAL( S3D_MASTER* father, const wxString& name );


    S3D_MATERIAL* Next() const { return (S3D_MATERIAL*) Pnext; }
    S3D_MATERIAL* Next() const { return (S3D_MATERIAL*) Pnext; }
    S3D_MATERIAL* Back() const { return (S3D_MATERIAL*) Pback; }
    S3D_MATERIAL* Back() const { return (S3D_MATERIAL*) Pback; }
@@ -66,7 +94,8 @@ public:
    Struct3D_Shape* m_3D_Drawings;
    Struct3D_Shape* m_3D_Drawings;
    S3D_MATERIAL*   m_Materials;
    S3D_MATERIAL*   m_Materials;


public: S3D_MASTER( EDA_ITEM* aParent );
public:
    S3D_MASTER( EDA_ITEM* aParent );
    ~S3D_MASTER();
    ~S3D_MASTER();


    S3D_MASTER* Next() const { return (S3D_MASTER*) Pnext; }
    S3D_MASTER* Next() const { return (S3D_MASTER*) Pnext; }
@@ -81,12 +110,27 @@ public: S3D_MASTER( EDA_ITEM* aParent );


    void Copy( S3D_MASTER* pattern );
    void Copy( S3D_MASTER* pattern );
    int  ReadData();
    int  ReadData();

    /**
     * Function ReadMaterial
     * read the description of a 3D material definition in the form:
     * DEF yellow material Material (
     * DiffuseColor 1.00000 1.00000 0.00000e 0
     * EmissiveColor 0.00000e 0 0.00000e 0 0.00000e 0
     * SpecularColor 1.00000 1.00000 1.00000
     * AmbientIntensity 1.00000
     * Transparency 0.00000e 0
     * Shininess 1.00000
     *)
     * Or type:
     * USE yellow material
     */
    int  ReadMaterial( FILE* file, int* LineNum );
    int  ReadMaterial( FILE* file, int* LineNum );
    int  ReadChildren( FILE* file, int* LineNum );
    int  ReadChildren( FILE* file, int* LineNum );
    int  ReadShape( FILE* file, int* LineNum );
    int  ReadShape( FILE* file, int* LineNum );
    int  ReadAppearance( FILE* file, int* LineNum );
    int  ReadAppearance( FILE* file, int* LineNum );
    int  ReadGeometry( FILE* file, int* LineNum );
    int  ReadGeometry( FILE* file, int* LineNum );
    void Set_Object_Coords( S3D_Vertex* coord, int nbcoord );
    void Set_Object_Coords( std::vector< S3D_Vertex >& aVertices );
};
};




@@ -98,7 +142,8 @@ public:
    int*        m_3D_CoordIndex;
    int*        m_3D_CoordIndex;
    int         m_3D_Points;
    int         m_3D_Points;


public: Struct3D_Shape( EDA_ITEM* aParent );
public:
    Struct3D_Shape( EDA_ITEM* aParent );
    ~Struct3D_Shape();
    ~Struct3D_Shape();


    Struct3D_Shape* Next() const { return (Struct3D_Shape*) Pnext; }
    Struct3D_Shape* Next() const { return (Struct3D_Shape*) Pnext; }
@@ -108,11 +153,13 @@ public: Struct3D_Shape( EDA_ITEM* aParent );
};
};




/* Display and edit a Vertex (triplet of values) in INCHES or MM or without
/**
 * units.
 * Class WinEDA_VertexCtrl
 * internal_unit is the internal unit number by inch:
 * displays a vertex for editing.  A vertex is a triplet of values in INCHES, MM,
 * - 1000 for EESchema
 * or without units.
 * - 10000 for PcbNew
 *
 * Internal_units are the internal units by inch which is  1000 for Eeschema and
 * 10000 for Pcbnew
 */
 */
class WinEDA_VertexCtrl
class WinEDA_VertexCtrl
{
{
@@ -128,6 +175,10 @@ public:


    ~WinEDA_VertexCtrl();
    ~WinEDA_VertexCtrl();


    /**
     * Function GetValue
     * @return the vertex in internal units.
     */
    S3D_Vertex GetValue();
    S3D_Vertex GetValue();
    void       SetValue( S3D_Vertex vertex );
    void       SetValue( S3D_Vertex vertex );
    void       Enable( bool enbl );
    void       Enable( bool enbl );
+52 −4
Original line number Original line Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
/**
 * @file 3d_viewer.h
 * @file 3d_viewer.h
 */
 */

#ifndef __3D_VIEWER_H__
#ifndef __3D_VIEWER_H__
#define __3D_VIEWER_H__
#define __3D_VIEWER_H__


@@ -175,6 +201,11 @@ public:
    void   OnEnterWindow( wxMouseEvent& event );
    void   OnEnterWindow( wxMouseEvent& event );


    void   Render();
    void   Render();

    /**
     * Function CreateDrawGL_List
     * creates the OpenGL draw list items.
     */
    GLuint CreateDrawGL_List();
    GLuint CreateDrawGL_List();
    void   InitGL();
    void   InitGL();
    void   SetLights();
    void   SetLights();
@@ -194,11 +225,28 @@ public:
     * @param aZpos = the z position in 3D units
     * @param aZpos = the z position in 3D units
    */
    */
    void   Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos );
    void   Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos );

    /**
     * Function Draw3D_Via
     * draws 3D via as a cylinder and filled circles.
     */
    void   Draw3D_Via( SEGVIA* via );
    void   Draw3D_Via( SEGVIA* via );
    void   Draw3D_DrawSegment( DRAWSEGMENT* segment );
    void   Draw3D_DrawSegment( DRAWSEGMENT* segment );

    /**
     * Function Draw3D_DrawText
     * draws 3D segments to create text objects.
     * When DrawGraphicText is called to draw a text to an OpenGL DC
     * it calls Draw3dTextSegm to each segment to draw.
     * 2 parameters used by Draw3D_FilledSegment are not handled by DrawGraphicText
     * but are used in Draw3D_FilledSegment().
     * they are 2 local variables. This is an ugly, but trivial code.
     * Using DrawGraphicText to draw all texts ensure texts have the same shape
     * in all contexts
     */
    void   Draw3D_DrawText( TEXTE_PCB* text );
    void   Draw3D_DrawText( TEXTE_PCB* text );


    /// Toggles ortographic projection on and off
    /// Toggles orthographic projection on and off
    void ToggleOrtho(){ m_ortho = !m_ortho ; Refresh(true);};
    void ToggleOrtho(){ m_ortho = !m_ortho ; Refresh(true);};


    /// Returns the orthographic projection flag
    /// Returns the orthographic projection flag
@@ -278,7 +326,7 @@ public:
};
};


void SetGLColor( int color );
void SetGLColor( int color );
void     Set_Object_Data( const S3D_Vertex* coord, int nbcoord );
void Set_Object_Data( std::vector< S3D_Vertex >& aVertices );


extern Info_3D_Visu g_Parm_3D_Visu;
extern Info_3D_Visu g_Parm_3D_Visu;
extern double       g_Draw3d_dx, g_Draw3d_dy;
extern double       g_Draw3d_dx, g_Draw3d_dy;
Loading