From 1222924607d4ea1612ce0f06fdf4ec944fb73697 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 18 Aug 2014 18:39:51 +0200 Subject: [PATCH] Eeschema: Fix some issues (all connections showed as not connected, DRC and NETLIST errors if all sheets in a hierarchy were not open) due to the fact the pointer of a schematic component to its part lib was calculated too late (or never calculated). --- eeschema/files-io.cpp | 17 +++++++-------- eeschema/load_one_schematic_file.cpp | 1 + eeschema/sch_screen.cpp | 31 ++++++++++++++++++++++------ include/class_sch_screen.h | 10 +++++++++ 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index c641075181..770c84223e 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -277,6 +277,13 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in LoadProjectFile(); + // load the libraries here, not in SCH_SCREEN::Draw() which is a context + // that will not tolerate DisplayError() dialog since we're already in an + // event handler in there. + // And when a schematic file is loaded, we need these libs to initialize + // some parameters (links to PART LIB, dangling ends ...) + Prj().SchLibs(); + if( is_new ) { // mark new, unsaved file as modified. @@ -302,15 +309,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in Zoom_Automatique( false ); SetSheetNumberAndCount(); - /* this is done in ReDraw() - UpdateTitle(); - */ - - // load the libraries here, not in SCH_SCREEN::Draw() which is a context - // that will not tolerate DisplayError() dialog since we're already in an - // event handler in there. - Prj().SchLibs(); - m_canvas->Refresh( true ); return true; @@ -363,6 +361,7 @@ bool SCH_EDIT_FRAME::AppendOneEEProject() // load the project bool success = LoadOneEEFile( screen, fullFileName, true ); + if( success ) { // load sub-sheets diff --git a/eeschema/load_one_schematic_file.cpp b/eeschema/load_one_schematic_file.cpp index ae159cb315..47a2a7df06 100644 --- a/eeschema/load_one_schematic_file.cpp +++ b/eeschema/load_one_schematic_file.cpp @@ -260,6 +260,7 @@ again." ); aScreen->Show( 0, std::cout ); #endif + aScreen->BuildSchCmpLinksToLibCmp(); // Build links between each components and its part lib LIB_PART aScreen->TestDanglingEnds(); msgDiag.Printf( _( "Done Loading <%s>" ), GetChars( aScreen->GetFileName() ) ); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 684ece90c7..fae15baf34 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -546,13 +546,11 @@ bool SCH_SCREEN::Save( FILE* aFile ) const return true; } - -void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor ) +void SCH_SCREEN::BuildSchCmpLinksToLibCmp() { - /* note: SCH_SCREEN::Draw is useful only for schematic. - * library editor and library viewer do not use m_drawList, and therefore - * their SCH_SCREEN::Draw() draws nothing - */ + // Initialize or reinitialize the pointer to the LIB_PART for each component + // found in m_drawList, but only if needed (change in lib or schematic) + // therefore the calculation time is usually very low. if( m_drawList.GetCount() ) { @@ -571,6 +569,18 @@ void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode m_modification_sync = mod_hash; // note the last mod_hash } } +} + + + +void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor ) +{ + /* note: SCH_SCREEN::Draw is useful only for schematic. + * library editor and library viewer do not use m_drawList, and therefore + * their SCH_SCREEN::Draw() draws nothing + */ + + BuildSchCmpLinksToLibCmp(); for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() ) { @@ -592,6 +602,8 @@ void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode */ void SCH_SCREEN::Plot( PLOTTER* aPlotter ) { + BuildSchCmpLinksToLibCmp(); + for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() ) { aPlotter->SetCurrentLineWidth( item->GetPenSize() ); @@ -1395,6 +1407,13 @@ void SCH_SCREENS::BuildScreenList( EDA_ITEM* aItem ) if( aItem && aItem->Type() == SCH_SCREEN_T ) { SCH_SCREEN* screen = (SCH_SCREEN*) aItem; + + // Ensure each component has its pointer to its part lib LIB_PART + // up to date (the cost is low if this is the case) + // We do this update here, because most of time this function is called + // to create a netlist, or an ERC, which need this update + screen->BuildSchCmpLinksToLibCmp(); + AddScreenToList( screen ); EDA_ITEM* strct = screen->GetDrawItems(); diff --git a/include/class_sch_screen.h b/include/class_sch_screen.h index 1a19657483..ce6d7a45d0 100644 --- a/include/class_sch_screen.h +++ b/include/class_sch_screen.h @@ -193,6 +193,16 @@ public: void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { }; + /** + * Initialize or reinitialize the pointer + * to the LIB_PART for each component found in m_drawList + * must be called: + * in Draw function + * when loading a schematic file + * before creating a netlist (in case a library is modified) + */ + void BuildSchCmpLinksToLibCmp(); + /** * Function Draw * draws all the items in the screen to \a aCanvas.