Commit 8080a2c9 authored by charras's avatar charras
Browse files

code cleaning and a bug in eeschema (print all not working) solved

parent 5a27f272
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -5,6 +5,15 @@ 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-Juil-31 UPDATE   Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+eeschema:
    Added component sheet X,Y location in BOM.
    Netlist generation: now spaces in names are replaced by '_' for pcbnew (which does not accept spaces)
    Bug: print all pages did not work.
    Please note in complex hierarchy, the current "Print All" function needs to be enhanced,
    because it does not draw all sheets but only all different sheets

2008-Jule-08 UPDATE   Andrey Fedorushkov <andrf@mail.ru>
2008-Jule-08 UPDATE   Andrey Fedorushkov <andrf@mail.ru>
================================================================================
================================================================================
+pcbnew:
+pcbnew:
+61 −6
Original line number Original line Diff line number Diff line
@@ -41,7 +41,7 @@ void WinEDA_DrawFrame::TraceWorkSheet( wxDC* DC, BASE_SCREEN* screen, int line_w
    if( Sheet == NULL )
    if( Sheet == NULL )
    {
    {
        DisplayError( this,
        DisplayError( this,
            wxT( "WinEDA_DrawFrame::TraceWorkSheet() error: m_CurrentSheet NULL" ) );
            wxT( "WinEDA_DrawFrame::TraceWorkSheet() error: NULL Sheet" ) );
        return;
        return;
    }
    }


@@ -315,6 +315,61 @@ void WinEDA_DrawFrame::TraceWorkSheet( wxDC* DC, BASE_SCREEN* screen, int line_w
}
}




/************************************************************************************************/
wxString WinEDA_DrawFrame::GetXYSheetReferences( BASE_SCREEN* aScreen, const wxPoint& aPosition )
/************************************************************************************************/

/** Function GetXYSheetReferences
 * Return the X,Y sheet references where the point position is located
 * @param aScreen = screen to use
 * @param aPosition = position to identify by YX ref
 * @return a wxString containing the message locator like A3 or B6 (or ?? if out of page limits)
 */
{
    Ki_PageDescr* Sheet = aScreen->m_CurrentSheetDesc;
    int           ii, xg, yg, ipas, gxpas, gypas;
    int           refx, refy;
    wxString      msg;

    if( Sheet == NULL )
    {
        DisplayError( this,
            wxT( "WinEDA_DrawFrame::GetXYSheetReferences() error: NULL Sheet" ) );
        return msg;
    }

    refx = Sheet->m_LeftMargin;
    refy = Sheet->m_TopMargin;                      /* Upper left corner */
    xg   = Sheet->m_Size.x - Sheet->m_RightMargin;
    yg   = Sheet->m_Size.y - Sheet->m_BottomMargin; /* lower right corner */

    /* Get the Y axis identifier (A symbol A ... Z) */
    if( aPosition.y < refy || aPosition.y > yg )  // Ouside of Y limits
        msg << wxT( "?" );
    else
    {
        ipas  = (yg - refy) / PAS_REF;      // ipas = Y count sections
        gypas = ( yg - refy) / ipas;        // gypas = Y section size
        ii    = (aPosition.y - refy) / gypas;
        msg.Printf( wxT( "%c" ), 'A' + ii );
    }

    /* Get the X axis identifier (A number 1 ... n) */
    if( aPosition.x < refx || aPosition.x > xg )  // Ouside of X limits
        msg << wxT( "?" );
    else
    {
        ipas  = (xg - refx) / PAS_REF;  // ipas = X count sections
        gxpas = ( xg - refx) / ipas;    // gxpas = X section size

        ii = (aPosition.x - refx) / gxpas;
        msg << ii + 1;
    }

    return msg;
}


/*********************************************************************/
/*********************************************************************/
wxString WinEDA_DrawFrame::GetScreenDesc()
wxString WinEDA_DrawFrame::GetScreenDesc()
/*********************************************************************/
/*********************************************************************/
+277 −238
Original line number Original line Diff line number Diff line
@@ -3,8 +3,8 @@
/***************/
/***************/


/* convertit la netliste PCAD en netliste standard (fichier temporaire)
/* convertit la netliste PCAD en netliste standard (fichier temporaire)
assure la reaffectation des alimentations selon le format :
  * assure la reaffectation des alimentations selon le format :
{I VALEUR<SEPARATEUR>(pin1,pin2,...=newalim).PRT ID
  * {I VALEUR<SEPARATEUR>(pin1,pin2,...=newalim).PRT ID
 */
 */


#include "fctsys.h"
#include "fctsys.h"
@@ -35,7 +35,8 @@ STORECMP * Cmp;
    Rjustify = 0;
    Rjustify = 0;


    /* Raz buffer et variable de gestion */
    /* Raz buffer et variable de gestion */
	if( g_BaseListeCmp ) FreeMemoryComponants();
    if( g_BaseListeCmp )
        FreeMemoryComponants();


    /* Ouverture du fichier source  */
    /* Ouverture du fichier source  */
    source = wxFopen( FFileName, wxT( "rt" ) );
    source = wxFopen( FFileName, wxT( "rt" ) );
@@ -43,7 +44,7 @@ STORECMP * Cmp;
    {
    {
        wxString msg;
        wxString msg;
        msg.Printf( _( "File <%s> not found" ), FFileName.GetData() );
        msg.Printf( _( "File <%s> not found" ), FFileName.GetData() );
		DisplayError(this, msg); return(-1);
        DisplayError( this, msg ); return -1;
    }
    }


    /* Lecture entete qui doit etre "{COMPONENT ORCAD.PCB" ou "{ OrCAD PCB"*/
    /* Lecture entete qui doit etre "{COMPONENT ORCAD.PCB" ou "{ OrCAD PCB"*/
@@ -55,7 +56,7 @@ STORECMP * Cmp;
        wxString msg, Lineconv = CONV_FROM_UTF8( Line );
        wxString msg, Lineconv = CONV_FROM_UTF8( Line );
        msg.Printf( _( "Unknown file format <%s>" ), Lineconv.GetData() );
        msg.Printf( _( "Unknown file format <%s>" ), Lineconv.GetData() );
        DisplayError( this, msg );
        DisplayError( this, msg );
		fclose(source); return(-3) ;
        fclose( source ); return -3;
    }
    }


    SetStatusText( _( "Netlist Format: Pcad" ), 0 );
    SetStatusText( _( "Netlist Format: Pcad" ), 0 );
@@ -66,15 +67,19 @@ for ( ;; )
    {
    {
        /* recherche du debut de la description d'un composant */
        /* recherche du debut de la description d'un composant */


	if ( fgets(Line,80,source) == 0 )  break ;
        if( fgets( Line, 80, source ) == 0 )
            break;


        /* suppression des blancs en d‚but de ligne */
        /* suppression des blancs en d‚but de ligne */
	i = 0 ; while (Line[i] == ' ') i++ ;
        i = 0; while( Line[i] == ' ' )
            i++;


        /* elimination des lignes vides : */
        /* elimination des lignes vides : */
	if (Line[i] < ' ') continue ;
        if( Line[i] < ' ' )
            continue;


	if (strncmp(&Line[i],"{I",2) != 0) continue ;
        if( strncmp( &Line[i], "{I", 2 ) != 0 )
            continue;


        /****************************/
        /****************************/
        /* debut description trouv‚ */
        /* debut description trouv‚ */
@@ -86,44 +91,53 @@ for ( ;; )
        {
        {
            label[j] = 0; val[j] = ' ';
            label[j] = 0; val[j] = ' ';
        }
        }

        val[16] = 0;
        val[16] = 0;


	for (j =0 ; j < 80 ; j++) alim[j] = 0 ;
        for( j = 0; j < 80; j++ )
            alim[j] = 0;


	/* lecture valeur du composant ( toujours recrire sur 8 caracteres) */
        /* lecture valeur du composant ( toujours reecrire sur 8 caracteres) */


        /* recherche fin de valeur (.PRT) */
        /* recherche fin de valeur (.PRT) */
        ptchar = strstr( Line, ".PRT" );
        ptchar = strstr( Line, ".PRT" );
        if( ptchar == 0 )
        if( ptchar == 0 )
        {
        {
		sprintf(cbuf,"Netlist error: %s\n",Line) ;
            //Netlist error: todo: display a message error
//		Affiche_Message(cbuf) ;
        }
        }
        k = ptchar - Line;
        k = ptchar - Line;


        for( j = 0; i < k; i++ )
        for( j = 0; i < k; i++ )
        {
        {
			 if ( Line[i] == SEPARATEUR ) break ;
            if( Line[i] == SEPARATEUR )
			 if ( j < 8 ) val[j++] = Line[i] ;
                break;
            if( j < 8 )
                val[j++] = Line[i];
        }
        }


        if( (Line[++i] == '(') && (Line[k - 1] == ')' ) )
        if( (Line[++i] == '(') && (Line[k - 1] == ')' ) )
        {
        {
		i++ ; l = 0 ; while ( k-1 > i ) alim[l++] = Line[i++] ;
            i++; l = 0; while( k - 1 > i )
                alim[l++] = Line[i++];
        }
        }

        else
	else	i = k ;
            i = k;


        /* recherche reference du composant */
        /* recherche reference du composant */
	while(Line[i] != ' ') i++ ; /* elimination fin valeur */
        while( Line[i] != ' ' )
	while(Line[i] == ' ') i++ ; /* recherche debut reference */
            i++;               /* elimination fin valeur */

        while( Line[i] == ' ' )
            i++;               /* recherche debut reference */


        /* debut reference trouv‚ */
        /* debut reference trouv‚ */
        for( k = 0; k < 8; i++, k++ )
        for( k = 0; k < 8; i++, k++ )
        {
        {
			if ( Line[i] <= ' ' ) break ;
            if( Line[i] <= ' ' )
                break;
            label[k] = Line[i];
            label[k] = Line[i];
        }
        }

        /* classement du composant ,suivi de sa valeur */
        /* classement du composant ,suivi de sa valeur */
        Cmp = new STORECMP();
        Cmp = new STORECMP();
        Cmp->Pnext       = g_BaseListeCmp;
        Cmp->Pnext       = g_BaseListeCmp;
@@ -139,9 +153,10 @@ for ( ;; )
    /* reclassement alpab‚tique : */
    /* reclassement alpab‚tique : */
    g_BaseListeCmp = TriListeComposantss( g_BaseListeCmp, nbcomp );
    g_BaseListeCmp = TriListeComposantss( g_BaseListeCmp, nbcomp );


	return(0);
    return 0;
}
}



/***********************************/
/***********************************/
/* pin() : analyse liste des pines */
/* pin() : analyse liste des pines */
/***********************************/
/***********************************/
@@ -156,28 +171,36 @@ for ( ;; )
    {
    {
        /* recherche du debut de la description des pins d'un composant */
        /* recherche du debut de la description des pins d'un composant */


	if ( fgets(Line,80,source) == 0 )  return(-1) ;
        if( fgets( Line, 80, source ) == 0 )
            return -1;
        /* suppression des blancs en d‚but de ligne */
        /* suppression des blancs en d‚but de ligne */
	i = 0 ; while (Line[i] == ' ') i++ ;
        i = 0; while( Line[i] == ' ' )
            i++;


        /* elimination des lignes vides : */
        /* elimination des lignes vides : */
	if (Line[i] < ' ') continue ;
        if( Line[i] < ' ' )
            continue;


	if (strncmp(&Line[i],"{CN",3) != 0) continue ;
        if( strncmp( &Line[i], "{CN", 3 ) != 0 )
            continue;


        /* debut description trouv‚ */
        /* debut description trouv‚ */
        for( ; ; )
        for( ; ; )
        {
        {
		if ( fgets(Line,80,source) == 0 )  return(-1) ;
            if( fgets( Line, 80, source ) == 0 )
                return -1;
            /* suppression des blancs en d‚but de ligne */
            /* suppression des blancs en d‚but de ligne */
		i = 0 ; while (Line[i] == ' ') i++ ;
            i = 0; while( Line[i] == ' ' )
                i++;




            /* elimination des lignes vides : */
            /* elimination des lignes vides : */
		if (Line[i] < ' ') continue ;
            if( Line[i] < ' ' )
                continue;


            /* fin de description ? */
            /* fin de description ? */
		if (Line[i] == '}' ) return(0) ;
            if( Line[i] == '}' )
                return 0;


            memset( net, 0, sizeof(net) );
            memset( net, 0, sizeof(net) );
            memset( numpin, 0, sizeof(numpin) );
            memset( numpin, 0, sizeof(numpin) );
@@ -186,9 +209,11 @@ for ( ;; )
            /* lecture name pin , 4 lettres */
            /* lecture name pin , 4 lettres */
            for( j = 0; j < 4; j++, i++ )
            for( j = 0; j < 4; j++, i++ )
            {
            {
			if ( Line[i] == ' ' ) break ;
                if( Line[i] == ' ' )
                    break;
                numpin[j] = Line[i];
                numpin[j] = Line[i];
            }
            }

            j = 0;
            j = 0;


            /* recherche affectation forc‚e de net  */
            /* recherche affectation forc‚e de net  */
@@ -199,16 +224,20 @@ for ( ;; )
            }
            }


            /* recherche netname */
            /* recherche netname */
		while(Line[i] == ' ') i++ ; /* recherche debut reference */
            while( Line[i] == ' ' )
                i++;               /* recherche debut reference */


            /* debut netname trouv‚ */
            /* debut netname trouv‚ */
            for( k = 0; k < 8; i++, k++ )
            for( k = 0; k < 8; i++, k++ )
            {
            {
			if ( Line[i] <= ' ' ) break ;
                if( Line[i] <= ' ' )
                    break;
                net[k] = Line[i];
                net[k] = Line[i];
            }
            }

            /* les pins non connect‚es sont ‚limin‚es :*/
            /* les pins non connect‚es sont ‚limin‚es :*/
		if (net[0] == '?' ) continue ;
            if( net[0] == '?' )
                continue;


//		fprintf(dest,"%s:%s\n",&numpin[j],net) ;
//		fprintf(dest,"%s:%s\n",&numpin[j],net) ;
        }
        }
@@ -219,8 +248,9 @@ for ( ;; )
/**************************************/
/**************************************/
int reaffect( char* ib, char* net )
int reaffect( char* ib, char* net )
/**************************************/
/**************************************/
/* force un nom de net pour une pine

ib = reference de pin , net = nouveau net ; alim = ligne de consigne
/* force un nom de net pour une pin
  * ib = reference de pin , net = nouveau net ; alim = ligne de consigne
 */
 */
{
{
    char* pt, * pt0, npin[12];
    char* pt, * pt0, npin[12];
@@ -235,17 +265,22 @@ while (*pt != 0 )
        /* recherche separateur (':' ou ',') */
        /* recherche separateur (':' ou ',') */
        while( (*pt != ':') && (*pt != ',') )
        while( (*pt != ':') && (*pt != ',') )
        {
        {
		pt++ ; if (*pt == 0 ) return(0) ;
            pt++; if( *pt == 0 )
                return 0;
        }
        }

        /* suppression des blancs eventuels */
        /* suppression des blancs eventuels */
        pt0 = pt; /* save position du nom du net */
        pt0 = pt; /* save position du nom du net */
	pt0-- ; while (*pt0 == ' ') pt0-- ;
        pt0--; while( *pt0 == ' ' )
            pt0--;


        for( i = 3; i >= 0; i-- )
        for( i = 3; i >= 0; i-- )
        {
        {
		if ( (*pt0 == ',') || (*pt0 ==' ')) break ;
            if( (*pt0 == ',') || (*pt0 ==' ') )
                break;
            npin[i] = *pt0;
            npin[i] = *pt0;
		if (pt0 == alim) break ;
            if( pt0 == alim )
                break;
            pt0--;
            pt0--;
        }
        }


@@ -256,19 +291,23 @@ while (*pt != 0 )
            npin[2] = npin[3];
            npin[2] = npin[3];
            npin[3] = ' ';
            npin[3] = ' ';
        }
        }

        if( strncmp( npin, ib, 4 ) == 0 ) /* pin trouv‚e */
        if( strncmp( npin, ib, 4 ) == 0 ) /* pin trouv‚e */
        {
        {
		pt++ ; while ((*pt == ' ' ) && (*pt != 0 )) pt++ ;
            pt++; while( (*pt == ' ' ) && (*pt != 0 ) )
                pt++;

            i = 0;
            i = 0;
            while( (*pt != 0) && (*pt != ',') && ( i < 8 ) )
            while( (*pt != 0) && (*pt != ',') && ( i < 8 ) )
            {
            {
                net[i++] = *pt++;
                net[i++] = *pt++;
            }
            }

            net[i] = 0;
            net[i] = 0;
		return(1) ;
            return 1;
        }
        }
        pt++;
        pt++;
    }
    }
return(0) ;
}


    return 0;
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -57,7 +57,7 @@ int WinEDA_CvpcbFrame::ReadSchematicNetlist()
    /* Read the file header (must be  "( { OrCAD PCB" or "({ OrCAD PCB" )
    /* Read the file header (must be  "( { OrCAD PCB" or "({ OrCAD PCB" )
     * or "# EESchema Netliste"
     * or "# EESchema Netliste"
     */
     */
    fgets( Line, 255, source );
    fgets( Line, BUFFER_CHAR_SIZE, source );
    /* test for netlist type PCB2 */
    /* test for netlist type PCB2 */
    i = strnicmp( Line, "( {", 3 );
    i = strnicmp( Line, "( {", 3 );
    if( i != 0 )
    if( i != 0 )
@@ -310,7 +310,7 @@ int ReadPinConnection( STORECMP* Cmp )
            memset( net, 0, sizeof(net) );
            memset( net, 0, sizeof(net) );
            memset( numpin, 0, sizeof(numpin) );
            memset( numpin, 0, sizeof(numpin) );


            /* Read pi name , 4 letters */
            /* Read pin name , 4 letters */
            for( jj = 0; jj < 4; jj++, i++ )
            for( jj = 0; jj < 4; jj++, i++ )
            {
            {
                if( Line[i] == ' ' )
                if( Line[i] == ' ' )
+16 −2
Original line number Original line Diff line number Diff line
@@ -312,8 +312,8 @@ int BuildComponentsListFromSchematic( ListComponent* aList )
                        CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ),
                        CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ),
                        sizeof( aList->m_Ref ) );
                        sizeof( aList->m_Ref ) );


                // @todo the above line is probably a bug, because it will not always nul terminate m_Ref.
                // Ensure always nul terminate m_Ref.

                aList->m_Ref[sizeof( aList->m_Ref ) - 1 ] = 0;
                aList++;
                aList++;
            }
            }
        }
        }
@@ -670,7 +670,11 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f,
        fprintf( f, "ref%cvalue", s_ExportSeparatorSymbol );
        fprintf( f, "ref%cvalue", s_ExportSeparatorSymbol );


        if( aIncludeSubComponents )
        if( aIncludeSubComponents )
        {
            fprintf( f, "%csheet path", s_ExportSeparatorSymbol );
            fprintf( f, "%csheet path", s_ExportSeparatorSymbol );
            fprintf( f, "%clocation", s_ExportSeparatorSymbol );

        }


        if( m_AddFootprintField->IsChecked() )
        if( m_AddFootprintField->IsChecked() )
            fprintf( f, "%cfootprint", s_ExportSeparatorSymbol );
            fprintf( f, "%cfootprint", s_ExportSeparatorSymbol );
@@ -737,9 +741,17 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f,
        {
        {
            msg = aList[ii].m_SheetList.PathHumanReadable();
            msg = aList[ii].m_SheetList.PathHumanReadable();
            if( CompactForm )
            if( CompactForm )
            {
                fprintf( f, "%c%s", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ) );
                fprintf( f, "%c%s", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ) );
                msg = m_Parent->GetXYSheetReferences( (BASE_SCREEN*)DrawLibItem->m_Parent, DrawLibItem->m_Pos );
                fprintf( f, "%c%s)", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ) );
            }
            else
            else
            {
                fprintf( f, "   (Sheet %s)", CONV_TO_UTF8( msg ) );
                fprintf( f, "   (Sheet %s)", CONV_TO_UTF8( msg ) );
                msg = m_Parent->GetXYSheetReferences( (BASE_SCREEN*)DrawLibItem->m_Parent, DrawLibItem->m_Pos );
                fprintf( f, "   (loc %s)", CONV_TO_UTF8( msg ) );
            }
        }
        }


        PrintFieldData( f, DrawLibItem, CompactForm );
        PrintFieldData( f, DrawLibItem, CompactForm );
@@ -811,6 +823,8 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f,
        {
        {
            msg = aList[ii].m_SheetList.PathHumanReadable();
            msg = aList[ii].m_SheetList.PathHumanReadable();
            fprintf( f, "   (Sheet %s)", CONV_TO_UTF8( msg ) );
            fprintf( f, "   (Sheet %s)", CONV_TO_UTF8( msg ) );
            msg = m_Parent->GetXYSheetReferences( (BASE_SCREEN*)DrawLibItem->m_Parent, DrawLibItem->m_Pos );
            fprintf( f, "   (loc %s)", CONV_TO_UTF8( msg ) );
        }
        }


        PrintFieldData( f, DrawLibItem );
        PrintFieldData( f, DrawLibItem );
Loading