Commit c586d973 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Eeschema: fix bug #142970 (broken append sheet function)

Fix a few minor coverity warnings.
parent 035b231b
Loading
Loading
Loading
Loading
+47 −6
Original line number Original line Diff line number Diff line
@@ -359,19 +359,60 @@ bool SCH_EDIT_FRAME::AppendOneEEProject()


    wxLogDebug( wxT( "Importing schematic " ) + fullFileName );
    wxLogDebug( wxT( "Importing schematic " ) + fullFileName );


    // Keep trace of the last item in list.
    // New items will be loaded after this one.
    SCH_ITEM* bs = screen->GetDrawItems();

    if( bs )
        while( bs->Next() )
            bs = bs->Next();

    // load the project
    // load the project
    bool success = LoadOneEEFile( screen, fullFileName, true );
    bool success = LoadOneEEFile( screen, fullFileName, true );


    if( success )
    if( success )
    {
    {
        // load sub-sheets
        // the new loaded items need cleaning to avoid duplicate parameters
        EDA_ITEM* bs = screen->GetDrawItems();
        // which should be unique (ref and time stamp).
        // Clear ref and set a new time stamp for new items
        if( bs == NULL )
            bs = screen->GetDrawItems();
        else
            bs = bs->Next();

        while( bs )
        while( bs )
        {
        {
            // do not append hierarchical sheets
            SCH_ITEM* nextbs = bs->Next();

            // To avoid issues with the current hieratchy,
            // do not load included sheets files and give new filenames
            // and new sheet names.
            // There are many tricky cases (loops, creation of complex hierarchies
            // with duplicate file names, duplicate sheet names...)
            // So the included sheets names are renamed if existing,
            // and filenames are just renamed to avoid loops and
            // creation of complex hierarchies.
            // If someone want to change it for a better append function, remember
            // these cases need work to avoid issues.
            if( bs->Type() == SCH_SHEET_T )
            if( bs->Type() == SCH_SHEET_T )
            {
            {
                screen->Remove( (SCH_SHEET*) bs );
                SCH_SHEET * sheet = (SCH_SHEET *) bs;
                time_t newtimestamp = GetNewTimeStamp();
                sheet->SetTimeStamp( newtimestamp );

                // Check for existing subsheet name in the current sheet
                wxString tmp = sheet->GetName();
                sheet->SetName( wxEmptyString );
                const SCH_SHEET* subsheet = GetScreen()->GetSheet( tmp );

                if( subsheet )
                    sheet->SetName( wxString::Format( wxT( "Sheet%8.8lX" ), (long) newtimestamp ) );
                else
                    sheet->SetName( tmp );

                sheet->SetFileName( wxString::Format( wxT( "file%8.8lX.sch" ), (long) newtimestamp ) );
                sheet->SetScreen( new SCH_SCREEN( &Kiway() ) );
                sheet->GetScreen()->SetFileName( sheet->GetFileName() );
            }
            }
            // clear annotation and init new time stamp for the new components
            // clear annotation and init new time stamp for the new components
            else if( bs->Type() == SCH_COMPONENT_T )
            else if( bs->Type() == SCH_COMPONENT_T )
@@ -383,7 +424,7 @@ bool SCH_EDIT_FRAME::AppendOneEEProject()
                bs->ClearFlags();
                bs->ClearFlags();
            }
            }


            bs = bs->Next();
            bs = nextbs;
        }
        }
    }
    }


+0 −3
Original line number Original line Diff line number Diff line
@@ -1191,9 +1191,6 @@ LIB_ITEM* LIB_EDIT_FRAME::LocateItemUsingCursor( const wxPoint& aPosition,


    LIB_ITEM* item = locateItem( aPosition, aFilterList );
    LIB_ITEM* item = locateItem( aPosition, aFilterList );


    if( item == NULL )
        return NULL;

    wxPoint pos = GetNearestGridPosition( aPosition );
    wxPoint pos = GetNearestGridPosition( aPosition );


    if( item == NULL && aPosition != pos )
    if( item == NULL && aPosition != pos )
+1 −1
Original line number Original line Diff line number Diff line
@@ -148,7 +148,7 @@ again." );
    // EELAYER i j
    // EELAYER i j
    // and the last line is
    // and the last line is
    // EELAYER END
    // EELAYER END
    // Skip all lines until end end of header EELAYER END is found
    // Skip all lines until the end of header "EELAYER END" is found
    while( reader.ReadLine() )
    while( reader.ReadLine() )
    {
    {
        line = reader.Line();
        line = reader.Line();
+3 −6
Original line number Original line Diff line number Diff line
@@ -112,16 +112,13 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )


        item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsOnly );
        item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsOnly );


        if( item )
        if( item )  // The user has clicked on a sheet: this is an enter sheet command
        {
        {
            m_CurrentSheet->Push( (SCH_SHEET*) item );
            m_CurrentSheet->Push( (SCH_SHEET*) item );
            DisplayCurrentSheet();
            DisplayCurrentSheet();
        }
        }
        else
        else if( m_CurrentSheet->Last() != g_RootSheet )
        {
        {   // The user has clicked ouside a sheet:this is an leave sheet command
            wxCHECK_RET( m_CurrentSheet->Last() != g_RootSheet,
                         wxT( "Cannot leave root sheet.  Bad Programmer!" ) );

            m_CurrentSheet->Pop();
            m_CurrentSheet->Pop();
            DisplayCurrentSheet();
            DisplayCurrentSheet();
        }
        }
+4 −3
Original line number Original line Diff line number Diff line
@@ -276,10 +276,11 @@ void SCH_COMPONENT::ResolveAll(
{
{
    for( int i = 0;  i < aComponents.GetCount();  ++i )
    for( int i = 0;  i < aComponents.GetCount();  ++i )
    {
    {
        SCH_COMPONENT* c = dynamic_cast<SCH_COMPONENT*>( aComponents[i] );
        SCH_COMPONENT* cmp = dynamic_cast<SCH_COMPONENT*>( aComponents[i] );
        wxASSERT( c );
        wxASSERT( cmp );


        c->Resolve( aLibs );
        if( cmp )   // cmp == NULL should not occur.
            cmp->Resolve( aLibs );
    }
    }
}
}


Loading