Commit 4002c6f4 authored by CHARRAS's avatar CHARRAS
Browse files

Solved an annotation problem, some code cleanning and translation

parent 08033923
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -4,6 +4,12 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.

2007-Dec-02 UPDATE  Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+eeschema:
    Solved an annotation problem: in multiple parts per package components,
	when sorted by position, parts were not grouped by package.


2007-Dec-2 UPDATE   Dick Hollenbeck <dick@softplc.com>
================================================================================
+100 −93
Original line number Diff line number Diff line
@@ -2,17 +2,19 @@
/* annotate.cpp: component annotation */
/**************************************/

/* Local Variable */
static bool AnnotProject   = true;
static bool SortByPosition = true;

#include "annotate_dialog.cpp"

#include "netlist.h"
#include "protos.h"

/* fonctions exportees */
int         ListeComposants( CmpListStruct* BaseListeCmp, SCH_SCREEN* screen, int NumSheet );
int         AnnotTriComposant( const void* o1, const void* o2 );
void        BreakReference( CmpListStruct* BaseListeCmp, int NbOfCmp );

/* fonctions locales */
/* Local Functions*/
static int  ListeComposants( CmpListStruct* BaseListeCmp, SCH_SCREEN* screen, int NumSheet );
static int  AnnotTriComposant( const void* o1, const void* o2 );
static void BreakReference( CmpListStruct* BaseListeCmp, int NbOfCmp );
static void ReAnnotateComponents( CmpListStruct* BaseListeCmp, int NbOfCmp );
static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp );
static int  GetLastReferenceNumber( CmpListStruct* Objet, CmpListStruct* BaseListeCmp,
@@ -20,19 +22,15 @@ static int GetLastReferenceNumber( CmpListStruct* Objet, CmpListStruct* BaseLis
static int  ExistUnit( CmpListStruct* Objet, int Unit,
                       CmpListStruct* BaseListeCmp, int NbOfCmp );

/* Variable locales */
static bool AnnotProject   = TRUE;
static bool SortByPosition = TRUE;


/**************************************/
void ReAnnotatePowerSymbolsOnly()
void ReAnnotatePowerSymbolsOnly( void )
/**************************************/

/* Used to reannotate the power symbols, before testing erc or computing netlist
 *  when a true component reannotation is not necessary
 *
 *  In order to avoid conflicts the ref number start with a 0:
 *  In order to avoid conflicts the ref number starts with a 0:
 *  PWR with id 12 is named PWR12 in global annotation and PWR012 by the Power annotation
 */
{
@@ -66,9 +64,13 @@ void ReAnnotatePowerSymbolsOnly()
}


/******************************************************************/
/***********************************************************************/
void InstallAnnotateFrame( WinEDA_SchematicFrame* parent, wxPoint& pos )
/******************************************************************/
/***********************************************************************/

/** Function InstallAnnotateFrame
 * Install the annotate dialog frame
 */
{
    WinEDA_AnnotateFrame* frame = new WinEDA_AnnotateFrame( parent );

@@ -81,7 +83,7 @@ void InstallAnnotateFrame( WinEDA_SchematicFrame* parent, wxPoint& pos )
void WinEDA_AnnotateFrame::AnnotateComponents( wxCommandEvent& event )
/******************************************************************/

/*
/** Function WinEDA_AnnotateFrame::AnnotateComponents
 *  Compute the annotation of the components for the whole projeect, or the current sheet only.
 *  All the components or the new ones only will be annotated.
 */
@@ -92,8 +94,8 @@ void WinEDA_AnnotateFrame::AnnotateComponents( wxCommandEvent& event )

    wxBusyCursor   dummy;

    AnnotProject   = (m_AnnotProjetCtrl->GetSelection() == 0) ? TRUE : FALSE;
    SortByPosition = (m_AnnotSortCmpCtrl->GetSelection() == 0) ? TRUE : FALSE;
    AnnotProject   = (m_AnnotProjetCtrl->GetSelection() == 0) ? true : FALSE;
    SortByPosition = (m_AnnotSortCmpCtrl->GetSelection() == 0) ? true : FALSE;

    /* If it is an annotation for all the components, reset previous annotation: */
    if( m_AnnotNewCmpCtrl->GetSelection() == 0 )
@@ -113,7 +115,7 @@ void WinEDA_AnnotateFrame::AnnotateComponents( wxCommandEvent& event )

    /* First pass: Component counting */
    screen = (SCH_SCREEN*) m_Parent->m_CurrentScreen;
    if( AnnotProject == TRUE )
    if( AnnotProject == true )
    {
        NbOfCmp = 0;
        for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
@@ -132,7 +134,7 @@ void WinEDA_AnnotateFrame::AnnotateComponents( wxCommandEvent& event )

    /* Second pass : Int data tables */
    screen = (SCH_SCREEN*) m_Parent->m_CurrentScreen;
    if( AnnotProject == TRUE )
    if( AnnotProject == true )
    {
        ii = 0;
        for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
@@ -147,22 +149,22 @@ void WinEDA_AnnotateFrame::AnnotateComponents( wxCommandEvent& event )
    if( ii != NbOfCmp )
        DisplayError( this, wxT( "Internal error in AnnotateComponents()" ) );

    /* Separation des Numeros de la reference: IC1 -> IC, et 1 dans .m_NumRef */
    /* Break full components reference in name (prefix) and number: example: IC1 become IC, and 1 */
    BreakReference( BaseListeCmp, NbOfCmp );

    qsort( BaseListeCmp, NbOfCmp, sizeof(CmpListStruct),
           ( int( * ) ( const void*, const void* ) )AnnotTriComposant );

    /* Recalcul des numeros de reference */
    /* Recalculate reference numbers */
    ComputeReferenceNumber( BaseListeCmp, NbOfCmp );
    ReAnnotateComponents( BaseListeCmp, NbOfCmp );

    MyFree( BaseListeCmp ); BaseListeCmp = NULL;

    /* Final control */
    CheckAnnotate( m_Parent, AnnotProject ? FALSE : TRUE );
    CheckAnnotate( m_Parent, AnnotProject ? FALSE : true );

    m_Parent->DrawPanel->Refresh( TRUE ); /* Refresh screen */
    m_Parent->DrawPanel->Refresh( true ); /* Refresh screen */
    EndModal( 1 );
}

@@ -181,10 +183,10 @@ void WinEDA_AnnotateFrame::DeleteAnnotation( wxCommandEvent& event )

    if( !IsOK( this, _( "Previous Annotation will be deleted. Continue ?" ) ) )
    {
        m_Abort = TRUE; return;
        m_Abort = true; return;
    }

    AnnotProject = (m_AnnotProjetCtrl->GetSelection() == 0) ? TRUE : FALSE;
    AnnotProject = (m_AnnotProjetCtrl->GetSelection() == 0) ? true : FALSE;
    m_Abort = FALSE;

    /* Build the screen list */
@@ -197,7 +199,7 @@ void WinEDA_AnnotateFrame::DeleteAnnotation( wxCommandEvent& event )

    ScreenSch->SetModify();

    if( AnnotProject == TRUE )
    if( AnnotProject == true )
        screen = ScreenList.GetFirst();
    else
        screen = (SCH_SCREEN*) m_Parent->m_CurrentScreen;
@@ -218,7 +220,7 @@ void WinEDA_AnnotateFrame::DeleteAnnotation( wxCommandEvent& event )
            break;
    }

    m_Parent->DrawPanel->Refresh( TRUE );
    m_Parent->DrawPanel->Refresh( true );
    EndModal( 0 );
}

@@ -321,18 +323,16 @@ int AnnotTriComposant( const void* o1, const void* o2 )

    int            ii = strnicmp( Objet1->m_TextRef, Objet2->m_TextRef, 32 );

    if( SortByPosition == TRUE )
    if( SortByPosition == true )
    {
        if( ii == 0 )
            ii = Objet1->m_Sheet - Objet2->m_Sheet;
        if( ii == 0 )
            ii = Objet1->m_Unit - Objet2->m_Unit;
        if( ii == 0 )
            ii = Objet1->m_Pos.x - Objet2->m_Pos.x;
        if( ii == 0 )
            ii = Objet1->m_Pos.y - Objet2->m_Pos.y;
    }
    else
    else    // Sort by value
    {
        if( ii == 0 )
            ii = strnicmp( Objet1->m_TextValue, Objet2->m_TextValue, 32 );
@@ -340,6 +340,10 @@ int AnnotTriComposant( const void* o1, const void* o2 )
            ii = Objet1->m_Unit - Objet2->m_Unit;
        if( ii == 0 )
            ii = Objet1->m_Sheet - Objet2->m_Sheet;
        if( ii == 0 )
            ii = Objet1->m_Pos.x - Objet2->m_Pos.x;
        if( ii == 0 )
            ii = Objet1->m_Pos.y - Objet2->m_Pos.y;
    }

    if( ii == 0 )
@@ -384,19 +388,16 @@ static void ReAnnotateComponents( CmpListStruct* BaseListeCmp, int NbOfCmp )
void BreakReference( CmpListStruct* BaseListeCmp, int NbOfCmp )
/**************************************************************/

/* Modifie dans BaseListeCmp la reference des composants en supprimant la
 *  partie nombre de la partie texte.
 *  Place le nombre dans .m_NumRef
 *  Pour les composants multiples non encore annotes, met .m_Unit a sa valeur max
 *  Utilise:
 *      BaseListeCmp
 *      NbOfCmp
/** BreakReference
 *  Break full components reference in name (prefix) and number: example: IC1 become IC, and 1 in .m_NumRef
 *  For multi part per package components not already annotated, set .m_Unit to a max value (0x7FFFFFFF)
 *  @param BaseListeCmp = list of component
 *  @param NbOfCmp	= item count in the list
 */
{
    int   ii, ll;
    char* Text;

    /* Separation des Numeros de la reference: IC1 -> IC, et 1 dans .m_NumRef */
    for( ii = 0; ii < NbOfCmp; ii++ )
    {
        BaseListeCmp[ii].m_NumRef = -1;
@@ -404,7 +405,7 @@ void BreakReference( CmpListStruct* BaseListeCmp, int NbOfCmp )
        ll   = strlen( Text ) - 1;
        if( Text[ll] == '?' )
        {
            BaseListeCmp[ii].m_IsNew = TRUE;
            BaseListeCmp[ii].m_IsNew = true;
            if( !BaseListeCmp[ii].m_PartsLocked )
                BaseListeCmp[ii].m_Unit = 0x7FFFFFFF;
            Text[ll] = 0;
@@ -413,7 +414,7 @@ void BreakReference( CmpListStruct* BaseListeCmp, int NbOfCmp )

        if( isdigit( Text[ll] ) == 0 )
        {
            BaseListeCmp[ii].m_IsNew = TRUE;
            BaseListeCmp[ii].m_IsNew = true;
            if( !BaseListeCmp[ii].m_PartsLocked )
                BaseListeCmp[ii].m_Unit = 0x7FFFFFFF;
            continue;
@@ -453,7 +454,7 @@ static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp )
        Text = BaseListeCmp[ii].m_TextRef;
        if( *Text == '#' )
        {
            BaseListeCmp[ii].m_IsNew  = TRUE;
            BaseListeCmp[ii].m_IsNew  = true;
            BaseListeCmp[ii].m_NumRef = 0;
        }
    }
@@ -472,7 +473,7 @@ static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp )
            LastReferenceNumber = GetLastReferenceNumber( BaseListeCmp + ii, BaseListeCmp, NbOfCmp );
        }

        /* Annotation of mono-part components ( 1 part per package ) (trivial case)*/
        /* Annotation of one part per package components (trivial case)*/
        if( BaseListeCmp[ii].m_NbParts <= 1 )
        {
            if( BaseListeCmp[ii].m_IsNew )
@@ -514,13 +515,12 @@ static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp )
                    continue;
                Text = BaseListeCmp[jj].m_TextRef;
                if( strnicmp( RefText, Text, 32 ) != 0 )
                    break;                                      // references are different
                    continue; // references are different
                Text = BaseListeCmp[jj].m_TextValue;
                if( strnicmp( ValText, Text, 32 ) != 0 )
                    break;                                      // values are different
                    continue; // values are different
                if( !BaseListeCmp[jj].m_IsNew )
                {
                    //BaseListeCmp[jj].m_Flag = 1;
                    continue;
                }
                /* Component without reference number found, annotate it if possible */
@@ -542,9 +542,13 @@ static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp )
static int GetLastReferenceNumber( CmpListStruct* Objet, CmpListStruct* BaseListeCmp, int NbOfCmp )
/*************************************************************************************************/

/* Recherche le plus grand numero de reference dans les composants
 *  de meme prefixe de reference que celui pointe par Objet
 *  la liste des composants est supposee triee
/** Function GetLastReferenceNumber
 *  Search the last (bigger) reference number in the component list
 *  for the prefix reference given by Objet
 *  The component list must be sorted
 * @param Objet = reference item ( Objet->m_TextRef is the search pattern)
 * @param BaseListeCmp = list of items
 * @param NbOfCmp = items count in list of items
 */
{
    CmpListStruct* LastObjet  = BaseListeCmp + NbOfCmp;
@@ -608,9 +612,10 @@ static int ExistUnit( CmpListStruct* Objet, int Unit,
int CheckAnnotate( WinEDA_SchematicFrame* frame, bool OneSheetOnly )
/******************************************************************/

/* Retourne le nombre de composants non annots ou de meme rfrence (doubls)
 *  Si OneSheetOnly : recherche sur le schema courant
 *  sinon: recherche sur toute la hierarchie
/** Function CheckAnnotate
 * @return composent count ( which are not annotated or have the same reference (duplicates))
 * @param OneSheetOnly : true = search is made only in the current sheet
 *                       false = search in whole hierarchy (usual search).
 */
{
    int            NbSheet, ii, NumSheet = 1, error, NbOfCmp;
@@ -619,7 +624,7 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool OneSheetOnly )
    wxString       Buff;
    wxString       msg, cmpref;

    /* build tje screen list */
    /* build the screen list */
    EDA_ScreenList ScreenList( NULL );

    NbSheet = ScreenList.GetCount();
@@ -628,7 +633,7 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool OneSheetOnly )
    ScreenSch->SetModify();
    ScreenList.UpdateSheetNumberAndDate();

    /* 1ere passe : Comptage du nombre de composants */
    /* first pass : count composents */
    screen = (SCH_SCREEN*) frame->m_CurrentScreen;
    if( !OneSheetOnly )
    {
@@ -647,10 +652,11 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool OneSheetOnly )
        return 0;
    }


    /* Second pass : create the list of components */
    ii = sizeof(CmpListStruct) * NbOfCmp;
    ListeCmp = (CmpListStruct*) MyZMalloc( ii );

    /* 2eme passe : Remplissage du tableau des caracteristiques */
    if( OneSheetOnly == 0 )
    {
        ii     = 0;
@@ -668,10 +674,10 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool OneSheetOnly )

    qsort( ListeCmp, NbOfCmp, sizeof(CmpListStruct), AnnotTriComposant );

    /* Separation des Numeros de la reference: IC1 -> IC, et 1 dans .m_NumRef */
    /* Break full components reference in name (prefix) and number: example: IC1 become IC, and 1 */
    BreakReference( ListeCmp, NbOfCmp );

    /* comptage des elements non annotes */
    /* count not yet annotated items */
    error = 0;
    for( ii = 0; ii < NbOfCmp - 1; ii++ )
    {
@@ -729,9 +735,10 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool OneSheetOnly )
        if( (stricmp( ListeCmp[ii].m_TextRef, ListeCmp[ii + 1].m_TextRef ) != 0)
           || ( ListeCmp[ii].m_NumRef != ListeCmp[ii + 1].m_NumRef ) )
            continue;
        /* Meme reference trouve */

        /* Il y a erreur si meme unite */
        /* Same reference found */

        /* If same unit, error ! */
        if( ListeCmp[ii].m_Unit == ListeCmp[ii + 1].m_Unit )
        {
            if( ListeCmp[ii].m_NumRef >= 0 )
@@ -753,8 +760,8 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool OneSheetOnly )
            continue;
        }

        /* Il y a erreur si unites differentes mais nombre de parts differentes
         *  par boitier (ex U3 ( 1 part) et U3B sont incompatibles) */
        /* Test error if units are different but number of parts per package to hight
          * (ex U3 ( 1 part) and we find U3B the is an error) */
        if( ListeCmp[ii].m_NbParts != ListeCmp[ii + 1].m_NbParts )
        {
            if( ListeCmp[ii].m_NumRef >= 0 )
@@ -775,7 +782,7 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool OneSheetOnly )
            error++;
        }

        /* Il y a erreur si unites differentes ET valeurs diffrentes */
        /* Error if values are diffrent between units, for the same reference */
        if( stricmp( ListeCmp[ii].m_TextValue, ListeCmp[ii + 1].m_TextValue ) != 0 )
        {
            wxString nextcmpref, cmpvalue, nextcmpvalue;
+2 −0
Original line number Diff line number Diff line
@@ -155,6 +155,8 @@ void WinEDA_AnnotateFrame::CreateControls()
    itemBoxSizer7->Add(itemButton10, 0, wxGROW|wxALL, 5);

////@end WinEDA_AnnotateFrame content construction

	m_AnnotSortCmpCtrl->SetSelection(SortByPosition ? 0 : 1);
}

/*!
+1 −1
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event )
        break;

    case ID_PCB_GLOBAL_DELETE:
        Erase_Current_Layer( &dc, TRUE );
        Erase_Current_Layer( TRUE );
        break;

    case wxID_CUT:
+3 −3
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )
    {
    case ID_MENU_LOAD_FILE:
    case ID_LOAD_FILE:
        if( Clear_Pcb( &dc, TRUE ) )
        if( Clear_Pcb( TRUE ) )
        {
            LoadOneGerberFile( wxEmptyString, &dc, 0 );
        }
@@ -56,7 +56,7 @@ void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )

    case ID_MENU_NEW_BOARD:
    case ID_NEW_BOARD:
        Clear_Pcb( &dc, TRUE );
        Clear_Pcb( TRUE );
        Zoom_Automatique( FALSE );
        GetScreen()->SetRefreshReq();
        break;
@@ -71,7 +71,7 @@ void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )
    case ID_LOAD_FILE_8:
    case ID_LOAD_FILE_9:
    case ID_LOAD_FILE_10:
        if( Clear_Pcb( &dc, TRUE ) )
        if( Clear_Pcb( TRUE ) )
        {
            LoadOneGerberFile(
                GetLastProject( id - ID_LOAD_FILE_1 ).GetData(),
Loading