Commit dd9497a1 authored by CHARRAS's avatar CHARRAS
Browse files

Fixed: problem which could crash eeschema when a schematic file in a hierarchy was not found

parent e92706bc
Loading
Loading
Loading
Loading
+6 −0
Original line number 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
email address.

2008-Feb-26 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+eeschema
	Fixed: problem which could crash eeschema when a sub schematic file in a hierarchy was not found.


2008-Feb-27 UPDATE  Wayne Stambaugh <stambaughw{at}verizon{dot}net>
================================================================================
+ eeschema
+160 −117
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@

/* Local Functions*/
static int  ListeComposants( CmpListStruct* BaseListeCmp,
                             DrawSheetList* sheet );
                             DrawSheetPath* sheet );
static void BreakReference( CmpListStruct* BaseListeCmp, int NbOfCmp );
static void ReAnnotateComponents( CmpListStruct* BaseListeCmp, int NbOfCmp );
static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp );
@@ -24,6 +24,48 @@ static int ExistUnit( CmpListStruct* Objet, int Unit,
                       CmpListStruct* BaseListeCmp, int NbOfCmp );


/************************************************/
void WinEDA_SchematicFrame::UpdateSheetNumberAndDate()
/************************************************/

/* Set a sheet number, the sheet count for sheets in the whole schematic
 * and update the date in all screens
 */
{
    wxString       date = GenDate();
    int            sheet_number = 1; // sheet 1 is the root sheet
    DrawSheetPath* sheetpath;

    /* Build the sheet list */
    EDA_SheetList  SheetList( g_RootSheet );
    int            sheet_count = SheetList.GetCount();

    for( sheetpath = SheetList.GetFirst();
        sheetpath != NULL;
        sheetpath = SheetList.GetNext() )
    {
        // Read all sheets in path, but not the root sheet (jj = 1)
        for( int jj = 1; jj < sheetpath->m_numSheets; jj++ )
        {
            DrawSheetStruct* sheet = sheetpath->m_sheets[jj];
            sheet->m_SheetNumber    = sheet_number++;
            sheet->m_NumberOfSheets = sheet_count;
            SCH_SCREEN*      screen = sheet->m_AssociatedScreen;
            if( screen != NULL )
            {
                screen->m_NumberOfScreen = sheet_count;
                screen->m_Date = date;
            }
        }
    }

    g_RootSheet->m_AssociatedScreen->m_Date = date;
    g_RootSheet->m_AssociatedScreen->m_NumberOfScreen = sheet_count;
    g_RootSheet->m_SheetNumber    = 1;
    g_RootSheet->m_NumberOfSheets = sheet_count;
}


/*****************************************************************************
 * Used to annotate the power symbols, before testing erc or computing
 * netlist when a component reannotation is not necessary
@@ -38,7 +80,7 @@ void ReAnnotatePowerSymbolsOnly( void )
    EDA_SheetList  SheetList( NULL );


    DrawSheetList* sheet;
    DrawSheetPath* sheet;
    int            CmpNumber = 1;

    for( sheet = SheetList.GetFirst();
@@ -179,21 +221,21 @@ void AnnotateComponents( WinEDA_SchematicFrame* parent,
                         bool                   resetAnnotation )
{
    int            ii, NbOfCmp;
    DrawSheetList* sheet;
    DrawSheetPath* sheet;
    CmpListStruct* BaseListeCmp;

    wxBusyCursor   dummy;

    /* If it is an annotation for all the components, reset previous
       annotation: */
      * annotation: */
    if( resetAnnotation )
        DeleteAnnotation( parent, annotateSchematic );

    /* Build the sheet list */
    EDA_SheetList SheetList( g_RootSheet );

    /* Update the screen number, sheet count and date */
    SheetList.UpdateSheetNumberAndDate();
    /* Update the sheet number, sheet count and date */
    parent->UpdateSheetNumberAndDate();

    /* First pass: Component counting */
    ii    = 0;
@@ -230,7 +272,7 @@ void AnnotateComponents( WinEDA_SchematicFrame* parent,
        DisplayError( parent, wxT( "Internal error in AnnotateComponents()" ) );

    /* Break full components reference in name (prefix) and number:
       example: IC1 become IC, and 1 */
      * example: IC1 become IC, and 1 */
    BreakReference( BaseListeCmp, NbOfCmp );

    if( sortByPosition )
@@ -257,7 +299,7 @@ void AnnotateComponents( WinEDA_SchematicFrame* parent,
* if BaseListeCmp == NULL : count components
*  else update data table BaseListeCmp
*****************************************************************************/
int ListeComposants( CmpListStruct* BaseListeCmp, DrawSheetList* sheet )
int ListeComposants( CmpListStruct* BaseListeCmp, DrawSheetPath* sheet )
{
    int                     NbrCmp   = 0;
    EDA_BaseStruct*         DrawList = sheet->LastDrawList();
@@ -448,7 +490,7 @@ static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp )
        }

        /* Annotation of multi-part components ( n parts per package )
           (complex case) */
          * (complex case) */
        ValText = BaseListeCmp[ii].m_TextValue;
        NumberOfUnits = BaseListeCmp[ii].m_NbParts;

@@ -486,10 +528,11 @@ static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp )
                {
                    continue;
                }

                /* Component without reference number found, annotate it if
                   possible */
                if( !BaseListeCmp[jj].m_PartsLocked ||
                    (BaseListeCmp[jj].m_Unit == Unit) )
                  * possible */
                if( !BaseListeCmp[jj].m_PartsLocked
                   || (BaseListeCmp[jj].m_Unit == Unit) )
                {
                    BaseListeCmp[jj].m_NumRef = BaseListeCmp[ii].m_NumRef;
                    BaseListeCmp[jj].m_Unit   = Unit;
@@ -588,7 +631,7 @@ static int ExistUnit( CmpListStruct* Objet, int Unit,
int CheckAnnotate( WinEDA_SchematicFrame* frame, bool oneSheetOnly )
{
    int            ii, error, NbOfCmp;
    DrawSheetList* sheet;
    DrawSheetPath* sheet;
    CmpListStruct* ListeCmp = NULL;
    wxString       Buff;
    wxString       msg, cmpref;
@@ -638,7 +681,7 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool oneSheetOnly )
    qsort( ListeCmp, NbOfCmp, sizeof(CmpListStruct), AnnotateByValue );

    /* Break full components reference in name (prefix) and number: example:
       IC1 become IC, and 1 */
      * IC1 become IC, and 1 */
    BreakReference( ListeCmp, NbOfCmp );

    /* count not yet annotated items */
@@ -700,8 +743,8 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool oneSheetOnly )
        Buff.Empty();

        if( (stricmp( ListeCmp[ii].m_TextRef,
                      ListeCmp[ii + 1].m_TextRef ) != 0)||
            ( ListeCmp[ii].m_NumRef != ListeCmp[ii + 1].m_NumRef ) )
                 ListeCmp[ii + 1].m_TextRef ) != 0)
           || ( ListeCmp[ii].m_NumRef != ListeCmp[ii + 1].m_NumRef ) )
            continue;

        /* Same reference found */
+1 −1
Original line number Diff line number Diff line
@@ -208,7 +208,7 @@ void WinEDA_AnnotateFrame::CreateControls()
    /* TODO: Check if there is any existing annotation and enable/disable
     *       the clear button accordingly.  Probably should also enable/
     *       disable new components radio button if all of the components
     *       are already annotated.  Some low level work on the DrawSheetList
     *       are already annotated.  Some low level work on the DrawSheetPath
     *       class will need to be done to accomadate this.
     */
    m_btnClear = new wxButton( this, wxID_CLEAR );
+54 −48
Original line number Diff line number Diff line
@@ -689,6 +689,7 @@ void MirrorOneStruct( EDA_BaseStruct* DrawStruct, wxPoint& Center )

    case DRAW_HIER_LABEL_STRUCT_TYPE:
    case DRAW_GLOBAL_LABEL_STRUCT_TYPE:

        // Text is not really mirrored: Orientation is changed
        DrawText = (DrawLabelStruct*) DrawStruct;
        if( DrawText->m_Orient == 0 )       /* horizontal text */
@@ -837,6 +838,7 @@ static EDA_BaseStruct* CopyStruct( WinEDA_DrawPanel* panel, wxDC* DC, BASE_SCREE
                //m_AssociatedScreen and m_sRefCount properly.
                DrawSheetStruct* sheet = (DrawSheetStruct*) Struct;
                sheet->m_TimeStamp = GetTimeStamp();

                //sheet->m_AssociatedScreen->m_UndoList  = NULL;
                //sheet->m_AssociatedScreen->m_RedoList  = NULL;
                //keep m_AssociatedScreen pointer & associated.
@@ -962,11 +964,15 @@ void DeleteStruct( WinEDA_DrawPanel* panel, wxDC* DC, EDA_BaseStruct* DrawStruct
        RedrawOneStruct( panel, DC, DrawStruct, g_XorMode );
        /* Unlink the structure */
        DrawStruct->Pnext = DrawStruct->Pback = NULL;   // Only one struct -> no link
		if(DrawStruct->Type() == DRAW_SHEET_STRUCT_TYPE){
			SAFE_DELETE(DrawStruct);  
        if( DrawStruct->Type() == DRAW_SHEET_STRUCT_TYPE )
        {
            frame->SaveCopyInUndoList( DrawStruct, IS_DELETED );	// Currently In TEST

//			SAFE_DELETE(DrawStruct);
            //no undo/redo for this (for now), it is on both the EEDrawList and m_SubSheet arrays,
            //hence the undo logic would have to be extended for this.
		}else
        }
        else
            frame->SaveCopyInUndoList( DrawStruct, IS_DELETED );
    }
}
+51 −30
Original line number Diff line number Diff line
@@ -43,10 +43,11 @@ DrawSheetStruct::DrawSheetStruct( const wxPoint& pos ) :
    m_NbLabel = 0;
    m_Layer   = LAYER_SHEET;
    m_Pos = pos;
	m_TimeStamp = GetTimeStamp();
    m_SheetNameSize = m_FileNameSize = 60;
    m_AssociatedScreen = NULL;
    m_SheetName = wxT( "Root" );
    m_FileName  = wxT( " " );
    m_SheetName.Printf( wxT("Sheet%8.8lX"), m_TimeStamp);
    m_FileName.Printf( wxT("file%8.8lX.sch"), m_TimeStamp);
	m_SheetNumber = 1;
    m_NumberOfSheets = 1;

@@ -351,7 +352,7 @@ bool DrawSheetStruct::SearchHierarchy( wxString filename, SCH_SCREEN** screen )


/*******************************************************************************/
bool DrawSheetStruct::LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetList* list )
bool DrawSheetStruct::LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* list )
/*******************************************************************************/
{
    //search the existing hierarchy for an instance of screen "FileName".
@@ -386,6 +387,8 @@ bool DrawSheetStruct::LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetList* lis
bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame )
/*******************************************************************************/
{
	bool success = true;

    if( !m_AssociatedScreen )
    {
        SCH_SCREEN* screen = NULL;
@@ -401,22 +404,24 @@ bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame )
        {
            m_AssociatedScreen = new SCH_SCREEN( SCHEMATIC_FRAME );
            m_AssociatedScreen->m_RefCount++;
            if( !frame->LoadOneEEFile( m_AssociatedScreen, m_FileName ) )
                return false;
            success = frame->LoadOneEEFile( m_AssociatedScreen, m_FileName);
			if ( success )
			{
				EDA_BaseStruct* bs = m_AssociatedScreen->EEDrawList;
				while( bs )
				{
					if( bs->Type() ==  DRAW_SHEET_STRUCT_TYPE )
					{
                    DrawSheetStruct* ss = (DrawSheetStruct*) bs;
                    if( !ss->Load( frame ) )
                        return false;
						DrawSheetStruct* sheetstruct = (DrawSheetStruct*) bs;
						if( !sheetstruct->Load( frame ) )
							success = false;
					}
					bs = bs->Pnext;
				}
			}
        }
    return true;
    }
    return success;
}


@@ -442,6 +447,21 @@ int DrawSheetStruct::CountSheets()
}


/******************************************/
wxString DrawSheetStruct::GetFileName(void)
/******************************************/
{
	return m_FileName;
}


/************************************************************/
void DrawSheetStruct::SetFileName(const wxString & aFilename)
/************************************************************/
{
	m_FileName = aFilename;
}

/************************/
/* DrawSheetLabelStruct */
/************************/
@@ -571,7 +591,7 @@ void DrawSheetLabelStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoin
/* class to handle a series of sheets *********/
/* a 'path' so to speak.. *********************/
/**********************************************/
DrawSheetList::DrawSheetList()
DrawSheetPath::DrawSheetPath()
{
    for( int i = 0; i<DSLSZ; i++ )
        m_sheets[i] = NULL;
@@ -580,7 +600,7 @@ DrawSheetList::DrawSheetList()
}


int DrawSheetList::Cmp( DrawSheetList& d )
int DrawSheetPath::Cmp( DrawSheetPath& d )
{
    if( m_numSheets > d.m_numSheets )
        return 1;
@@ -600,7 +620,7 @@ int DrawSheetList::Cmp( DrawSheetList& d )
}


DrawSheetStruct* DrawSheetList::Last()
DrawSheetStruct* DrawSheetPath::Last()
{
    if( m_numSheets )
        return m_sheets[m_numSheets - 1];
@@ -608,7 +628,7 @@ DrawSheetStruct* DrawSheetList::Last()
}


SCH_SCREEN* DrawSheetList::LastScreen()
SCH_SCREEN* DrawSheetPath::LastScreen()
{
    if( m_numSheets )
        return m_sheets[m_numSheets - 1]->m_AssociatedScreen;
@@ -616,7 +636,7 @@ SCH_SCREEN* DrawSheetList::LastScreen()
}


EDA_BaseStruct* DrawSheetList::LastDrawList()
EDA_BaseStruct* DrawSheetPath::LastDrawList()
{
    if( m_numSheets && m_sheets[m_numSheets - 1]->m_AssociatedScreen )
        return m_sheets[m_numSheets - 1]->m_AssociatedScreen->EEDrawList;
@@ -624,8 +644,9 @@ EDA_BaseStruct* DrawSheetList::LastDrawList()
}


void DrawSheetList::Push( DrawSheetStruct* sheet )
void DrawSheetPath::Push( DrawSheetStruct* sheet )
{
	wxASSERT( m_numSheets <= DSLSZ );
    if( m_numSheets < DSLSZ )
    {
        m_sheets[m_numSheets] = sheet;
@@ -634,7 +655,7 @@ void DrawSheetList::Push( DrawSheetStruct* sheet )
}


DrawSheetStruct* DrawSheetList::Pop()
DrawSheetStruct* DrawSheetPath::Pop()
{
    if( m_numSheets > 0 )
    {
@@ -645,7 +666,7 @@ DrawSheetStruct* DrawSheetList::Pop()
}


wxString DrawSheetList::Path()
wxString DrawSheetPath::Path()
{
    wxString s, t;

@@ -664,7 +685,7 @@ wxString DrawSheetList::Path()
}


wxString DrawSheetList::PathHumanReadable()
wxString DrawSheetPath::PathHumanReadable()
{
    wxString s, t;

@@ -680,7 +701,7 @@ wxString DrawSheetList::PathHumanReadable()
}


void DrawSheetList::UpdateAllScreenReferences()
void DrawSheetPath::UpdateAllScreenReferences()
{
    EDA_BaseStruct* t = LastDrawList();

@@ -698,7 +719,7 @@ void DrawSheetList::UpdateAllScreenReferences()
}


bool DrawSheetList::operator=( const DrawSheetList& d1 )
bool DrawSheetPath::operator=( const DrawSheetPath& d1 )
{
    m_numSheets = d1.m_numSheets;
    int i;
@@ -716,7 +737,7 @@ bool DrawSheetList::operator=( const DrawSheetList& d1 )
}


bool DrawSheetList::operator==( const DrawSheetList& d1 )
bool DrawSheetPath::operator==( const DrawSheetPath& d1 )
{
    if( m_numSheets != d1.m_numSheets )
        return false;
@@ -730,7 +751,7 @@ bool DrawSheetList::operator==( const DrawSheetList& d1 )
}


bool DrawSheetList::operator!=( const DrawSheetList& d1 )
bool DrawSheetPath::operator!=( const DrawSheetPath& d1 )
{
    if( m_numSheets != d1.m_numSheets )
        return true;
Loading