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

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

Fix a few minor coverity warnings.
parent 035b231b
...@@ -359,19 +359,60 @@ bool SCH_EDIT_FRAME::AppendOneEEProject() ...@@ -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() ...@@ -383,7 +424,7 @@ bool SCH_EDIT_FRAME::AppendOneEEProject()
bs->ClearFlags(); bs->ClearFlags();
} }
bs = bs->Next(); bs = nextbs;
} }
} }
......
...@@ -1191,9 +1191,6 @@ LIB_ITEM* LIB_EDIT_FRAME::LocateItemUsingCursor( const wxPoint& aPosition, ...@@ -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 )
......
...@@ -148,7 +148,7 @@ again." ); ...@@ -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();
......
...@@ -112,16 +112,13 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -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();
} }
......
...@@ -276,10 +276,11 @@ void SCH_COMPONENT::ResolveAll( ...@@ -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 );
} }
} }
......
...@@ -673,6 +673,7 @@ public: ...@@ -673,6 +673,7 @@ public:
{ {
// Avoid non initialized variables: // Avoid non initialized variables:
pageStreamHandle = streamLengthHandle = fontResDictHandle = 0; pageStreamHandle = streamLengthHandle = fontResDictHandle = 0;
pageTreeHandle = 0;
} }
virtual PlotFormat GetPlotterType() const virtual PlotFormat GetPlotterType() const
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <class_board_design_settings.h> #include <class_board_design_settings.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
#include <ratsnest_data.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <dialog_netlist.h> #include <dialog_netlist.h>
...@@ -331,6 +332,10 @@ void DIALOG_NETLIST::OnTestFootprintsClick( wxCommandEvent& event ) ...@@ -331,6 +332,10 @@ void DIALOG_NETLIST::OnTestFootprintsClick( wxCommandEvent& event )
void DIALOG_NETLIST::OnCompileRatsnestClick( wxCommandEvent& event ) void DIALOG_NETLIST::OnCompileRatsnestClick( wxCommandEvent& event )
{ {
// Rebuild the board connectivity:
if( m_parent->IsGalCanvasActive() )
m_parent->GetBoard()->GetRatsnest()->ProcessBoard();
m_parent->Compile_Ratsnest( m_dc, true ); m_parent->Compile_Ratsnest( m_dc, true );
} }
......
...@@ -136,7 +136,7 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, ...@@ -136,7 +136,7 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName,
// Rebuild the board connectivity: // Rebuild the board connectivity:
if( IsGalCanvasActive() ) if( IsGalCanvasActive() )
board->GetRatsnest()->ProcessBoard(); board->GetRatsnest()->ProcessBoard();
else
Compile_Ratsnest( NULL, true ); Compile_Ratsnest( NULL, true );
SetMsgPanel( board ); SetMsgPanel( board );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment