2011-10-15 13:25:57 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_sheet_path.cpp
|
|
|
|
* @brief SCH_SHEET_PATH class implementation.
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
|
|
|
#include "general.h"
|
2010-03-16 18:22:59 +00:00
|
|
|
#include "dlist.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
|
|
|
#include "sch_item_struct.h"
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
#include "netlist.h"
|
|
|
|
#include "class_library.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_sheet.h"
|
|
|
|
#include "sch_sheet_path.h"
|
|
|
|
#include "sch_component.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "template_fieldnames.h"
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
#include "dialogs/dialog_schematic_find.h"
|
2009-01-04 18:52:57 +00:00
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH::SCH_SHEET_PATH()
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2011-01-23 21:22:42 +00:00
|
|
|
for( int i = 0; i<DSLSZ; i++ )
|
|
|
|
m_sheets[i] = NULL;
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
m_numSheets = 0;
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
bool SCH_SHEET_PATH::BuildSheetPathInfoFromSheetPathValue( const wxString& aPath, bool aFound )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
if( aFound )
|
2009-01-07 20:09:03 +00:00
|
|
|
return true;
|
|
|
|
|
2011-12-08 21:05:43 +00:00
|
|
|
if( GetSheetsCount() == 0 )
|
2009-01-07 20:09:03 +00:00
|
|
|
Push( g_RootSheet );
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( aPath == Path() )
|
2009-01-07 20:09:03 +00:00
|
|
|
return true;
|
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
SCH_ITEM* schitem = LastDrawList();
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
while( schitem && GetSheetsCount() < NB_MAX_SHEET )
|
2009-01-07 20:09:03 +00:00
|
|
|
{
|
2011-01-23 21:22:42 +00:00
|
|
|
if( schitem->Type() == SCH_SHEET_T )
|
2009-01-07 20:09:03 +00:00
|
|
|
{
|
2011-01-23 21:22:42 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) schitem;
|
2009-01-07 20:09:03 +00:00
|
|
|
Push( sheet );
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( aPath == Path() )
|
2009-01-07 20:09:03 +00:00
|
|
|
return true;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( BuildSheetPathInfoFromSheetPathValue( aPath ) )
|
2009-01-07 20:09:03 +00:00
|
|
|
return true;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-01-07 20:09:03 +00:00
|
|
|
Pop();
|
|
|
|
}
|
2011-12-01 16:49:28 +00:00
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
schitem = schitem->Next();
|
2009-01-07 20:09:03 +00:00
|
|
|
}
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2009-01-07 20:09:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
int SCH_SHEET_PATH::Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2011-01-23 21:22:42 +00:00
|
|
|
if( m_numSheets > aSheetPathToTest.m_numSheets )
|
2009-01-04 18:52:57 +00:00
|
|
|
return 1;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
if( m_numSheets < aSheetPathToTest.m_numSheets )
|
2009-01-04 18:52:57 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
//otherwise, same number of sheets.
|
|
|
|
for( unsigned i = 0; i<m_numSheets; i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2011-12-12 08:37:05 +00:00
|
|
|
if( m_sheets[i]->GetTimeStamp() > aSheetPathToTest.m_sheets[i]->GetTimeStamp() )
|
2009-01-04 18:52:57 +00:00
|
|
|
return 1;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2011-12-12 08:37:05 +00:00
|
|
|
if( m_sheets[i]->GetTimeStamp() < aSheetPathToTest.m_sheets[i]->GetTimeStamp() )
|
2009-01-04 18:52:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET* SCH_SHEET_PATH::Last()
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2011-01-23 21:22:42 +00:00
|
|
|
if( m_numSheets )
|
|
|
|
return m_sheets[m_numSheets - 1];
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SCREEN* SCH_SHEET_PATH::LastScreen()
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2010-04-01 13:15:48 +00:00
|
|
|
SCH_SHEET* lastSheet = Last();
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2010-04-01 13:15:48 +00:00
|
|
|
if( lastSheet )
|
2011-01-20 16:34:57 +00:00
|
|
|
return lastSheet->GetScreen();
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_ITEM* SCH_SHEET_PATH::LastDrawList()
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2011-01-23 21:22:42 +00:00
|
|
|
SCH_SHEET* lastSheet = Last();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
if( lastSheet && lastSheet->GetScreen() )
|
|
|
|
return lastSheet->GetScreen()->GetDrawItems();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
SCH_ITEM* SCH_SHEET_PATH::FirstDrawList()
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = NULL;
|
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
if( m_numSheets && m_sheets[0]->GetScreen() )
|
|
|
|
item = m_sheets[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
|
|
|
|
* list.
|
|
|
|
*/
|
|
|
|
SCH_ITEM* lastItem = NULL;
|
|
|
|
|
|
|
|
while( item != NULL )
|
|
|
|
{
|
|
|
|
lastItem = item;
|
|
|
|
item = item->Next();
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
return lastItem;
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_SHEET_PATH::Push( SCH_SHEET* aSheet )
|
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
wxCHECK_RET( m_numSheets < DSLSZ,
|
|
|
|
wxString::Format( _( "Schematic sheets can only be nested %d levels deep." ),
|
|
|
|
DSLSZ ) );
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
m_sheets[ m_numSheets ] = aSheet;
|
|
|
|
m_numSheets++;
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET* SCH_SHEET_PATH::Pop()
|
|
|
|
{
|
2011-01-23 21:22:42 +00:00
|
|
|
if( m_numSheets > 0 )
|
|
|
|
{
|
|
|
|
m_numSheets--;
|
|
|
|
return m_sheets[m_numSheets];
|
|
|
|
}
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
return NULL;
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-17 01:06:08 +00:00
|
|
|
wxString SCH_SHEET_PATH::Path() const
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2009-01-04 18:52:57 +00:00
|
|
|
wxString s, t;
|
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
s = wxT( "/" ); // This is the root path
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
// start at 1 to avoid the root sheet,
|
|
|
|
// which does not need to be added to the path
|
|
|
|
// it's timestamp changes anyway.
|
2011-01-23 21:22:42 +00:00
|
|
|
for( unsigned i = 1; i < m_numSheets; i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2011-12-12 08:37:05 +00:00
|
|
|
t.Printf( _( "%8.8lX/" ), m_sheets[i]->GetTimeStamp() );
|
2009-01-04 18:52:57 +00:00
|
|
|
s = s + t;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
wxString SCH_SHEET_PATH::PathHumanReadable() const
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2009-01-04 18:52:57 +00:00
|
|
|
wxString s, t;
|
|
|
|
|
|
|
|
s = wxT( "/" );
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
// start at 1 to avoid the root sheet, as above.
|
2011-01-23 21:22:42 +00:00
|
|
|
for( unsigned i = 1; i< m_numSheets; i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
s = s + m_sheets[i]->GetName() + wxT( "/" );
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_SHEET_PATH::UpdateAllScreenReferences()
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* t = LastDrawList();
|
2009-01-04 18:52:57 +00:00
|
|
|
|
|
|
|
while( t )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( t->Type() == SCH_COMPONENT_T )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) t;
|
2009-01-06 20:09:32 +00:00
|
|
|
component->GetField( REFERENCE )->m_Text = component->GetRef( this );
|
2010-12-14 15:56:30 +00:00
|
|
|
component->SetUnit( component->GetUnitSelection( this ) );
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
2010-12-14 15:56:30 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
t = t->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
void SCH_SHEET_PATH::AnnotatePowerSymbols( int* aReference )
|
|
|
|
{
|
|
|
|
int ref = 1;
|
|
|
|
|
|
|
|
if( aReference != NULL )
|
|
|
|
ref = *aReference;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item = LastDrawList(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
|
|
|
|
|
|
|
|
if( ( entry == NULL ) || !entry->IsPower() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString refstr = component->GetPrefix();
|
|
|
|
|
|
|
|
//str will be "C?" or so after the ClearAnnotation call.
|
|
|
|
while( refstr.Last() == '?' )
|
|
|
|
refstr.RemoveLast();
|
|
|
|
|
|
|
|
if( !refstr.StartsWith( wxT( "#" ) ) )
|
|
|
|
refstr = wxT( "#" ) + refstr;
|
|
|
|
|
|
|
|
refstr << wxT( "0" ) << ref;
|
|
|
|
component->SetRef( this, refstr );
|
|
|
|
ref++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aReference != NULL )
|
|
|
|
*aReference = ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
void SCH_SHEET_PATH::GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2011-01-01 17:28:21 +00:00
|
|
|
// Search to sheet path number:
|
|
|
|
int sheetnumber = 1; // 1 = root
|
|
|
|
SCH_SHEET_LIST sheetList;
|
2011-03-29 19:33:07 +00:00
|
|
|
|
2011-01-01 17:28:21 +00:00
|
|
|
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path != NULL;
|
|
|
|
path = sheetList.GetNext(), sheetnumber++ )
|
2011-03-29 19:33:07 +00:00
|
|
|
{
|
2011-01-01 17:28:21 +00:00
|
|
|
if( Cmp(*path) == 0 )
|
|
|
|
break;
|
2011-03-29 19:33:07 +00:00
|
|
|
}
|
2011-01-01 17:28:21 +00:00
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
for( SCH_ITEM* item = LastDrawList(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
|
|
|
|
|
|
|
// Skip pseudo components, which have a reference starting with #. This mainly
|
|
|
|
// effects power symbols.
|
|
|
|
if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
|
|
|
|
|
|
|
|
if( entry == NULL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_REFERENCE reference = SCH_REFERENCE( component, entry, *this );
|
2011-01-06 16:55:18 +00:00
|
|
|
reference.SetSheetNumber( sheetnumber );
|
2011-01-01 17:28:21 +00:00
|
|
|
aReferences.AddItem( reference );
|
2010-12-31 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
SCH_ITEM* SCH_SHEET_PATH::FindNextItem( KICAD_T aType, SCH_ITEM* aLastItem, bool aWrap )
|
|
|
|
{
|
|
|
|
bool hasWrapped = false;
|
|
|
|
bool firstItemFound = false;
|
|
|
|
SCH_ITEM* drawItem = LastDrawList();
|
|
|
|
|
|
|
|
while( drawItem != NULL )
|
|
|
|
{
|
|
|
|
if( drawItem->Type() == aType )
|
|
|
|
{
|
|
|
|
if( aLastItem == NULL || firstItemFound )
|
|
|
|
{
|
|
|
|
return drawItem;
|
|
|
|
}
|
|
|
|
else if( !firstItemFound && drawItem == aLastItem )
|
|
|
|
{
|
|
|
|
firstItemFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drawItem = drawItem->Next();
|
|
|
|
|
|
|
|
if( drawItem == NULL && aLastItem && aWrap && !hasWrapped )
|
|
|
|
{
|
|
|
|
hasWrapped = true;
|
|
|
|
drawItem = LastDrawList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_ITEM* SCH_SHEET_PATH::FindPreviousItem( KICAD_T aType, SCH_ITEM* aLastItem, bool aWrap )
|
|
|
|
{
|
|
|
|
bool hasWrapped = false;
|
|
|
|
bool firstItemFound = false;
|
|
|
|
SCH_ITEM* drawItem = FirstDrawList();
|
|
|
|
|
|
|
|
while( drawItem != NULL )
|
|
|
|
{
|
|
|
|
if( drawItem->Type() == aType )
|
|
|
|
{
|
|
|
|
if( aLastItem == NULL || firstItemFound )
|
|
|
|
{
|
|
|
|
return drawItem;
|
|
|
|
}
|
|
|
|
else if( !firstItemFound && drawItem == aLastItem )
|
|
|
|
{
|
|
|
|
firstItemFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drawItem = drawItem->Back();
|
|
|
|
|
|
|
|
if( drawItem == NULL && aLastItem && aWrap && !hasWrapped )
|
|
|
|
{
|
|
|
|
hasWrapped = true;
|
|
|
|
drawItem = FirstDrawList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 18:23:01 +00:00
|
|
|
bool SCH_SHEET_PATH::SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
|
|
|
|
bool aSetVisible )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = LastScreen();
|
|
|
|
|
|
|
|
if( screen == NULL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return screen->SetComponentFootprint( this, aReference, aFootPrint, aSetVisible );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
SCH_SHEET_PATH& SCH_SHEET_PATH::operator=( const SCH_SHEET_PATH& d1 )
|
2011-01-23 21:22:42 +00:00
|
|
|
{
|
2011-01-30 22:22:38 +00:00
|
|
|
if( this == &d1 ) // Self assignment is bad!
|
|
|
|
return *this;
|
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
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;
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
return *this;
|
2011-01-23 21:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
bool SCH_SHEET_PATH::operator==( const SCH_SHEET_PATH& d1 ) const
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2011-01-23 21:22:42 +00:00
|
|
|
if( m_numSheets != d1.m_numSheets )
|
2009-01-04 18:52:57 +00:00
|
|
|
return false;
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
for( unsigned i = 0; i < m_numSheets; i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2011-01-23 21:22:42 +00:00
|
|
|
if( m_sheets[i] != d1.m_sheets[i] )
|
2009-01-04 18:52:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
/********************************************************************/
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Class SCH_SHEET_LIST to handle the list of Sheets in a hierarchy */
|
2011-03-29 19:33:07 +00:00
|
|
|
/********************************************************************/
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST::SCH_SHEET_LIST( SCH_SHEET* aSheet )
|
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
m_index = 0;
|
|
|
|
m_count = 0;
|
|
|
|
m_List = NULL;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
if( aSheet == NULL )
|
|
|
|
aSheet = g_RootSheet;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
BuildSheetList( aSheet );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* SCH_SHEET_LIST::GetFirst()
|
|
|
|
{
|
2009-01-04 18:52:57 +00:00
|
|
|
m_index = 0;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
if( GetCount() > 0 )
|
2009-01-04 18:52:57 +00:00
|
|
|
return &( m_List[0] );
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* SCH_SHEET_LIST::GetNext()
|
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
if( m_index < GetCount() )
|
2009-01-04 18:52:57 +00:00
|
|
|
m_index++;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
return GetSheet( m_index );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* SCH_SHEET_LIST::GetSheet( int aIndex )
|
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
if( aIndex < GetCount() )
|
2009-11-03 13:26:31 +00:00
|
|
|
return &( m_List[aIndex] );
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-17 01:06:08 +00:00
|
|
|
SCH_SHEET_PATH* SCH_SHEET_LIST::GetSheet( const wxString aPath, bool aHumanReadable )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH* sheet = GetFirst();
|
|
|
|
wxString sheetPath;
|
|
|
|
|
|
|
|
while( sheet != NULL )
|
|
|
|
{
|
|
|
|
sheetPath = ( aHumanReadable ) ? sheet->PathHumanReadable() : sheet->Path();
|
|
|
|
|
|
|
|
if( sheetPath == aPath )
|
|
|
|
return sheet;
|
|
|
|
|
|
|
|
sheet = GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet )
|
|
|
|
{
|
2009-01-04 18:52:57 +00:00
|
|
|
if( m_List == NULL )
|
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
int count = aSheet->CountSheets();
|
2009-01-04 18:52:57 +00:00
|
|
|
m_count = count;
|
|
|
|
m_index = 0;
|
2011-11-10 15:55:05 +00:00
|
|
|
m_List = new SCH_SHEET_PATH[ count ];
|
2009-01-04 18:52:57 +00:00
|
|
|
m_currList.Clear();
|
|
|
|
}
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
m_currList.Push( aSheet );
|
2009-01-04 18:52:57 +00:00
|
|
|
m_List[m_index] = m_currList;
|
|
|
|
m_index++;
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( aSheet->GetScreen() != NULL )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* strct = m_currList.LastDrawList();
|
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
while( strct )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( strct->Type() == SCH_SHEET_T )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) strct;
|
2009-01-06 20:09:32 +00:00
|
|
|
BuildSheetList( sheet );
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
strct = strct->Next();
|
|
|
|
}
|
|
|
|
}
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
m_currList.Pop();
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
bool SCH_SHEET_LIST::IsModified()
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PATH* sheet = GetFirst(); sheet != NULL; sheet = GetNext() )
|
|
|
|
{
|
|
|
|
if( sheet->LastScreen() && sheet->LastScreen()->IsModify() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
bool SCH_SHEET_LIST::IsAutoSaveRequired()
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PATH* sheet = GetFirst(); sheet != NULL; sheet = GetNext() )
|
|
|
|
{
|
|
|
|
if( sheet->LastScreen() && sheet->LastScreen()->IsSave() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
void SCH_SHEET_LIST::ClearModifyStatus()
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PATH* sheet = GetFirst(); sheet != NULL; sheet = GetNext() )
|
|
|
|
{
|
|
|
|
if( sheet->LastScreen() )
|
|
|
|
sheet->LastScreen()->ClrModify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
void SCH_SHEET_LIST::AnnotatePowerSymbols()
|
|
|
|
{
|
|
|
|
int ref = 1;
|
|
|
|
|
|
|
|
for( SCH_SHEET_PATH* path = GetFirst(); path != NULL; path = GetNext() )
|
|
|
|
path->AnnotatePowerSymbols( &ref );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-01 17:28:21 +00:00
|
|
|
void SCH_SHEET_LIST::GetComponents( SCH_REFERENCE_LIST& aReferences,
|
|
|
|
bool aIncludePowerSymbols )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
|
|
|
for( SCH_SHEET_PATH* path = GetFirst(); path != NULL; path = GetNext() )
|
|
|
|
path->GetComponents( aReferences, aIncludePowerSymbols );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
SCH_ITEM* SCH_SHEET_LIST::FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFoundIn,
|
|
|
|
SCH_ITEM* aLastItem, bool aWrap )
|
|
|
|
{
|
|
|
|
bool hasWrapped = false;
|
|
|
|
bool firstItemFound = false;
|
|
|
|
SCH_ITEM* drawItem = NULL;
|
|
|
|
SCH_SHEET_PATH* sheet = GetFirst();
|
|
|
|
|
|
|
|
while( sheet != NULL )
|
|
|
|
{
|
|
|
|
drawItem = sheet->LastDrawList();
|
|
|
|
|
|
|
|
while( drawItem != NULL )
|
|
|
|
{
|
|
|
|
if( drawItem->Type() == aType )
|
|
|
|
{
|
|
|
|
if( aLastItem == NULL || firstItemFound )
|
|
|
|
{
|
|
|
|
if( aSheetFoundIn )
|
|
|
|
*aSheetFoundIn = sheet;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
return drawItem;
|
|
|
|
}
|
|
|
|
else if( !firstItemFound && drawItem == aLastItem )
|
|
|
|
{
|
|
|
|
firstItemFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drawItem = drawItem->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
sheet = GetNext();
|
|
|
|
|
|
|
|
if( sheet == NULL && aLastItem && aWrap && !hasWrapped )
|
|
|
|
{
|
|
|
|
hasWrapped = true;
|
|
|
|
sheet = GetFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFoundIn,
|
|
|
|
SCH_ITEM* aLastItem, bool aWrap )
|
|
|
|
{
|
|
|
|
bool hasWrapped = false;
|
|
|
|
bool firstItemFound = false;
|
|
|
|
SCH_ITEM* drawItem = NULL;
|
|
|
|
SCH_SHEET_PATH* sheet = GetLast();
|
|
|
|
|
|
|
|
while( sheet != NULL )
|
|
|
|
{
|
|
|
|
drawItem = sheet->FirstDrawList();
|
|
|
|
|
|
|
|
while( drawItem != NULL )
|
|
|
|
{
|
|
|
|
if( drawItem->Type() == aType )
|
|
|
|
{
|
|
|
|
if( aLastItem == NULL || firstItemFound )
|
|
|
|
{
|
|
|
|
if( aSheetFoundIn )
|
|
|
|
*aSheetFoundIn = sheet;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
return drawItem;
|
|
|
|
}
|
|
|
|
else if( !firstItemFound && drawItem == aLastItem )
|
|
|
|
{
|
|
|
|
firstItemFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drawItem = drawItem->Back();
|
|
|
|
}
|
|
|
|
|
|
|
|
sheet = GetPrevious();
|
|
|
|
|
|
|
|
if( sheet == NULL && aLastItem && aWrap && !hasWrapped )
|
|
|
|
{
|
|
|
|
hasWrapped = true;
|
|
|
|
sheet = GetLast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 18:23:01 +00:00
|
|
|
bool SCH_SHEET_LIST::SetComponentFootprint( const wxString& aReference,
|
|
|
|
const wxString& aFootPrint, bool aSetVisible )
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for( SCH_SHEET_PATH* path = GetFirst(); path != NULL; path = GetNext() )
|
|
|
|
found = path->SetComponentFootprint( aReference, aFootPrint, aSetVisible );
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|