Eeschema: SCH_SHEET_PATH refactor.

* Derive SCH_SHEET_PATH from std::vector< SCH_SHEET* > and remove unnecessary
  assignment operator and list management functions.
* Remove function BuildSheetPathInfoFromSheetPathValue() since it was
  effectively an assignment operation.
* Replace all calls to BuildSheetPathInfoFromSheetPathValue() with assignment
  operator.
* Replace list management functions with vector management functions.
* Fix a error message that wasn't translatable.
This commit is contained in:
Wayne Stambaugh 2016-02-27 14:35:45 -05:00
parent 89ea49ff14
commit b7e56ae1cb
14 changed files with 156 additions and 294 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors.
* Copyright (C) 2015-2016 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -92,6 +92,7 @@ public:
void DrawPage( SCH_SCREEN* aScreen );
};
/**
* Custom schematic print preview frame.
* This derived preview frame remembers its size and position during a session
@ -136,6 +137,7 @@ private:
static wxSize s_size;
};
wxPoint SCH_PREVIEW_FRAME::s_pos;
wxSize SCH_PREVIEW_FRAME::s_size;
@ -251,7 +253,7 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event )
if( preview == NULL )
{
DisplayError( this, wxT( "Print preview error!" ) );
DisplayError( this, _( "Print preview error!" ) );
return;
}
@ -320,12 +322,13 @@ bool SCH_PRINTOUT::OnPrintPage( int page )
SCH_SCREEN* screen = m_parent->GetScreen();
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
SCH_SHEET_PATH list;
SCH_SHEET_LIST SheetList( NULL );
SCH_SHEET_PATH* sheetpath = SheetList.GetSheet( page - 1 );
SCH_SHEET_PATH list;
if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
if( sheetpath )
{
list = *sheetpath;
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
@ -360,6 +363,7 @@ bool SCH_PRINTOUT::HasPage( int pageNum )
int pageCount;
pageCount = g_RootSheet->CountSheets();
if( pageCount >= pageNum )
return true;

View File

@ -158,7 +158,7 @@ HIERARCHY_NAVIG_DLG::HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* aParent, const wxPoint
m_Tree->SetItemBold( cellule, true );
SCH_SHEET_PATH list;
list.Push( g_RootSheet );
list.push_back( g_RootSheet );
m_Tree->SetItemData( cellule, new TreeItemData( list ) );
if( m_Parent->GetCurrentSheet().Last() == g_RootSheet )
@ -227,7 +227,7 @@ void HIERARCHY_NAVIG_DLG::BuildSheetsTree( SCH_SHEET_PATH* list, wxTreeItemId*
SCH_SHEET* sheet = (SCH_SHEET*) schitem;
m_nbsheets++;
menu = m_Tree->AppendItem( *previousmenu, sheet->GetName(), 0, 1 );
list->Push( sheet );
list->push_back( sheet );
m_Tree->SetItemData( menu, new TreeItemData( *list ) );
int ll = m_Tree->GetItemText( menu ).Len();
@ -248,7 +248,7 @@ void HIERARCHY_NAVIG_DLG::BuildSheetsTree( SCH_SHEET_PATH* list, wxTreeItemId*
BuildSheetsTree( list, &menu );
m_Tree->Expand( menu );
list->Pop();
list->pop_back();
}
schitem = schitem->Next();

View File

@ -114,12 +114,12 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
if( item ) // The user has clicked on a sheet: this is an enter sheet command
{
m_CurrentSheet->Push( (SCH_SHEET*) item );
m_CurrentSheet->push_back( (SCH_SHEET*) item );
DisplayCurrentSheet();
}
else if( m_CurrentSheet->Last() != g_RootSheet )
{ // The user has clicked ouside a sheet:this is an leave sheet command
m_CurrentSheet->Pop();
m_CurrentSheet->pop_back();
DisplayCurrentSheet();
}
break;
@ -356,7 +356,7 @@ void SCH_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
switch( item->Type() )
{
case SCH_SHEET_T:
m_CurrentSheet->Push( (SCH_SHEET*) item );
m_CurrentSheet->push_back( (SCH_SHEET*) item );
DisplayCurrentSheet();
break;

View File

@ -5,7 +5,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2010 Lorenzo Marcantonio
* Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -62,20 +62,11 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
if( sheetpath == NULL )
break;
list.Clear();
if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
{
schframe->SetCurrentSheet( list );
schframe->GetCurrentSheet().UpdateAllScreenReferences();
schframe->SetSheetNumberAndCount();
screen = schframe->GetCurrentSheet().LastScreen();
}
else // Should not happen
{
return;
}
list = *sheetpath;
schframe->SetCurrentSheet( list );
schframe->GetCurrentSheet().UpdateAllScreenReferences();
schframe->SetSheetNumberAndCount();
screen = schframe->GetCurrentSheet().LastScreen();
sheetpath = SheetList.GetNext();
}
@ -89,14 +80,16 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname,
ext, &reporter );
if( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, plot_offset, 1.0, aPlotFrameRef ) )
if( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, plot_offset, 1.0,
aPlotFrameRef ) )
{
msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ACTION );
}
else // Error
{
msg.Printf( _( "Unable to create file '%s'.\n" ), GetChars( plotFileName.GetFullPath() ) );
msg.Printf( _( "Unable to create file '%s'.\n" ),
GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}
}

View File

@ -5,7 +5,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2010 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr
* Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -135,21 +135,15 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
if( sheetpath == NULL )
break;
list.Clear();
list = *sheetpath;
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
{
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
screen = m_parent->GetCurrentSheet().LastScreen();
if( !screen ) // LastScreen() may return NULL
screen = m_parent->GetScreen();
}
else // Should not happen
return;
if( !screen ) // LastScreen() may return NULL
screen = m_parent->GetScreen();
sheetpath = SheetList.GetNext();
}
@ -192,7 +186,8 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
}
else
{
msg.Printf( _( "Unable to create file '%s'.\n" ), GetChars( plotFileName.GetFullPath() ) );
msg.Printf( _( "Unable to create file '%s'.\n" ),
GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}

View File

@ -5,7 +5,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2010 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr
* Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -67,23 +67,20 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
// First page handling is different
bool first_page = true;
do
{
// Step over the schematic hierarchy
if( aPlotAll )
{
SCH_SHEET_PATH list;
wxCHECK_RET( sheetpath != NULL, wxT( "Attempt to plot undefined sheet path." ) );
if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
{
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
}
else // Should not happen
wxASSERT( 0 );
SCH_SHEET_PATH list = *sheetpath;
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
sheetpath = SheetList.GetNext();
}
@ -99,7 +96,8 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
if( !plotter->OpenFile( plotFileName.GetFullPath() ) )
{
msg.Printf( _( "Unable to create file '%s'.\n" ), GetChars( plotFileName.GetFullPath() ) );
msg.Printf( _( "Unable to create file '%s'.\n" ),
GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
delete plotter;
return;
@ -139,14 +137,12 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ACTION );
restoreEnvironment(plotter, oldsheetpath );
restoreEnvironment( plotter, oldsheetpath );
}
void DIALOG_PLOT_SCHEMATIC::restoreEnvironment( PDF_PLOTTER* aPlotter,
SCH_SHEET_PATH& aOldsheetpath )
SCH_SHEET_PATH& aOldsheetpath )
{
aPlotter->EndPlot();
delete aPlotter;

View File

@ -4,7 +4,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -62,18 +62,11 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
if( sheetpath == NULL )
break;
list.Clear();
if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
{
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
}
else // Should not happen
return;
list = *sheetpath;
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
sheetpath = SheetList.GetNext();
}
@ -125,7 +118,8 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
else
{
// Error
msg.Printf( _( "Unable to create file '%s'.\n" ), GetChars( plotFileName.GetFullPath() ) );
msg.Printf( _( "Unable to create file '%s'.\n" ),
GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -49,7 +49,7 @@ void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef )
if( aPrintAll )
{
SCH_SHEET_PATH* sheetpath;
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
SCH_SHEET_LIST SheetList( NULL );
sheetpath = SheetList.GetFirst();
SCH_SHEET_PATH list;
@ -62,20 +62,11 @@ void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef )
}
SCH_SCREEN* screen;
list.Clear();
if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
{
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
}
else // Should not happen
{
return;
}
list = *sheetpath;
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
sheetpath = SheetList.GetNext();
try

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2011 Kicad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2016 Kicad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -725,7 +725,7 @@ bool SCH_SHEET::LocatePathOfScreen( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aList )
{
if( m_screen )
{
aList->Push( this );
aList->push_back( this );
if( m_screen == aScreen )
return true;
@ -745,8 +745,9 @@ bool SCH_SHEET::LocatePathOfScreen( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aList )
strct = strct->Next();
}
aList->Pop();
aList->pop_back();
}
return false;
}
@ -1082,7 +1083,7 @@ void SCH_SHEET::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
SCH_SHEET_PATH* aSheetPath )
{
SCH_SHEET_PATH sheetPath = *aSheetPath;
sheetPath.Push( this );
sheetPath.push_back( this );
for( size_t i = 0; i < m_pins.size(); i++ )
{

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -37,7 +37,6 @@
#include <sch_reference_list.h>
#include <class_library.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <sch_component.h>
#include <template_fieldnames.h>
@ -50,64 +49,25 @@
SCH_SHEET_PATH::SCH_SHEET_PATH()
{
for( int i = 0; i<DSLSZ; i++ )
m_sheets[i] = NULL;
m_numSheets = 0;
}
bool SCH_SHEET_PATH::BuildSheetPathInfoFromSheetPathValue( const wxString& aPath, bool aFound )
{
if( aFound )
return true;
if( GetCount() == 0 )
Push( g_RootSheet );
if( aPath == Path() )
return true;
SCH_ITEM* schitem = LastDrawList();
while( schitem && GetCount() < NB_MAX_SHEET )
{
if( schitem->Type() == SCH_SHEET_T )
{
SCH_SHEET* sheet = (SCH_SHEET*) schitem;
Push( sheet );
if( aPath == Path() )
return true;
if( BuildSheetPathInfoFromSheetPathValue( aPath ) )
return true;
Pop();
}
schitem = schitem->Next();
}
return false;
m_pageNumber = 0;
}
int SCH_SHEET_PATH::Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const
{
if( m_numSheets > aSheetPathToTest.m_numSheets )
if( size() > aSheetPathToTest.size() )
return 1;
if( m_numSheets < aSheetPathToTest.m_numSheets )
if( size() < aSheetPathToTest.size() )
return -1;
//otherwise, same number of sheets.
for( unsigned i = 0; i<m_numSheets; i++ )
for( unsigned i = 0; i < size(); i++ )
{
if( m_sheets[i]->GetTimeStamp() > aSheetPathToTest.m_sheets[i]->GetTimeStamp() )
if( at( i )->GetTimeStamp() > aSheetPathToTest.at( i )->GetTimeStamp() )
return 1;
if( m_sheets[i]->GetTimeStamp() < aSheetPathToTest.m_sheets[i]->GetTimeStamp() )
if( at( i )->GetTimeStamp() < aSheetPathToTest.at( i )->GetTimeStamp() )
return -1;
}
@ -117,8 +77,8 @@ int SCH_SHEET_PATH::Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const
SCH_SHEET* SCH_SHEET_PATH::Last() const
{
if( m_numSheets )
return m_sheets[m_numSheets - 1];
if( !empty() )
return at( size() - 1 );
return NULL;
}
@ -150,8 +110,8 @@ SCH_ITEM* SCH_SHEET_PATH::FirstDrawList() const
{
SCH_ITEM* item = NULL;
if( m_numSheets && m_sheets[0]->GetScreen() )
item = m_sheets[0]->GetScreen()->GetDrawItems();
if( !empty() && at( 0 )->GetScreen() )
item = at( 0 )->GetScreen()->GetDrawItems();
/* @fixme - These lists really should be one of the boost pointer containers. This
* is a brain dead hack to allow reverse iteration of EDA_ITEM linked
@ -169,29 +129,6 @@ SCH_ITEM* SCH_SHEET_PATH::FirstDrawList() const
}
void SCH_SHEET_PATH::Push( SCH_SHEET* aSheet )
{
wxCHECK_RET( m_numSheets < DSLSZ,
wxString::Format( _( "Schematic sheets can only be nested %d levels deep." ),
DSLSZ ) );
m_sheets[ m_numSheets ] = aSheet;
m_numSheets++;
}
SCH_SHEET* SCH_SHEET_PATH::Pop()
{
if( m_numSheets > 0 )
{
m_numSheets--;
return m_sheets[m_numSheets];
}
return NULL;
}
wxString SCH_SHEET_PATH::Path() const
{
wxString s, t;
@ -201,9 +138,9 @@ wxString SCH_SHEET_PATH::Path() const
// start at 1 to avoid the root sheet,
// which does not need to be added to the path
// it's timestamp changes anyway.
for( unsigned i = 1; i < m_numSheets; i++ )
for( unsigned i = 1; i < size(); i++ )
{
t.Printf( _( "%8.8lX/" ), (long unsigned) m_sheets[i]->GetTimeStamp() );
t.Printf( _( "%8.8lX/" ), (long unsigned) at( i )->GetTimeStamp() );
s = s + t;
}
@ -218,9 +155,9 @@ wxString SCH_SHEET_PATH::PathHumanReadable() const
s = wxT( "/" );
// start at 1 to avoid the root sheet, as above.
for( unsigned i = 1; i< m_numSheets; i++ )
for( unsigned i = 1; i < size(); i++ )
{
s = s + m_sheets[i]->GetName() + wxT( "/" );
s = s + at( i )->GetName() + wxT( "/" );
}
return s;
@ -255,7 +192,7 @@ void SCH_SHEET_PATH::AnnotatePowerSymbols( PART_LIBS* aLibs, int* aReference )
for( EDA_ITEM* item = LastDrawList(); item; item = item->Next() )
{
if( item->Type() != SCH_COMPONENT_T )
continue;
continue;
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
LIB_PART* part = aLibs->FindLibPart( component->GetPartName() );
@ -282,19 +219,9 @@ void SCH_SHEET_PATH::AnnotatePowerSymbols( PART_LIBS* aLibs, int* aReference )
}
void SCH_SHEET_PATH::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols )
void SCH_SHEET_PATH::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences,
bool aIncludePowerSymbols )
{
// Search to sheet path number:
int sheetnumber = 1; // 1 = root
SCH_SHEET_LIST sheetList;
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext(), sheetnumber++ )
{
if( Cmp( *path ) == 0 )
break;
}
for( SCH_ITEM* item = LastDrawList(); item; item = item->Next() )
{
if( item->Type() == SCH_COMPONENT_T )
@ -307,33 +234,28 @@ void SCH_SHEET_PATH::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aRefer
continue;
LIB_PART* part = aLibs->FindLibPart( component->GetPartName() );
if( part )
{
SCH_REFERENCE reference = SCH_REFERENCE( component, part, *this );
reference.SetSheetNumber( sheetnumber );
reference.SetSheetNumber( m_pageNumber );
aReferences.AddItem( reference );
}
}
}
}
void SCH_SHEET_PATH::GetMultiUnitComponents( PART_LIBS* aLibs, SCH_MULTI_UNIT_REFERENCE_MAP &aRefList,
bool aIncludePowerSymbols )
void SCH_SHEET_PATH::GetMultiUnitComponents( PART_LIBS* aLibs,
SCH_MULTI_UNIT_REFERENCE_MAP &aRefList,
bool aIncludePowerSymbols )
{
// Find sheet path number
int sheetnumber = 1; // 1 = root
SCH_SHEET_LIST sheetList;
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext(), sheetnumber++ )
{
if( Cmp( *path ) == 0 )
break;
}
for( SCH_ITEM* item = LastDrawList(); item; item = item->Next() )
{
if( item->Type() != SCH_COMPONENT_T ) continue;
if( item->Type() != SCH_COMPONENT_T )
continue;
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
// Skip pseudo components, which have a reference starting with #. This mainly
@ -342,14 +264,16 @@ void SCH_SHEET_PATH::GetMultiUnitComponents( PART_LIBS* aLibs, SCH_MULTI_UNIT_RE
continue;
LIB_PART* part = aLibs->FindLibPart( component->GetPartName() );
if( part && part->GetUnitCount() > 1 )
{
SCH_REFERENCE reference = SCH_REFERENCE( component, part, *this );
reference.SetSheetNumber( sheetnumber );
reference.SetSheetNumber( m_pageNumber );
wxString reference_str = reference.GetRef();
// Never lock unassigned references
if( reference_str[reference_str.Len() - 1] == '?' ) continue;
if( reference_str[reference_str.Len() - 1] == '?' )
continue;
aRefList[reference_str].AddItem( reference );
}
@ -435,33 +359,14 @@ bool SCH_SHEET_PATH::SetComponentFootprint( const wxString& aReference, const wx
}
SCH_SHEET_PATH& SCH_SHEET_PATH::operator=( const SCH_SHEET_PATH& d1 )
{
if( this == &d1 ) // Self assignment is bad!
return *this;
m_numSheets = d1.m_numSheets;
unsigned i;
for( i = 0; i < m_numSheets; i++ )
m_sheets[i] = d1.m_sheets[i];
for( ; i < DSLSZ; i++ )
m_sheets[i] = 0;
return *this;
}
bool SCH_SHEET_PATH::operator==( const SCH_SHEET_PATH& d1 ) const
{
if( m_numSheets != d1.m_numSheets )
if( size() != d1.size() )
return false;
for( unsigned i = 0; i < m_numSheets; i++ )
for( unsigned i = 0; i < size(); i++ )
{
if( m_sheets[i] != d1.m_sheets[i] )
if( at( i ) != d1[i] )
return false;
}
@ -492,9 +397,9 @@ bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName,
/// located in the project folder which may or may not be desirable.
unsigned i = 0;
while( i < m_numSheets )
while( i < size() )
{
wxFileName cmpFn = m_sheets[i]->GetFileName();
wxFileName cmpFn = at( i )->GetFileName();
if( cmpFn.IsRelative() )
cmpFn.MakeAbsolute( rootFn.GetPath() );
@ -508,7 +413,7 @@ bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName,
// The destination sheet file name was not found in the sheet path or the destination
// sheet file name is the root sheet so no recursion is possible.
if( i >= m_numSheets || i == 0 )
if( i >= size() || i == 0 )
return false;
// Walk back up to the root sheet to see if the source file name is already a parent in
@ -517,7 +422,7 @@ bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName,
{
i -= 1;
wxFileName cmpFn = m_sheets[i]->GetFileName();
wxFileName cmpFn = at( i )->GetFileName();
if( cmpFn.IsRelative() )
cmpFn.MakeAbsolute( rootFn.GetPath() );
@ -534,9 +439,9 @@ bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName,
int SCH_SHEET_PATH::FindSheet( const wxString& aFileName ) const
{
for( unsigned i = 0; i < m_numSheets; i++ )
for( unsigned i = 0; i < size(); i++ )
{
if( m_sheets[i]->GetFileName().CmpNoCase( aFileName ) == 0 )
if( at( i )->GetFileName().CmpNoCase( aFileName ) == 0 )
return (int)i;
}
@ -546,10 +451,10 @@ int SCH_SHEET_PATH::FindSheet( const wxString& aFileName ) const
SCH_SHEET* SCH_SHEET_PATH::FindSheetByName( const wxString& aSheetName )
{
for( unsigned i = 0; i < m_numSheets; i++ )
for( unsigned i = 0; i < size(); i++ )
{
if( m_sheets[i]->GetName().CmpNoCase( aSheetName ) == 0 )
return m_sheets[i];
if( at( i )->GetName().CmpNoCase( aSheetName ) == 0 )
return at( i );
}
return NULL;
@ -657,10 +562,17 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet )
m_count = count;
m_index = 0;
m_list = new SCH_SHEET_PATH[ count ];
m_currList.Clear();
m_currList.clear();
}
m_currList.Push( aSheet );
m_currList.push_back( aSheet );
/**
* @todo: Schematic page number is currently a left over relic and is generated as
* SCH_SHEET_PATH object is pushed to the list. This only has meaning when
* entire hierarchy is created from the root sheet down.
*/
m_currList.SetPageNumber( m_index + 1 );
m_list[m_index] = m_currList;
m_index++;
@ -680,7 +592,7 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet )
}
}
m_currList.Pop();
m_currList.pop_back();
}
@ -896,7 +808,7 @@ bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
{
SCH_SHEET_PATH* sheetPath = aSrcSheetHierarchy.GetSheet( j );
for( unsigned k = 0; k < sheetPath->GetCount(); k++ )
for( unsigned k = 0; k < sheetPath->size(); k++ )
{
if( m_list[i].TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
aDestFileName ) )

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -76,11 +76,11 @@
* (usable in flat and simple hierarchies).
*/
#include "sch_sheet.h" // SCH_SHEETS
class wxFindReplaceData;
class SCH_SCREEN;
class SCH_MARKER;
class SCH_SHEET;
class SCH_ITEM;
class SCH_REFERENCE_LIST;
class PART_LIBS;
@ -96,39 +96,34 @@ typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
/**
* Class SCH_SHEET_PATH
* handles access to a sheet by way of a path.
*
* handles access to a stack of flattened #SCH_SHEET objects by way of a path for
* creating a flattened schematic hierarchy.
*
* <p>
* The member m_sheets stores the list of sheets from the first (usually
* g_RootSheet) to a given sheet in last position.
* The _last_ sheet is usually the sheet we want to select or reach (which is
* what the function Last() returns).
* Others sheets constitute the "path" from the first to the last sheet.
* The #SCH_SHEET objects are stored in a list from first (usually the root sheet) to a
* given sheet in last position. The _last_ sheet is usually the sheet we want to select
* or reach (which is what the function Last() returns). Others sheets constitute the
* "path" from the first to the last sheet.
* </p>
*/
class SCH_SHEET_PATH
class SCH_SHEET_PATH : public SCH_SHEETS
{
#define DSLSZ 32 // Max number of levels for a sheet path
#define MAX_SHEET_DEPTH 32 /// Maximum number of levels for a sheet path.
SCH_SHEET* m_sheets[ DSLSZ ];
unsigned m_numSheets;
int m_pageNumber; /// Page numbers are maintained by the sheet load order.
public:
SCH_SHEET_PATH();
void Clear()
{
m_numSheets = 0;
}
void SetPageNumber( int aPageNumber ) { m_pageNumber = aPageNumber; }
unsigned GetCount()
{
return m_numSheets;
}
int GetPageNumber() const { return m_pageNumber; }
SCH_SHEET* GetSheet( unsigned index )
SCH_SHEET* GetSheet( unsigned aIndex )
{
if( index < m_numSheets )
return m_sheets[index];
if( aIndex < size() )
return at( aIndex );
return NULL;
}
@ -171,24 +166,6 @@ public:
*/
SCH_ITEM* FirstDrawList() const;
/**
* Function Push
* store (push) aSheet in list
* @param aSheet = pointer to the SCH_SHEET to store in list
* Push is used when entered a sheet to select or analyze it
* This is like cd &ltdirectory&gt in directories navigation
*/
void Push( SCH_SHEET* aSheet );
/**
* Function Pop
* retrieves (pop) the last entered sheet and remove it from list
* @return a SCH_SHEET* pointer to the removed sheet in list
* Pop is used when leaving a sheet after a selection or analyze
* This is like cd .. in directories navigation
*/
SCH_SHEET* Pop();
/**
* Function Path
* the path uses the time stamps which do not changes even when editing
@ -206,15 +183,6 @@ public:
*/
wxString PathHumanReadable() const;
/**
* Function BuildSheetPathInfoFromSheetPathValue
* Fill this with data to access to the hierarchical sheet known by its path \a aPath
* @param aPath = path of the sheet to reach (in non human readable format)
* @param aFound - Please document me.
* @return true if success else false
*/
bool BuildSheetPathInfoFromSheetPathValue( const wxString& aPath, bool aFound = false );
/**
* Function UpdateAllScreenReferences
* updates the reference and the m_Multi parameter (part selection) for all
@ -321,7 +289,15 @@ public:
*/
SCH_SHEET* FindSheetByName( const wxString& aSheetName );
SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& d1 );
/**
* Function FindSheetByPageNumber
*
* searches the #SCH_SHEET_LIST for a sheet with \a aPageNumber.
*
* @param aPageNumber is the number of the sheet to find.
* @return a pointer to a #SCH_SHEET object page \a aPageNumber if found or NULL if not found.
*/
SCH_SHEET* FindSheetByPageNumber( int aPageNumber );
bool operator==( const SCH_SHEET_PATH& d1 ) const;

View File

@ -315,7 +315,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( item && (item->Type() == SCH_SHEET_T) )
{
m_CurrentSheet->Push( (SCH_SHEET*) item );
m_CurrentSheet->push_back( (SCH_SHEET*) item );
DisplayCurrentSheet();
}
@ -324,7 +324,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_SCH_LEAVE_SHEET:
if( m_CurrentSheet->Last() != g_RootSheet )
{
m_CurrentSheet->Pop();
m_CurrentSheet->pop_back();
DisplayCurrentSheet();
}

View File

@ -535,8 +535,8 @@ void SCH_EDIT_FRAME::CreateScreens()
g_RootSheet->GetScreen()->SetFileName( m_DefaultSchematicFileName );
m_CurrentSheet->Clear();
m_CurrentSheet->Push( g_RootSheet );
m_CurrentSheet->clear();
m_CurrentSheet->push_back( g_RootSheet );
if( GetScreen() == NULL )
{
@ -680,7 +680,7 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
g_RootSheet->GetScreen()->Clear();
// all sub sheets are deleted, only the main sheet is usable
m_CurrentSheet->Clear();
m_CurrentSheet->clear();
Destroy();
}