Eeschema: SCH_SHEET_LIST improvements.

* Derive SCH_SHEET_LIST from std::vector rather than using internal array
  management.  Change all internal code to use iterators or array operator
  in loops.
* Allow creation of empty SCH_SHEET_LIST for external population for plotting
  and printing.
* Clean up print an plot code to take advantage of new SCH_SHEET_LIST behavior.
* Make BuildSheetList() public so list can be populated after creation.
* Update all instances of SCH_SHEET_LIST with the appropriate SCH_SHEET
  object on initialization.
* Create const and non-const version of SCH_SHEET_PATH::GetSheet().
This commit is contained in:
Wayne Stambaugh 2016-03-06 16:22:01 -05:00
parent 0d1395ee08
commit 92f5ab8589
23 changed files with 300 additions and 524 deletions

View File

@ -6,7 +6,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-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
@ -69,7 +69,7 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
SCH_SCREENS screens;
// Build the sheet list.
SCH_SHEET_LIST sheets;
SCH_SHEET_LIST sheets( g_RootSheet );
// Map of locked components
SCH_MULTI_UNIT_REFERENCE_MAP lockedComponents;
@ -187,7 +187,7 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly )
{
// build the screen list
SCH_SHEET_LIST SheetList;
SCH_SHEET_LIST SheetList( g_RootSheet );
SCH_REFERENCE_LIST ComponentsList;
// Build the list of components

View File

@ -2,8 +2,8 @@
* 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) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-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
@ -53,7 +53,7 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef
{
// Build a flat list of components in schematic:
SCH_REFERENCE_LIST refs;
SCH_SHEET_LIST sheets;
SCH_SHEET_LIST sheets( g_RootSheet );
bool isChanged = false;
sheets.GetComponents( Prj().SchLibs(), refs, false );
@ -135,7 +135,7 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilenam
{
// Build a flat list of components in schematic:
SCH_REFERENCE_LIST referencesList;
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
sheetList.GetComponents( Prj().SchLibs(), referencesList, false );

View File

@ -2,8 +2,8 @@
* 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) 2009-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2009-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-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
@ -448,7 +448,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
{
unsigned i;
SCH_ITEM* item;
SCH_SHEET_LIST hierarchy; // This is the entire schematic hierarcy.
SCH_SHEET_LIST hierarchy( g_RootSheet ); // This is the entire schematic hierarcy.
if( m_blockItems.GetCount() == 0 )
{

View File

@ -201,13 +201,13 @@ void DIALOG_ERC::OnLeftClickMarkersList( wxHtmlLinkEvent& event )
return;
// Search for the selected marker
SCH_SHEET_PATH* sheet;
SCH_SHEET_LIST SheetList;
unsigned i;
SCH_SHEET_LIST sheetList( g_RootSheet );
bool notFound = true;
for( sheet = SheetList.GetFirst(); sheet; sheet = SheetList.GetNext() )
for( i = 0; i < sheetList.size(); i++ )
{
SCH_ITEM* item = (SCH_ITEM*) sheet->LastDrawList();
SCH_ITEM* item = (SCH_ITEM*) sheetList[i].LastDrawList();
for( ; item; item = item->Next() )
{
@ -231,10 +231,10 @@ void DIALOG_ERC::OnLeftClickMarkersList( wxHtmlLinkEvent& event )
return;
}
if( *sheet != m_parent->GetCurrentSheet() )
if( sheetList[i] != m_parent->GetCurrentSheet() )
{
sheet->LastScreen()->SetZoom( m_parent->GetScreen()->GetZoom() );
m_parent->SetCurrentSheet( *sheet );
sheetList[i].LastScreen()->SetZoom( m_parent->GetScreen()->GetZoom() );
m_parent->SetCurrentSheet( sheetList[i] );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
}
@ -372,14 +372,12 @@ void DIALOG_ERC::setDRCMatrixButtonState( wxBitmapButton *aButton, int aState )
void DIALOG_ERC::DisplayERC_MarkersList()
{
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet);
m_MarkersList->ClearList();
SCH_SHEET_PATH* sheet = sheetList.GetFirst();
for( ; sheet != NULL; sheet = sheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
SCH_ITEM* item = sheet->LastDrawList();
SCH_ITEM* item = sheetList[i].LastDrawList();
for( ; item != NULL; item = item->Next() )
{
@ -455,7 +453,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
m_tstUniqueGlobalLabels = m_cbTestUniqueGlbLabels->GetValue();
// Build the whole sheet list in hierarchy (sheet, not screen)
SCH_SHEET_LIST sheets;
SCH_SHEET_LIST sheets( g_RootSheet );
sheets.AnnotatePowerSymbols( Prj().SchLibs() );
if( m_parent->CheckAnnotate( aMessagesList, false ) )

View File

@ -315,6 +315,14 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
bool SCH_PRINTOUT::OnPrintPage( int page )
{
SCH_SHEET_LIST sheetList( g_RootSheet );
wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false,
wxT( "Cannot print invalid page number." ) );
wxCHECK_MSG( sheetList[ page - 1].LastScreen() != NULL, false,
wxT( "Cannot print page with NULL screen." ) );
wxString msg;
msg.Printf( _( "Print page %d" ), page );
m_parent->ClearMsgPanel();
@ -322,26 +330,10 @@ bool SCH_PRINTOUT::OnPrintPage( int page )
SCH_SCREEN* screen = m_parent->GetScreen();
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
SCH_SHEET_LIST SheetList( NULL );
SCH_SHEET_PATH* sheetpath = SheetList.GetSheet( page - 1 );
SCH_SHEET_PATH list;
if( sheetpath )
{
list = *sheetpath;
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
}
else
{
screen = NULL;
}
if( screen == NULL )
return false;
m_parent->SetCurrentSheet( sheetList[ page - 1 ] );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
DrawPage( screen );
m_parent->SetCurrentSheet( oldsheetpath );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();

View File

@ -2,8 +2,8 @@
* 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) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2015 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
@ -538,15 +538,14 @@ bool WriteDiagnosticERC( const wxString& aFullFileName )
int err_count = 0;
int warn_count = 0;
int total_count = 0;
SCH_SHEET_LIST sheetList;
SCH_SHEET_PATH* sheet;
SCH_SHEET_LIST sheetList( g_RootSheet );
for( sheet = sheetList.GetFirst(); sheet != NULL; sheet = sheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
msg << wxString::Format( _( "\n***** Sheet %s\n" ),
GetChars( sheet->PathHumanReadable() ) );
GetChars( sheetList[i].PathHumanReadable() ) );
for( SCH_ITEM* item = sheet->LastDrawList(); item != NULL; item = item->Next() )
for( SCH_ITEM* item = sheetList[i].LastDrawList(); item != NULL; item = item->Next() )
{
if( item->Type() != SCH_MARKER_T )
continue;

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-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,7 +62,7 @@ void SCH_EDIT_FRAME::OnFindDrcMarker( wxFindDialogEvent& event )
static SCH_MARKER* lastMarker = NULL;
wxString msg;
SCH_SHEET_LIST schematic;
SCH_SHEET_LIST schematic( g_RootSheet );
SCH_SHEET_PATH* sheetFoundIn = NULL;
bool wrap = ( event.GetFlags() & FR_SEARCH_WRAP ) != 0;
bool warpCursor = ( ( event.GetId() == wxEVT_COMMAND_FIND_CLOSE ) ||
@ -113,7 +113,7 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference,
const wxString& aSearchText,
bool aWarpMouse )
{
SCH_SHEET_PATH* sheet;
SCH_SHEET_PATH* sheet = NULL;
SCH_SHEET_PATH* sheetWithComponentFound = NULL;
SCH_ITEM* item = NULL;
SCH_COMPONENT* Component = NULL;
@ -121,16 +121,17 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference,
bool centerAndRedraw = false;
bool notFound = true;
LIB_PIN* pin;
SCH_SHEET_LIST sheetList;
sheet = sheetList.GetFirst();
SCH_SHEET_LIST sheetList( g_RootSheet );
if( !aSearchHierarchy )
sheet = m_CurrentSheet;
sheetList.push_back( *m_CurrentSheet );
else
sheetList.BuildSheetList( g_RootSheet );
for( ; sheet != NULL; sheet = sheetList.GetNext() )
for( SCH_SHEET_PATHS_ITER it = sheetList.begin(); it != sheetList.end(); ++it )
{
item = sheet->LastDrawList();
sheet = &(*it);
item = (*it).LastDrawList();
for( ; ( item != NULL ) && ( notFound == true ); item = item->Next() )
{
@ -181,7 +182,7 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference,
}
}
if( (aSearchHierarchy == false) || (notFound == false) )
if( notFound == false )
break;
}
@ -361,7 +362,7 @@ void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent )
static int nextFoundIndex = 0;
SCH_ITEM* item;
SCH_SHEET_PATH* sheet;
SCH_SHEET_LIST schematic;
SCH_SHEET_LIST schematic( g_RootSheet );
SCH_FIND_COLLECTOR_DATA data;
SCH_FIND_REPLACE_DATA searchCriteria;
@ -454,7 +455,7 @@ void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent )
void SCH_EDIT_FRAME::updateFindReplaceView( wxFindDialogEvent& aEvent )
{
wxString msg;
SCH_SHEET_LIST schematic;
SCH_SHEET_LIST schematic( g_RootSheet );
SCH_FIND_COLLECTOR_DATA data;
SCH_FIND_REPLACE_DATA searchCriteria;
bool warpCursor = !( aEvent.GetFlags() & FR_NO_WARP_CURSOR );

View File

@ -2,8 +2,8 @@
* 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) 2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2013-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
@ -67,7 +67,7 @@ int TestDuplicateSheetNames( bool aCreateMarker );
bool SCH_EDIT_FRAME::prepareForNetlist()
{
SCH_SHEET_LIST sheets;
SCH_SHEET_LIST sheets( g_RootSheet );
sheets.AnnotatePowerSymbols( Prj().SchLibs() );
@ -173,7 +173,7 @@ NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::BuildNetListBase()
std::auto_ptr<NETLIST_OBJECT_LIST> ret( new NETLIST_OBJECT_LIST() );
// Creates the flattened sheet list:
SCH_SHEET_LIST aSheets;
SCH_SHEET_LIST aSheets( g_RootSheet );
// Build netlist info
bool success = ret->BuildNetListInfo( aSheets );
@ -197,9 +197,10 @@ bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets )
SCH_SHEET_PATH* sheet;
// Fill list with connected items from the flattened sheet list
for( sheet = aSheets.GetFirst(); sheet != NULL;
sheet = aSheets.GetNext() )
for( unsigned i = 0; i < aSheets.size(); i++ )
{
sheet = &aSheets[i];
for( SCH_ITEM* item = sheet->LastScreen()->GetDrawItems(); item; item = item->Next() )
{
item->GetNetListItem( *this, sheet );
@ -420,8 +421,7 @@ static int getPriority( const NETLIST_OBJECT* Objet )
* evalLabelsPriority calculates the priority of alabel1 and aLabel2
* return true if alabel1 has a higher priority than aLabel2
*/
static bool evalLabelsPriority( const NETLIST_OBJECT* aLabel1,
const NETLIST_OBJECT* aLabel2 )
static bool evalLabelsPriority( const NETLIST_OBJECT* aLabel1, const NETLIST_OBJECT* aLabel2 )
{
// Global labels have the highest prioriy.
// For local labels: names are prefixed by their sheetpath
@ -542,6 +542,7 @@ void NETLIST_OBJECT_LIST::findBestNetNameForEachNet()
for( unsigned ii = 0; ii < size(); ii++ )
{
item = GetItem( ii );
if( !item->HasNetNameCandidate() )
list.push_back( item );
}
@ -592,6 +593,7 @@ void NETLIST_OBJECT_LIST::findBestNetNameForEachNet()
// changed each time the netlist is built (power components)
// and anyway obviously they are not a good candidate
SCH_COMPONENT* link = item->GetComponentParent();
if( link && link->IsInNetlist() )
{
// select the better between the previous and this one
@ -711,8 +713,7 @@ void NETLIST_OBJECT_LIST::propageNetCode( int aOldNetCode, int aNewNetCode, bool
}
void NETLIST_OBJECT_LIST::pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus,
int start )
void NETLIST_OBJECT_LIST::pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus, int start )
{
int netCode;
@ -808,7 +809,7 @@ void NETLIST_OBJECT_LIST::pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus
void NETLIST_OBJECT_LIST::segmentToPointConnect( NETLIST_OBJECT* aJonction,
bool aIsBus, int aIdxStart )
bool aIsBus, int aIdxStart )
{
for( unsigned i = aIdxStart; i < size(); i++ )
{

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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
@ -328,22 +328,23 @@ void NETLIST_EXPORTER::findAllInstancesOfComponent( SCH_COMPONENT* aComponent,
wxString ref = aComponent->GetRef( aSheetPath );
wxString ref2;
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() )
for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
{
if( item->Type() != SCH_COMPONENT_T )
continue;
SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item;
ref2 = comp2->GetRef( sheet );
ref2 = comp2->GetRef( &sheetList[i] );
if( ref2.CmpNoCase( ref ) != 0 )
continue;
int unit2 = comp2->GetUnitSelection( sheet ); // slow
int unit2 = comp2->GetUnitSelection( &sheetList[i] ); // slow
for( LIB_PIN* pin = aEntry->GetNextPin(); pin; pin = aEntry->GetNextPin( pin ) )
{
@ -356,7 +357,7 @@ void NETLIST_EXPORTER::findAllInstancesOfComponent( SCH_COMPONENT* aComponent,
continue;
// A suitable pin is found: add it to the current list
addPinToComponentPinList( comp2, sheet, pin );
addPinToComponentPinList( comp2, &sheetList[i], pin );
}
}
}

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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
@ -53,7 +53,6 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig
wxString StartCmpDesc = StartLine + wxT( "ADD_COM" );
wxString msg;
SCH_SHEET_PATH* sheet;
EDA_ITEM* DrawList;
SCH_COMPONENT* component;
wxString title = wxT( "Eeschema " ) + GetBuildVersion();
@ -71,13 +70,13 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig
// Create netlist module section
m_ReferencesAlreadyFound.Clear();
SCH_SHEET_LIST SheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
for( DrawList = sheet->LastDrawList(); DrawList != NULL; DrawList = DrawList->Next() )
for( DrawList = sheetList[i].LastDrawList(); DrawList != NULL; DrawList = DrawList->Next() )
{
DrawList = component = findNextComponentAndCreatePinList( DrawList, sheet );
DrawList = component = findNextComponentAndCreatePinList( DrawList, &sheetList[i] );
if( component == NULL )
break;
@ -93,7 +92,7 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig
footprint = wxT( "$noname" );
*/
msg = component->GetRef( sheet );
msg = component->GetRef( &sheetList[i] );
ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
ret |= fprintf( f, "%s", TO_UTF8( msg ) );

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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
@ -108,16 +108,16 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents()
m_ReferencesAlreadyFound.Clear();
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
// Output is xml, so there is no reason to remove spaces from the field values.
// And XML element names need not be translated to various languages.
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
for( EDA_ITEM* schItem = path->LastDrawList(); schItem; schItem = schItem->Next() )
for( EDA_ITEM* schItem = sheetList[i].LastDrawList(); schItem; schItem = schItem->Next() )
{
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( schItem, path );
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( schItem, &sheetList[i] );
if( !comp )
break; // No component left
@ -131,7 +131,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents()
// an element.
xcomps->AddChild( xcomp = node( sComponent ) );
xcomp->AddAttribute( sRef, comp->GetRef( path ) );
xcomp->AddAttribute( sRef, comp->GetRef( &sheetList[i] ) );
xcomp->AddChild( node( sValue, comp->GetField( VALUE )->GetText() ) );
@ -178,8 +178,8 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents()
XNODE* xsheetpath;
xcomp->AddChild( xsheetpath = node( sSheetPath ) );
xsheetpath->AddAttribute( sNames, path->PathHumanReadable() );
xsheetpath->AddAttribute( sTStamps, path->Path() );
xsheetpath->AddAttribute( sNames, sheetList[i].PathHumanReadable() );
xsheetpath->AddAttribute( sTStamps, sheetList[i].Path() );
timeStamp.Printf( sTSFmt, (unsigned long)comp->GetTimeStamp() );
xcomp->AddChild( node( sTStamp, timeStamp ) );
@ -193,7 +193,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents()
XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader()
{
SCH_SCREEN* screen;
XNODE* xdesign = node( wxT("design") );
XNODE* xdesign = node( wxT( "design" ) );
XNODE* xtitleBlock;
XNODE* xsheet;
XNODE* xcomment;
@ -211,21 +211,21 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader()
/*
Export the sheets information
*/
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
screen = sheet->LastScreen();
screen = sheetList[i].LastScreen();
xdesign->AddChild( xsheet = node( wxT( "sheet" ) ) );
// get the string representation of the sheet index number.
// Note that sheet->GetIndex() is zero index base and we need to increment the number by one to make
// human readable
sheetTxt.Printf( wxT( "%d" ), ( sheetList.GetIndex() + 1 ) );
// Note that sheet->GetIndex() is zero index base and we need to increment the
// number by one to make it human readable
sheetTxt.Printf( wxT( "%u" ), i + 1 );
xsheet->AddAttribute( wxT( "number" ), sheetTxt );
xsheet->AddAttribute( wxT( "name" ), sheet->PathHumanReadable() );
xsheet->AddAttribute( wxT( "tstamps" ), sheet->Path() );
xsheet->AddAttribute( wxT( "name" ), sheetList[i].PathHumanReadable() );
xsheet->AddAttribute( wxT( "tstamps" ), sheetList[i].Path() );
TITLE_BLOCK tb = screen->GetTitleBlock();

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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
@ -66,13 +66,13 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, uns
// Create netlist module section
m_ReferencesAlreadyFound.Clear();
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
for( EDA_ITEM* item = path->LastDrawList(); item; item = item->Next() )
for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
{
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, path );
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, &sheetList[i] );
if( !comp )
break;
@ -87,7 +87,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, uns
{
if( part->GetFootPrints().GetCount() != 0 ) // Put in list
{
cmpList.push_back( SCH_REFERENCE( comp, part, *path ) );
cmpList.push_back( SCH_REFERENCE( comp, part, sheetList[i] ) );
}
}
@ -99,10 +99,10 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, uns
else
footprint = wxT( "$noname" );
field = comp->GetRef( path );
field = comp->GetRef( &sheetList[i] );
ret |= fprintf( f, " ( %s %s",
TO_UTF8( comp->GetPath( path ) ),
TO_UTF8( comp->GetPath( &sheetList[i] ) ),
TO_UTF8( footprint ) );
ret |= fprintf( f, " %s", TO_UTF8( field ) );

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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
@ -79,11 +79,11 @@ bool NETLIST_EXPORTER_PSPICE::WriteNetlist( const wxString& aOutFileName, unsign
// commands) and create text list starting by [+]pspice , or [+]gnucap
// (simulator commands)
bufnum[BUFYPOS_LEN] = 0;
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() )
for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
{
size_t l1, l2;
wxChar ident;
@ -162,13 +162,13 @@ bool NETLIST_EXPORTER_PSPICE::WriteNetlist( const wxString& aOutFileName, unsign
m_ReferencesAlreadyFound.Clear();
for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
ret |= fprintf( f, "* Sheet Name: %s\n", TO_UTF8( sheet->PathHumanReadable() ) );
ret |= fprintf( f, "* Sheet Name: %s\n", TO_UTF8( sheetList[i].PathHumanReadable() ) );
for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() )
for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
{
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, sheet );
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, &sheetList[i] );
if( !comp )
break;
@ -235,7 +235,7 @@ bool NETLIST_EXPORTER_PSPICE::WriteNetlist( const wxString& aOutFileName, unsign
}
//Get Standard Reference Designator:
wxString RefName = comp->GetRef( sheet );
wxString RefName = comp->GetRef( &sheetList[i] );
//Conditionally add Prefix only for devices that begin with U or IC:
if( aUsePrefix )

View File

@ -40,7 +40,6 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
{
SCH_EDIT_FRAME* schframe = m_parent;
SCH_SCREEN* screen = schframe->GetScreen();
SCH_SHEET_PATH* sheetpath;
SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet();
/* When printing all pages, the printed page is not the current page.
@ -49,26 +48,21 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
* because in complex hierarchies a SCH_SCREEN (a schematic drawings)
* is shared between many sheets
*/
SCH_SHEET_LIST SheetList( NULL );
SCH_SHEET_LIST sheetList;
if( aPlotAll )
sheetList.BuildSheetList( g_RootSheet );
else
sheetList.push_back( schframe->GetCurrentSheet() );
sheetpath = SheetList.GetFirst();
SCH_SHEET_PATH list;
REPORTER& reporter = m_MessagesBox->Reporter();
while( true )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
if( aPlotAll )
{
if( sheetpath == NULL )
break;
list = *sheetpath;
schframe->SetCurrentSheet( list );
schframe->GetCurrentSheet().UpdateAllScreenReferences();
schframe->SetSheetNumberAndCount();
screen = schframe->GetCurrentSheet().LastScreen();
sheetpath = SheetList.GetNext();
}
schframe->SetCurrentSheet( sheetList[i] );
schframe->GetCurrentSheet().UpdateAllScreenReferences();
schframe->SetSheetNumberAndCount();
screen = schframe->GetCurrentSheet().LastScreen();
wxPoint plot_offset;
wxString msg;
@ -102,10 +96,6 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
schframe->SetSheetNumberAndCount();
return;
}
if( !aPlotAll )
{
break;
}
}
schframe->SetCurrentSheet( oldsheetpath );

View File

@ -111,7 +111,6 @@ void DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth()
void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
{
SCH_SCREEN* screen = m_parent->GetScreen();
SCH_SHEET_PATH* sheetpath;
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
/* When printing all pages, the printed page is not the current page.
@ -120,33 +119,27 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
* because in complex hierarchies a SCH_SCREEN (a schematic drawings)
* is shared between many sheets
*/
SCH_SHEET_LIST SheetList( NULL );
SCH_SHEET_LIST sheetList;
if( aPlotAll )
sheetList.BuildSheetList( g_RootSheet );
else
sheetList.push_back( m_parent->GetCurrentSheet() );
sheetpath = SheetList.GetFirst();
SCH_SHEET_PATH list;
REPORTER& reporter = m_MessagesBox->Reporter();
SetHPGLPenWidth();
while( true )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
if( aPlotAll )
{
if( sheetpath == NULL )
break;
m_parent->SetCurrentSheet( sheetList[i] );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
list = *sheetpath;
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();
sheetpath = SheetList.GetNext();
}
if( !screen ) // LastScreen() may return NULL
screen = m_parent->GetScreen();
const PAGE_INFO& curPage = screen->GetPageSettings();
@ -179,7 +172,7 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
LOCALE_IO toggle;
if( Plot_1_Page_HPGL( plotFileName.GetFullPath(), screen, plotPage, plotOffset,
plot_scale, aPlotFrameRef ) )
plot_scale, aPlotFrameRef ) )
{
msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ACTION );
@ -190,9 +183,6 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}
if( !aPlotAll )
break;
}
catch( IO_ERROR& e )
{

View File

@ -41,7 +41,6 @@
void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
{
SCH_SCREEN* screen = m_parent->GetScreen();
SCH_SHEET_PATH* sheetpath;
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
/* When printing all pages, the printed page is not the current page. In
@ -51,9 +50,12 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
* between many sheets and component references depend on the actual sheet
* path used
*/
SCH_SHEET_LIST SheetList( NULL );
SCH_SHEET_LIST sheetList;
sheetpath = SheetList.GetFirst();
if( aPlotAll )
sheetList.BuildSheetList( g_RootSheet );
else
sheetList.push_back( m_parent->GetCurrentSheet() );
// Allocate the plotter and set the job level parameter
PDF_PLOTTER* plotter = new PDF_PLOTTER();
@ -65,26 +67,14 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
wxFileName plotFileName;
REPORTER& reporter = m_MessagesBox->Reporter();
// First page handling is different
bool first_page = true;
do
for( unsigned i = 0; i < sheetList.size(); i++ )
{
// Step over the schematic hierarchy
if( aPlotAll )
{
wxCHECK_RET( sheetpath != NULL, wxT( "Attempt to plot undefined sheet path." ) );
m_parent->SetCurrentSheet( sheetList[i] );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
SCH_SHEET_PATH list = *sheetpath;
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
sheetpath = SheetList.GetNext();
}
if( first_page )
if( i == 0 )
{
try
@ -107,8 +97,6 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
SetLocaleTo_C_standard();
setupPlotPagePDF( plotter, screen );
plotter->StartPlot();
first_page = false;
}
catch( const IO_ERROR& e )
{
@ -131,7 +119,7 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
}
plotOneSheetPDF( plotter, screen, aPlotFrameRef );
} while( aPlotAll && sheetpath );
}
// Everything done, close the plot and restore the environment
msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) );

View File

@ -39,10 +39,9 @@
void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
{
SCH_SCREEN* screen = m_parent->GetScreen();
SCH_SHEET_PATH* sheetpath;
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
PAGE_INFO actualPage; // page size selected in schematic
PAGE_INFO plotPage; // page size selected to plot
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
PAGE_INFO actualPage; // page size selected in schematic
PAGE_INFO plotPage; // page size selected to plot
/* When printing all pages, the printed page is not the current page.
* In complex hierarchies, we must update component references
@ -50,26 +49,19 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
* because in complex hierarchies a SCH_SCREEN (a drawing )
* is shared between many sheets and component references depend on the actual sheet path used
*/
SCH_SHEET_LIST SheetList( NULL );
SCH_SHEET_LIST sheetList;
sheetpath = SheetList.GetFirst();
SCH_SHEET_PATH list;
if( aPlotAll )
sheetList.BuildSheetList( g_RootSheet );
else
sheetList.push_back( m_parent->GetCurrentSheet() );
while( true )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
if( aPlotAll )
{
if( sheetpath == NULL )
break;
list = *sheetpath;
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
sheetpath = SheetList.GetNext();
}
m_parent->SetCurrentSheet( sheetList[i] );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
actualPage = screen->GetPageSettings();
switch( m_pageSizeSelect )
@ -129,9 +121,6 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
msg.Printf( wxT( "PS Plotter exception: %s"), GetChars( e.errorText ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}
if( !aPlotAll )
break;
}
m_parent->SetCurrentSheet( oldsheetpath );

View File

@ -43,108 +43,60 @@
void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef )
{
wxString msg;
REPORTER& reporter = m_MessagesBox->Reporter();
wxString msg;
REPORTER& reporter = m_MessagesBox->Reporter();
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
SCH_SHEET_LIST sheetList;
if( aPrintAll )
sheetList.BuildSheetList( g_RootSheet );
else
sheetList.push_back( m_parent->GetCurrentSheet() );
for( unsigned i = 0; i < sheetList.size(); i++ )
{
SCH_SHEET_PATH* sheetpath;
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
SCH_SHEET_LIST SheetList( NULL );
sheetpath = SheetList.GetFirst();
SCH_SHEET_PATH list;
for( ; ; )
{
if( sheetpath == NULL )
{
break;
}
SCH_SCREEN* screen;
list = *sheetpath;
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
sheetpath = SheetList.GetNext();
try
{
wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
wxString ext = SVG_PLOTTER::GetDefaultFileExtension();
wxFileName plotFileName = createPlotFileName( m_outputDirectoryName,
fname, ext, &reporter );
bool success = plotOneSheetSVG( m_parent, plotFileName.GetFullPath(), screen,
getModeColor() ? false : true,
aPrintFrameRef );
if( !success )
{
msg.Printf( _( "Cannot create file '%s'.\n" ),
GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}
else
{
msg.Printf( _( "Plot: '%s' OK.\n" ),
GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ACTION );
}
}
catch( const IO_ERROR& e )
{
// Cannot plot SVG file
msg.Printf( wxT( "SVG Plotter exception: %s" ), GetChars( e.errorText ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
m_parent->SetCurrentSheet( oldsheetpath );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
return;
}
}
m_parent->SetCurrentSheet( oldsheetpath );
SCH_SCREEN* screen;
m_parent->SetCurrentSheet( sheetList[i] );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
}
else // Print current sheet
{
SCH_SCREEN* screen = (SCH_SCREEN*) m_parent->GetScreen();
screen = m_parent->GetCurrentSheet().LastScreen();
try
{
wxString fname = screen->GetFileName();
wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
wxString ext = SVG_PLOTTER::GetDefaultFileExtension();
wxFileName fn = createPlotFileName( m_outputDirectoryName, fname, ext );
wxFileName plotFileName = createPlotFileName( m_outputDirectoryName,
fname, ext, &reporter );
bool success = plotOneSheetSVG( m_parent, fn.GetFullPath(), screen,
bool success = plotOneSheetSVG( m_parent, plotFileName.GetFullPath(), screen,
getModeColor() ? false : true,
aPrintFrameRef );
if( success )
if( !success )
{
msg.Printf( _( "Cannot create file '%s'.\n" ),
GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}
else
{
msg.Printf( _( "Plot: '%s' OK.\n" ),
GetChars( fn.GetFullPath() ) );
GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ACTION );
}
else // Error
{
msg.Printf( _( "Unable to create file '%s'.\n" ),
GetChars( fn.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}
}
catch( const IO_ERROR& e )
{
// Cannot plot SVG file
msg.Printf( wxT( "SVG Plotter exception: %s."), GetChars( e.errorText ) );
msg.Printf( wxT( "SVG Plotter exception: %s" ), GetChars( e.errorText ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
return;
break;
}
}
m_parent->SetCurrentSheet( oldsheetpath );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
}

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-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
@ -528,13 +528,12 @@ void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData,
}
else
{
SCH_SHEET_LIST schematic;
m_sheetPath = schematic.GetFirst();
SCH_SHEET_LIST schematic( g_RootSheet );
while( m_sheetPath != NULL )
for( unsigned i = 0; i < schematic.size(); i++ )
{
m_sheetPath = &schematic[i];
EDA_ITEM::IterateForward( m_sheetPath->LastDrawList(), this, NULL, m_ScanTypes );
m_sheetPath = schematic.GetNext();
}
}

View File

@ -466,82 +466,23 @@ SCH_SHEET* SCH_SHEET_PATH::FindSheetByName( const wxString& aSheetName )
/********************************************************************/
SCH_SHEET_LIST::SCH_SHEET_LIST( SCH_SHEET* aSheet )
{
m_index = 0;
m_count = 0;
m_list = NULL;
m_isRootSheet = false;
if( aSheet == NULL )
aSheet = g_RootSheet;
BuildSheetList( aSheet );
}
SCH_SHEET_PATH* SCH_SHEET_LIST::GetFirst()
{
m_index = 0;
if( GetCount() > 0 )
return &( m_list[0] );
return NULL;
}
SCH_SHEET_PATH* SCH_SHEET_LIST::GetNext()
{
if( m_index < GetCount() )
m_index++;
return GetSheet( m_index );
}
SCH_SHEET_PATH* SCH_SHEET_LIST::GetLast()
{
if( GetCount() == 0 )
return NULL;
m_index = GetCount() - 1;
return GetSheet( m_index );
}
SCH_SHEET_PATH* SCH_SHEET_LIST::GetPrevious()
{
if( m_index == 0 )
return NULL;
m_index -= 1;
return GetSheet( m_index );
}
SCH_SHEET_PATH* SCH_SHEET_LIST::GetSheet( int aIndex ) const
{
if( aIndex < GetCount() )
return &( m_list[aIndex] );
return NULL;
if( aSheet != NULL )
BuildSheetList( aSheet );
}
SCH_SHEET_PATH* SCH_SHEET_LIST::GetSheetByPath( const wxString aPath, bool aHumanReadable )
{
SCH_SHEET_PATH* sheet = GetFirst();
wxString sheetPath;
while( sheet )
for( unsigned i = 0; i < size(); i++ )
{
sheetPath = ( aHumanReadable ) ? sheet->PathHumanReadable() : sheet->Path();
sheetPath = ( aHumanReadable ) ? at( i ).PathHumanReadable() : at( i ).Path();
if( sheetPath == aPath )
return sheet;
sheet = GetNext();
return &at( i );
}
return NULL;
@ -555,52 +496,41 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet )
if( aSheet == g_RootSheet )
m_isRootSheet = true;
if( m_list == NULL )
{
int count = aSheet->CountSheets();
m_count = count;
m_index = 0;
m_list = new SCH_SHEET_PATH[ count ];
m_currList.clear();
}
m_currList.push_back( aSheet );
m_currentSheetPath.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++;
m_currentSheetPath.SetPageNumber( size() + 1 );
push_back( m_currentSheetPath );
if( aSheet->GetScreen() )
{
EDA_ITEM* strct = m_currList.LastDrawList();
EDA_ITEM* item = m_currentSheetPath.LastDrawList();
while( strct )
while( item )
{
if( strct->Type() == SCH_SHEET_T )
if( item->Type() == SCH_SHEET_T )
{
SCH_SHEET* sheet = (SCH_SHEET*) strct;
SCH_SHEET* sheet = (SCH_SHEET*) item;
BuildSheetList( sheet );
}
strct = strct->Next();
item = item->Next();
}
}
m_currList.pop_back();
m_currentSheetPath.pop_back();
}
bool SCH_SHEET_LIST::IsModified()
{
for( SCH_SHEET_PATH* sheet = GetFirst(); sheet; sheet = GetNext() )
for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
{
if( sheet->LastScreen() && sheet->LastScreen()->IsModify() )
if( (*it).LastScreen() && (*it).LastScreen()->IsModify() )
return true;
}
@ -610,9 +540,9 @@ bool SCH_SHEET_LIST::IsModified()
bool SCH_SHEET_LIST::IsAutoSaveRequired()
{
for( SCH_SHEET_PATH* sheet = GetFirst(); sheet; sheet = GetNext() )
for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
{
if( sheet->LastScreen() && sheet->LastScreen()->IsSave() )
if( (*it).LastScreen() && (*it).LastScreen()->IsSave() )
return true;
}
@ -622,10 +552,10 @@ bool SCH_SHEET_LIST::IsAutoSaveRequired()
void SCH_SHEET_LIST::ClearModifyStatus()
{
for( SCH_SHEET_PATH* sheet = GetFirst(); sheet; sheet = GetNext() )
for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
{
if( sheet->LastScreen() )
sheet->LastScreen()->ClrModify();
if( (*it).LastScreen() )
(*it).LastScreen()->ClrModify();
}
}
@ -634,29 +564,32 @@ void SCH_SHEET_LIST::AnnotatePowerSymbols( PART_LIBS* aLibs )
{
int ref = 1;
for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() )
path->AnnotatePowerSymbols( aLibs, &ref );
for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
(*it).AnnotatePowerSymbols( aLibs, &ref );
}
void SCH_SHEET_LIST::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences,
bool aIncludePowerSymbols )
bool aIncludePowerSymbols )
{
for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() )
path->GetComponents( aLibs, aReferences, aIncludePowerSymbols );
for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
(*it).GetComponents( aLibs, aReferences, aIncludePowerSymbols );
}
void SCH_SHEET_LIST::GetMultiUnitComponents( PART_LIBS* aLibs,
SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols )
SCH_MULTI_UNIT_REFERENCE_MAP &aRefList,
bool aIncludePowerSymbols )
{
for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() )
for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
{
SCH_MULTI_UNIT_REFERENCE_MAP tempMap;
path->GetMultiUnitComponents( aLibs, tempMap );
(*it).GetMultiUnitComponents( aLibs, tempMap );
BOOST_FOREACH( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair, tempMap )
{
// Merge this list into the main one
unsigned n_refs = pair.second.GetCount();
for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
{
aRefList[pair.first].AddItem( pair.second[thisRef] );
@ -673,11 +606,11 @@ SCH_ITEM* SCH_SHEET_LIST::FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFo
bool firstItemFound = false;
SCH_ITEM* drawItem = NULL;
SCH_SHEET_PATH* sheet = GetFirst();
SCH_SHEET_PATHS_ITER it = begin();
while( sheet )
while( it != end() )
{
drawItem = sheet->LastDrawList();
drawItem = (*it).LastDrawList();
while( drawItem )
{
@ -686,7 +619,7 @@ SCH_ITEM* SCH_SHEET_LIST::FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFo
if( aLastItem == NULL || firstItemFound )
{
if( aSheetFoundIn )
*aSheetFoundIn = sheet;
*aSheetFoundIn = &(*it);
return drawItem;
}
@ -699,12 +632,12 @@ SCH_ITEM* SCH_SHEET_LIST::FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFo
drawItem = drawItem->Next();
}
sheet = GetNext();
++it;
if( sheet == NULL && aLastItem && aWrap && !hasWrapped )
if( it == end() && aLastItem && aWrap && !hasWrapped )
{
hasWrapped = true;
sheet = GetFirst();
it = begin();
}
}
@ -718,11 +651,11 @@ SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aShe
bool hasWrapped = false;
bool firstItemFound = false;
SCH_ITEM* drawItem = NULL;
SCH_SHEET_PATH* sheet = GetLast();
SCH_SHEET_PATHS_RITER it = rbegin();
while( sheet )
while( it != rend() )
{
drawItem = sheet->FirstDrawList();
drawItem = (*it).FirstDrawList();
while( drawItem )
{
@ -731,7 +664,7 @@ SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aShe
if( aLastItem == NULL || firstItemFound )
{
if( aSheetFoundIn )
*aSheetFoundIn = sheet;
*aSheetFoundIn = &(*it);
return drawItem;
}
@ -744,12 +677,12 @@ SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aShe
drawItem = drawItem->Back();
}
sheet = GetPrevious();
++it;
if( sheet == NULL && aLastItem && aWrap && !hasWrapped )
if( it == rend() && aLastItem && aWrap && !hasWrapped )
{
hasWrapped = true;
sheet = GetLast();
it = rbegin();
}
}
@ -762,8 +695,8 @@ bool SCH_SHEET_LIST::SetComponentFootprint( const wxString& aReference,
{
bool found = false;
for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() )
found = path->SetComponentFootprint( aReference, aFootPrint, aSetVisible );
for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
found = (*it).SetComponentFootprint( aReference, aFootPrint, aSetVisible );
return found;
}
@ -773,16 +706,16 @@ bool SCH_SHEET_LIST::IsComplexHierarchy() const
{
wxString fileName;
for( int i = 0; i < m_count; i++ )
for( unsigned i = 0; i < size(); i++ )
{
fileName = m_list[i].Last()->GetFileName();
fileName = at( i ).Last()->GetFileName();
for( int j = 0; j < m_count; j++ )
for( unsigned j = 0; j < size(); j++ )
{
if( i == j )
continue;
if( fileName == m_list[j].Last()->GetFileName() )
if( fileName == at( j ).Last()->GetFileName() )
return true;
}
}
@ -801,17 +734,17 @@ bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
destFn.MakeAbsolute( rootFn.GetPath() );
// Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
for( int i = 0; i < m_count; i++ )
for( unsigned i = 0; i < size(); i++ )
{
// Test each SCH_SHEET_PATH in the source sheet.
for( int j = 0; j < aSrcSheetHierarchy.GetCount(); j++ )
for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
{
SCH_SHEET_PATH* sheetPath = aSrcSheetHierarchy.GetSheet( j );
const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j];
for( unsigned k = 0; k < sheetPath->size(); k++ )
{
if( m_list[i].TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
aDestFileName ) )
if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
aDestFileName ) )
return true;
}
}
@ -824,9 +757,9 @@ bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
SCH_SHEET* SCH_SHEET_LIST::FindSheetByName( const wxString& aSheetName )
{
for( int i = 0; i < m_count; i++ )
for( unsigned i = 0; i < size(); i++ )
{
SCH_SHEET* sheet = m_list[i].FindSheetByName( aSheetName );
SCH_SHEET* sheet = at( i ).FindSheetByName( aSheetName );
if( sheet )
return sheet;

View File

@ -120,12 +120,19 @@ public:
int GetPageNumber() const { return m_pageNumber; }
const SCH_SHEET* GetSheet( unsigned aIndex ) const
{
SCH_SHEET* retv = NULL;
if( aIndex < size() )
retv = at( aIndex );
return const_cast< SCH_SHEET* >( retv );
}
SCH_SHEET* GetSheet( unsigned aIndex )
{
if( aIndex < size() )
return at( aIndex );
return NULL;
return const_cast< SCH_SHEET* >( static_cast< const SCH_SHEET_PATH& >( *this ).GetSheet( aIndex ) );
}
/**
@ -305,100 +312,40 @@ public:
};
typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
typedef SCH_SHEET_PATHS::const_iterator SCH_SHEET_PATHS_CITER;
typedef SCH_SHEET_PATHS::reverse_iterator SCH_SHEET_PATHS_RITER;
typedef SCH_SHEET_PATHS::const_reverse_iterator SCH_SHEET_PATHS_CRITER;
/**
* Class SCH_SHEET_LIST
* handles the list of Sheets in a hierarchy.
* Sheets are not unique, there can be many sheets with the same
* filename and the same SCH_SCREEN reference.
* The schematic (SCH_SCREEN) is shared between these sheets,
* and component references are specific to a sheet path.
* When a sheet is entered, component references and sheet number are updated.
*
* handles a list of #SCH_SHEET_PATH objects in a flattened hierarchy.
*
* #SCH_SHEET objects are not unique, there can be many sheets with the same filename and
* that share the same #SCH_SCREEN reference. Each The schematic file (#SCH_SCREEN) may
* be shared between these sheets and component references are specific to a sheet path.
* When a sheet is entered, component references and sheet page number are updated.
*/
class SCH_SHEET_LIST
class SCH_SHEET_LIST : public SCH_SHEET_PATHS
{
private:
SCH_SHEET_PATH* m_list;
int m_count; /* Number of sheets included in hierarchy,
* starting at the given sheet in constructor .
* the given sheet is counted
*/
int m_index; /* internal variable to handle GetNext(): cleared by
* GetFirst() and incremented by GetNext() after
* returning the next item in m_list. Also used for
* internal calculations in BuildSheetList()
*/
bool m_isRootSheet;
SCH_SHEET_PATH m_currList;
SCH_SHEET_PATH m_currentSheetPath;
public:
/**
* Constructor
* builds the list of sheets from aSheet.
* If aSheet == NULL (default) build the whole list of sheets in hierarchy.
* So usually call it with no parameter.
* build a flattened list of SCH_SHEET_PATH objects from \a aSheet.
*
* If aSheet == NULL, then this is an empty hierarchy which the user can populate.
*/
SCH_SHEET_LIST( SCH_SHEET* aSheet = NULL );
~SCH_SHEET_LIST()
{
if( m_list )
delete[] m_list;
m_list = NULL;
}
/**
* Function GetCount
* @return the number of sheets in list:
* usually the number of sheets found in the whole hierarchy
*/
int GetCount() const { return m_count; }
/**
* Function GetIndex
* @return the last selected screen index.
*/
int GetIndex() const { return m_index; }
/**
* Function GetFirst
* @return the first item (sheet) in m_list and prepare calls to GetNext()
*/
SCH_SHEET_PATH* GetFirst();
/**
* Function GetNext
* @return the next item (sheet) in m_list or NULL if no more item in
* sheet list
*/
SCH_SHEET_PATH* GetNext();
/**
* Function GetLast
* returns the last sheet in the sheet list.
*
* @return Last sheet in the list or NULL if sheet list is empty.
*/
SCH_SHEET_PATH* GetLast();
/**
* Function GetPrevious
* returns the previous sheet in the sheet list.
*
* @return The previous sheet in the sheet list or NULL if already at the
* beginning of the list.
*/
SCH_SHEET_PATH* GetPrevious();
/**
* Function GetSheet
*
* @param aIndex A index in sheet list to get the sheet.
* @return the sheet at \a aIndex position in m_list or NULL if \a aIndex is
* outside the bounds of the index list.
*/
SCH_SHEET_PATH* GetSheet( int aIndex ) const;
~SCH_SHEET_LIST() {}
/**
* Function GetSheetByPath
@ -443,7 +390,8 @@ public:
* @param aReferences List of references to populate.
* @param aIncludePowerSymbols Set to false to only get normal components.
*/
void GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true );
void GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences,
bool aIncludePowerSymbols = true );
/**
* Function GetMultiUnitComponents
@ -455,7 +403,7 @@ public:
* @param aIncludePowerSymbols Set to false to only get normal components.
*/
void GetMultiUnitComponents( PART_LIBS* aLibs, SCH_MULTI_UNIT_REFERENCE_MAP &aRefList,
bool aIncludePowerSymbols = true );
bool aIncludePowerSymbols = true );
/**
* Function FindNextItem
@ -530,8 +478,6 @@ public:
*/
SCH_SHEET* FindSheetByName( const wxString& aSheetName );
private:
/**
* Function BuildSheetList
* builds the list of sheets and their sheet path from \a aSheet.

View File

@ -477,15 +477,13 @@ void SCH_EDIT_FRAME::SetSheetNumberAndCount()
int sheet_count = g_RootSheet->CountSheets();
int SheetNumber = 1;
wxString current_sheetpath = m_CurrentSheet->Path();
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
// Examine all sheets path to find the current sheets path,
// and count them from root to the current sheet path:
SCH_SHEET_PATH* sheet;
for( sheet = sheetList.GetFirst(); sheet != NULL; sheet = sheetList.GetNext() )
for( unsigned i = 0; i < sheetList.size(); i++ )
{
wxString sheetpath = sheet->Path();
wxString sheetpath = sheetList[i].Path();
if( sheetpath == current_sheetpath ) // Current sheet path found
break;
@ -614,7 +612,7 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
return;
}
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
if( sheetList.IsModified() )
{
@ -787,7 +785,7 @@ void SCH_EDIT_FRAME::OnUpdateHiddenPins( wxUpdateUIEvent& aEvent )
void SCH_EDIT_FRAME::OnUpdateSave( wxUpdateUIEvent& aEvent )
{
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
aEvent.Enable( sheetList.IsModified() );
}
@ -1232,7 +1230,7 @@ bool SCH_EDIT_FRAME::isAutoSaveRequired() const
if( g_RootSheet != NULL )
{
SCH_SHEET_LIST sheetList;
SCH_SHEET_LIST sheetList( g_RootSheet );
return sheetList.IsAutoSaveRequired();
}

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) 2004-2015 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-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
@ -46,7 +46,7 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy )
if( aSheet == NULL || aHierarchy == NULL )
return false;
SCH_SHEET_LIST hierarchy; // This is the schematic sheet hierarchy.
SCH_SHEET_LIST hierarchy( g_RootSheet ); // This is the schematic sheet hierarchy.
// Get the new texts
DIALOG_SCH_SHEET_PROPS dlg( this );