2011-10-15 13:25:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-04-12 06:18:46 +00:00
|
|
|
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-10-06 18:07:43 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-01-04 20:39:50 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-15 13:25:57 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <sch_screen.h>
|
2019-05-10 19:57:24 +00:00
|
|
|
#include <sch_item.h>
|
2020-04-24 13:36:10 +00:00
|
|
|
#include <sch_marker.h>
|
2022-12-03 14:17:15 +00:00
|
|
|
#include <sch_label.h>
|
2015-02-21 08:11:58 +00:00
|
|
|
#include <sch_reference_list.h>
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_sheet.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <template_fieldnames.h>
|
2020-04-26 20:53:29 +00:00
|
|
|
#include <trace_helpers.h>
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <boost/functional/hash.hpp>
|
2015-06-07 20:31:55 +00:00
|
|
|
#include <wx/filename.h>
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A singleton item of this class is returned for a weak reference that no longer exists.
|
|
|
|
* Its sole purpose is to flag the item as having been deleted.
|
|
|
|
*/
|
|
|
|
class DELETED_SHEET_ITEM : public SCH_ITEM
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DELETED_SHEET_ITEM() :
|
|
|
|
SCH_ITEM( nullptr, NOT_USED )
|
|
|
|
{}
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
|
|
|
return _( "(Deleted Item)" );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetClass() const override
|
|
|
|
{
|
|
|
|
return wxT( "DELETED_SHEET_ITEM" );
|
|
|
|
}
|
|
|
|
|
2020-07-06 23:55:38 +00:00
|
|
|
static DELETED_SHEET_ITEM* GetInstance()
|
|
|
|
{
|
|
|
|
static DELETED_SHEET_ITEM* item = nullptr;
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
item = new DELETED_SHEET_ITEM();
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
// pure virtuals:
|
2022-01-01 06:04:08 +00:00
|
|
|
void SetPosition( const VECTOR2I& ) override {}
|
|
|
|
void Move( const VECTOR2I& aMoveVector ) override {}
|
2021-02-16 20:45:25 +00:00
|
|
|
void MirrorHorizontally( int aCenter ) override {}
|
|
|
|
void MirrorVertically( int aCenter ) override {}
|
2024-04-04 22:51:22 +00:00
|
|
|
void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override {}
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
double Similarity( const SCH_ITEM& aOther ) const override
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==( const SCH_ITEM& aOther ) const override
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void Show( int , std::ostream& ) const override {}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
size_t hash<SCH_SHEET_PATH>::operator()( const SCH_SHEET_PATH& path ) const
|
|
|
|
{
|
2019-04-09 03:27:04 +00:00
|
|
|
return path.GetCurrentHash();
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH::SCH_SHEET_PATH()
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2022-04-24 15:22:41 +00:00
|
|
|
m_virtualPageNumber = 1;
|
2019-04-09 03:27:04 +00:00
|
|
|
m_current_hash = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-08 21:42:05 +00:00
|
|
|
SCH_SHEET_PATH::SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther )
|
|
|
|
{
|
|
|
|
initFromOther( aOther );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_SHEET_PATH& SCH_SHEET_PATH::operator=( const SCH_SHEET_PATH& aOther )
|
|
|
|
{
|
|
|
|
initFromOther( aOther );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-08 16:05:27 +00:00
|
|
|
SCH_SHEET_PATH SCH_SHEET_PATH::operator+( const SCH_SHEET_PATH& aOther )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH retv = *this;
|
|
|
|
|
|
|
|
size_t size = aOther.size();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < size; i++ )
|
|
|
|
retv.push_back( aOther.at( i ) );
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-08 21:42:05 +00:00
|
|
|
void SCH_SHEET_PATH::initFromOther( const SCH_SHEET_PATH& aOther )
|
|
|
|
{
|
2024-06-06 10:40:24 +00:00
|
|
|
m_sheets = aOther.m_sheets;
|
|
|
|
m_virtualPageNumber = aOther.m_virtualPageNumber;
|
|
|
|
m_current_hash = aOther.m_current_hash;
|
|
|
|
m_cached_page_number = aOther.m_cached_page_number;
|
2020-07-08 21:42:05 +00:00
|
|
|
|
2024-06-03 10:11:04 +00:00
|
|
|
// Note: don't copy m_recursion_test_cache as it is slow and we want std::vector<SCH_SHEET_PATH> to be
|
2020-07-08 21:42:05 +00:00
|
|
|
// very fast to construct for use in the connectivity algorithm.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-08 18:36:23 +00:00
|
|
|
bool SCH_SHEET_PATH::IsFullPath() const
|
|
|
|
{
|
2022-11-22 19:35:27 +00:00
|
|
|
// The root sheet path is empty. All other sheet paths must start with the root sheet path.
|
|
|
|
return ( m_sheets.size() == 0 ) || ( GetSheet( 0 )->IsRootSheet() );
|
2021-12-08 18:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-09 03:27:04 +00:00
|
|
|
void SCH_SHEET_PATH::Rehash()
|
|
|
|
{
|
|
|
|
m_current_hash = 0;
|
|
|
|
|
2022-07-29 21:02:35 +00:00
|
|
|
for( SCH_SHEET* sheet : m_sheets )
|
2020-02-20 12:11:04 +00:00
|
|
|
boost::hash_combine( m_current_hash, sheet->m_Uuid.Hash() );
|
2009-01-07 20:09:03 +00:00
|
|
|
}
|
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
|
|
|
{
|
2016-02-27 19:35:45 +00:00
|
|
|
if( size() > aSheetPathToTest.size() )
|
2009-01-04 18:52:57 +00:00
|
|
|
return 1;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2016-02-27 19:35:45 +00:00
|
|
|
if( size() < aSheetPathToTest.size() )
|
2009-01-04 18:52:57 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-01-23 21:22:42 +00:00
|
|
|
//otherwise, same number of sheets.
|
2016-02-27 19:35:45 +00:00
|
|
|
for( unsigned i = 0; i < size(); i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
if( at( i )->m_Uuid < aSheetPathToTest.at( i )->m_Uuid )
|
2009-01-04 18:52:57 +00:00
|
|
|
return -1;
|
2020-02-20 12:11:04 +00:00
|
|
|
|
|
|
|
if( at( i )->m_Uuid != aSheetPathToTest.at( i )->m_Uuid )
|
|
|
|
return 1;
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-02 23:20:01 +00:00
|
|
|
int SCH_SHEET_PATH::ComparePageNum( const SCH_SHEET_PATH& aSheetPathToTest ) const
|
2021-04-11 15:24:11 +00:00
|
|
|
{
|
2022-11-22 19:35:27 +00:00
|
|
|
wxString pageA = this->GetPageNumber();
|
2021-12-06 12:47:18 +00:00
|
|
|
wxString pageB = aSheetPathToTest.GetPageNumber();
|
2021-04-11 15:24:11 +00:00
|
|
|
|
|
|
|
int pageNumComp = SCH_SHEET::ComparePageNum( pageA, pageB );
|
|
|
|
|
|
|
|
if( pageNumComp == 0 )
|
|
|
|
{
|
2022-01-01 18:21:37 +00:00
|
|
|
int virtualPageA = GetVirtualPageNumber();
|
|
|
|
int virtualPageB = aSheetPathToTest.GetVirtualPageNumber();
|
2021-04-11 15:24:11 +00:00
|
|
|
|
2022-01-24 18:37:54 +00:00
|
|
|
if( virtualPageA > virtualPageB )
|
|
|
|
pageNumComp = 1;
|
|
|
|
else if( virtualPageA < virtualPageB )
|
|
|
|
pageNumComp = -1;
|
2021-04-11 15:24:11 +00:00
|
|
|
}
|
2022-01-24 18:37:54 +00:00
|
|
|
|
|
|
|
return pageNumComp;
|
2021-04-11 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
bool SCH_SHEET_PATH::IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) const
|
|
|
|
{
|
|
|
|
if( aSheetPathToTest.size() > size() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < aSheetPathToTest.size(); ++i )
|
|
|
|
{
|
|
|
|
if( at( i )->m_Uuid != aSheetPathToTest.at( i )->m_Uuid )
|
2022-04-08 16:05:27 +00:00
|
|
|
{
|
|
|
|
wxLogTrace( traceSchSheetPaths, "Sheet path '%s' is not within path '%s'.",
|
|
|
|
aSheetPathToTest.Path().AsString(), Path().AsString() );
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
return false;
|
2022-04-08 16:05:27 +00:00
|
|
|
}
|
2021-05-01 22:56:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-08 16:05:27 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, "Sheet path '%s' is within path '%s'.",
|
|
|
|
aSheetPathToTest.Path().AsString(), Path().AsString() );
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-30 19:16:22 +00:00
|
|
|
SCH_SHEET* SCH_SHEET_PATH::Last() const
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2016-02-27 19:35:45 +00:00
|
|
|
if( !empty() )
|
2019-06-25 23:39:58 +00:00
|
|
|
return m_sheets.back();
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
return nullptr;
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +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
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
return nullptr;
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_SCREEN* SCH_SHEET_PATH::LastScreen() const
|
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
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( lastSheet )
|
|
|
|
return lastSheet->GetScreen();
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
return nullptr;
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-02 21:26:49 +00:00
|
|
|
bool SCH_SHEET_PATH::GetExcludedFromSim() const
|
|
|
|
{
|
|
|
|
for( SCH_SHEET* sheet : m_sheets )
|
|
|
|
{
|
|
|
|
if( sheet->GetExcludedFromSim() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SHEET_PATH::GetExcludedFromBOM() const
|
|
|
|
{
|
|
|
|
for( SCH_SHEET* sheet : m_sheets )
|
|
|
|
{
|
|
|
|
if( sheet->GetExcludedFromBOM() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SHEET_PATH::GetExcludedFromBoard() const
|
|
|
|
{
|
|
|
|
for( SCH_SHEET* sheet : m_sheets )
|
|
|
|
{
|
|
|
|
if( sheet->GetExcludedFromBoard() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SHEET_PATH::GetDNP() const
|
|
|
|
{
|
|
|
|
for( SCH_SHEET* sheet : m_sheets )
|
|
|
|
{
|
|
|
|
if( sheet->GetDNP() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
wxString SCH_SHEET_PATH::PathAsString() const
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
wxString s;
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
s = wxT( "/" ); // This is the root path
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2019-06-17 15:59:39 +00:00
|
|
|
// Start at 1 to avoid the root sheet, which does not need to be added to the path.
|
Fix source comment/doc typos (follow-up)
Found via `codespell -q 3 -S *.po,./thirdparty -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,dout,einstance,modul,ot,overide,serie,te,,tesselate,tesselator,tht`
2021-07-03 22:37:31 +00:00
|
|
|
// Its timestamp changes anyway.
|
2016-02-27 19:35:45 +00:00
|
|
|
for( unsigned i = 1; i < size(); i++ )
|
2020-02-21 23:18:43 +00:00
|
|
|
s += at( i )->m_Uuid.AsString() + "/";
|
2009-01-04 18:52:57 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH SCH_SHEET_PATH::Path() const
|
|
|
|
{
|
|
|
|
KIID_PATH path;
|
2024-06-06 10:40:24 +00:00
|
|
|
path.reserve( m_sheets.size() );
|
2020-02-22 21:39:59 +00:00
|
|
|
|
|
|
|
for( const SCH_SHEET* sheet : m_sheets )
|
|
|
|
path.push_back( sheet->m_Uuid );
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-12 11:00:18 +00:00
|
|
|
wxString SCH_SHEET_PATH::PathHumanReadable( bool aUseShortRootName,
|
|
|
|
bool aStripTrailingSeparator ) const
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2015-11-03 19:44:05 +00:00
|
|
|
wxString s;
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2020-10-27 19:57:56 +00:00
|
|
|
if( aUseShortRootName )
|
2022-07-09 22:30:52 +00:00
|
|
|
{
|
2022-09-22 17:04:17 +00:00
|
|
|
s = wxS( "/" ); // Use only the short name in netlists
|
2022-07-09 22:30:52 +00:00
|
|
|
}
|
2020-10-27 19:57:56 +00:00
|
|
|
else
|
2022-07-09 22:30:52 +00:00
|
|
|
{
|
2022-09-22 17:04:17 +00:00
|
|
|
wxString fileName;
|
|
|
|
|
|
|
|
if( !empty() && at( 0 )->GetScreen() )
|
|
|
|
fileName = at( 0 )->GetScreen()->GetFileName();
|
|
|
|
|
2022-07-09 22:30:52 +00:00
|
|
|
wxFileName fn = fileName;
|
|
|
|
|
2022-09-22 17:04:17 +00:00
|
|
|
s = fn.GetName() + wxS( "/" );
|
2022-07-09 22:30:52 +00:00
|
|
|
}
|
2019-06-17 15:59:39 +00:00
|
|
|
|
2020-10-24 22:29:29 +00:00
|
|
|
// Start at 1 since we've already processed the root sheet.
|
2016-02-27 19:35:45 +00:00
|
|
|
for( unsigned i = 1; i < size(); i++ )
|
2023-05-05 13:21:56 +00:00
|
|
|
s << at( i )->GetFields()[SHEETNAME].GetShownText( false ) << wxS( "/" );
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2022-12-12 11:00:18 +00:00
|
|
|
if( aStripTrailingSeparator && s.EndsWith( "/" ) )
|
|
|
|
s = s.Left( s.length() - 1 );
|
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
void SCH_SHEET_PATH::UpdateAllScreenReferences() const
|
2016-02-15 20:17:51 +00:00
|
|
|
{
|
2022-12-03 14:17:15 +00:00
|
|
|
std::vector<SCH_ITEM*> items;
|
2022-06-30 21:57:23 +00:00
|
|
|
|
2022-12-03 14:17:15 +00:00
|
|
|
std::copy_if( LastScreen()->Items().begin(), LastScreen()->Items().end(),
|
|
|
|
std::back_inserter( items ),
|
2022-06-30 21:57:23 +00:00
|
|
|
[]( SCH_ITEM* aItem )
|
|
|
|
{
|
2022-12-03 14:17:15 +00:00
|
|
|
return ( aItem->Type() == SCH_SYMBOL_T || aItem->Type() == SCH_GLOBAL_LABEL_T );
|
2022-06-30 21:57:23 +00:00
|
|
|
} );
|
|
|
|
|
2022-12-03 14:17:15 +00:00
|
|
|
for( SCH_ITEM* item : items )
|
2016-02-15 20:17:51 +00:00
|
|
|
{
|
2022-12-03 14:17:15 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
symbol->GetField( REFERENCE_FIELD )->SetText( symbol->GetRef( this ) );
|
2024-04-02 17:28:17 +00:00
|
|
|
symbol->SetUnit( symbol->GetUnitSelection( this ) );
|
2023-02-02 20:53:57 +00:00
|
|
|
LastScreen()->Update( item, false );
|
2022-12-03 14:17:15 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_GLOBAL_LABEL_T )
|
|
|
|
{
|
|
|
|
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( item );
|
|
|
|
|
2022-12-27 18:46:08 +00:00
|
|
|
if( label->GetFields().size() > 0 ) // Possible when reading a legacy .sch schematic
|
2022-12-04 20:06:16 +00:00
|
|
|
{
|
2022-12-27 18:46:08 +00:00
|
|
|
SCH_FIELD& intersheetRefs = label->GetFields()[0];
|
|
|
|
|
|
|
|
// Fixup for legacy files which didn't store a position for the intersheet refs
|
|
|
|
// unless they were shown.
|
|
|
|
if( label->GetFields().size() == 1
|
|
|
|
&& intersheetRefs.GetInternalName() == wxT( "Intersheet References" )
|
|
|
|
&& intersheetRefs.GetPosition() == VECTOR2I( 0, 0 )
|
|
|
|
&& !intersheetRefs.IsVisible() )
|
|
|
|
{
|
|
|
|
label->AutoplaceFields( LastScreen(), false );
|
|
|
|
}
|
2022-12-04 20:06:16 +00:00
|
|
|
|
|
|
|
intersheetRefs.SetVisible( label->Schematic()->Settings().m_IntersheetRefsShow );
|
|
|
|
LastScreen()->Update( &intersheetRefs );
|
|
|
|
}
|
2022-12-03 14:17:15 +00:00
|
|
|
}
|
2016-02-15 20:17:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-12 17:27:17 +00:00
|
|
|
|
|
|
|
void SCH_SHEET_PATH::GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols,
|
|
|
|
bool aForceIncludeOrphanSymbols ) const
|
2016-02-15 20:16:54 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
2016-02-15 20:16:54 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2024-06-12 17:27:17 +00:00
|
|
|
AppendSymbol( aReferences, symbol, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
|
2021-04-27 21:00:48 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-15 20:16:54 +00:00
|
|
|
|
2016-02-27 19:35:45 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SHEET_PATH::AppendSymbol( SCH_REFERENCE_LIST& aReferences, SCH_SYMBOL* aSymbol,
|
2024-06-12 17:27:17 +00:00
|
|
|
bool aIncludePowerSymbols,
|
|
|
|
bool aForceIncludeOrphanSymbols ) const
|
2021-04-27 21:00:48 +00:00
|
|
|
{
|
|
|
|
// Skip pseudo-symbols, which have a reference starting with #. This mainly
|
|
|
|
// affects power symbols.
|
|
|
|
if( aIncludePowerSymbols || aSymbol->GetRef( this )[0] != wxT( '#' ) )
|
|
|
|
{
|
2024-06-12 17:27:17 +00:00
|
|
|
if( aSymbol->GetLibSymbolRef() || aForceIncludeOrphanSymbols )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE schReference( aSymbol, *this );
|
2016-06-24 10:55:54 +00:00
|
|
|
|
2024-06-12 17:27:17 +00:00
|
|
|
schReference.SetSheetNumber( m_virtualPageNumber );
|
|
|
|
aReferences.AddItem( schReference );
|
|
|
|
}
|
2016-02-15 20:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-15 20:14:48 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
void SCH_SHEET_PATH::GetMultiUnitSymbols( SCH_MULTI_UNIT_REFERENCE_MAP& aRefList,
|
|
|
|
bool aIncludePowerSymbols ) const
|
2016-02-27 19:35:45 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
2016-02-15 20:14:48 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2021-04-27 21:00:48 +00:00
|
|
|
AppendMultiUnitSymbol( aRefList, symbol, aIncludePowerSymbols );
|
|
|
|
}
|
|
|
|
}
|
2016-02-15 20:14:48 +00:00
|
|
|
|
|
|
|
|
2021-04-27 21:00:48 +00:00
|
|
|
void SCH_SHEET_PATH::AppendMultiUnitSymbol( SCH_MULTI_UNIT_REFERENCE_MAP& aRefList,
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* aSymbol,
|
2021-04-27 21:00:48 +00:00
|
|
|
bool aIncludePowerSymbols ) const
|
|
|
|
{
|
|
|
|
// Skip pseudo-symbols, which have a reference starting with #. This mainly
|
|
|
|
// affects power symbols.
|
|
|
|
if( !aIncludePowerSymbols && aSymbol->GetRef( this )[0] == wxT( '#' ) )
|
|
|
|
return;
|
2016-02-27 19:35:45 +00:00
|
|
|
|
2024-06-12 17:27:17 +00:00
|
|
|
LIB_SYMBOL* symbol = aSymbol->GetLibSymbolRef().get();
|
|
|
|
|
|
|
|
if( symbol && symbol->GetUnitCount() > 1 )
|
2021-04-27 21:00:48 +00:00
|
|
|
{
|
2024-06-03 19:41:35 +00:00
|
|
|
SCH_REFERENCE schReference = SCH_REFERENCE( aSymbol, *this );
|
2021-04-27 21:00:48 +00:00
|
|
|
schReference.SetSheetNumber( m_virtualPageNumber );
|
|
|
|
wxString reference_str = schReference.GetRef();
|
2016-02-15 20:14:48 +00:00
|
|
|
|
2021-04-27 21:00:48 +00:00
|
|
|
// Never lock unassigned references
|
|
|
|
if( reference_str[reference_str.Len() - 1] == '?' )
|
|
|
|
return;
|
2016-02-15 20:14:48 +00:00
|
|
|
|
2021-04-27 21:00:48 +00:00
|
|
|
aRefList[reference_str].AddItem( schReference );
|
2016-02-15 20:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-08 16:05:27 +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
|
|
|
{
|
2019-04-09 03:27:04 +00:00
|
|
|
return m_current_hash == d1.GetCurrentHash();
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 04:03:04 +00:00
|
|
|
bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName )
|
2016-02-15 20:12:42 +00:00
|
|
|
{
|
2020-02-29 04:03:04 +00:00
|
|
|
auto pair = std::make_pair( aSrcFileName, aDestFileName );
|
|
|
|
|
|
|
|
if( m_recursion_test_cache.count( pair ) )
|
|
|
|
return m_recursion_test_cache.at( pair );
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCHEMATIC* sch = LastScreen()->Schematic();
|
|
|
|
|
|
|
|
wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_PATH::TestForRecursion!" );
|
|
|
|
|
|
|
|
wxFileName rootFn = sch->GetFileName();
|
2016-02-15 20:12:42 +00:00
|
|
|
wxFileName srcFn = aSrcFileName;
|
|
|
|
wxFileName destFn = aDestFileName;
|
|
|
|
|
|
|
|
if( srcFn.IsRelative() )
|
|
|
|
srcFn.MakeAbsolute( rootFn.GetPath() );
|
|
|
|
|
|
|
|
if( destFn.IsRelative() )
|
|
|
|
destFn.MakeAbsolute( rootFn.GetPath() );
|
|
|
|
|
|
|
|
// The source and destination sheet file names cannot be the same.
|
|
|
|
if( srcFn == destFn )
|
2020-02-29 04:03:04 +00:00
|
|
|
{
|
|
|
|
m_recursion_test_cache[pair] = true;
|
2016-02-15 20:12:42 +00:00
|
|
|
return true;
|
2020-02-29 04:03:04 +00:00
|
|
|
}
|
2016-02-15 20:12:42 +00:00
|
|
|
|
|
|
|
/// @todo Store sheet file names with full path, either relative to project path
|
|
|
|
/// or absolute path. The current design always assumes subsheet files are
|
|
|
|
/// located in the project folder which may or may not be desirable.
|
|
|
|
unsigned i = 0;
|
|
|
|
|
2016-02-27 19:35:45 +00:00
|
|
|
while( i < size() )
|
2016-02-15 20:12:42 +00:00
|
|
|
{
|
2016-02-27 19:35:45 +00:00
|
|
|
wxFileName cmpFn = at( i )->GetFileName();
|
2016-02-15 20:12:42 +00:00
|
|
|
|
|
|
|
if( cmpFn.IsRelative() )
|
|
|
|
cmpFn.MakeAbsolute( rootFn.GetPath() );
|
|
|
|
|
|
|
|
// Test if the file name of the destination sheet is in anywhere in this sheet path.
|
|
|
|
if( cmpFn == destFn )
|
|
|
|
break;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2016-02-27 19:35:45 +00:00
|
|
|
if( i >= size() || i == 0 )
|
2020-02-29 04:03:04 +00:00
|
|
|
{
|
|
|
|
m_recursion_test_cache[pair] = false;
|
2016-02-15 20:12:42 +00:00
|
|
|
return false;
|
2020-02-29 04:03:04 +00:00
|
|
|
}
|
2016-02-15 20:12:42 +00:00
|
|
|
|
|
|
|
// Walk back up to the root sheet to see if the source file name is already a parent in
|
|
|
|
// the sheet path. If so, recursion will occur.
|
|
|
|
do
|
|
|
|
{
|
|
|
|
i -= 1;
|
|
|
|
|
2016-02-27 19:35:45 +00:00
|
|
|
wxFileName cmpFn = at( i )->GetFileName();
|
2016-02-15 20:12:42 +00:00
|
|
|
|
|
|
|
if( cmpFn.IsRelative() )
|
|
|
|
cmpFn.MakeAbsolute( rootFn.GetPath() );
|
|
|
|
|
|
|
|
if( cmpFn == srcFn )
|
2020-02-29 04:03:04 +00:00
|
|
|
{
|
|
|
|
m_recursion_test_cache[pair] = true;
|
2016-02-15 20:12:42 +00:00
|
|
|
return true;
|
2020-02-29 04:03:04 +00:00
|
|
|
}
|
2016-02-15 20:12:42 +00:00
|
|
|
|
|
|
|
} while( i != 0 );
|
|
|
|
|
|
|
|
// The source sheet file name is not a parent of the destination sheet file name.
|
2020-02-29 04:03:04 +00:00
|
|
|
m_recursion_test_cache[pair] = false;
|
2016-02-15 20:12:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-06 12:47:18 +00:00
|
|
|
wxString SCH_SHEET_PATH::GetPageNumber() const
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = Last();
|
|
|
|
|
|
|
|
wxCHECK( sheet, wxEmptyString );
|
|
|
|
|
2024-06-06 10:40:24 +00:00
|
|
|
KIID_PATH tmpPath = Path();
|
2022-11-22 19:35:27 +00:00
|
|
|
tmpPath.pop_back();
|
|
|
|
|
|
|
|
return sheet->getPageNumber( tmpPath );
|
2021-12-06 12:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHEET_PATH::SetPageNumber( const wxString& aPageNumber )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = Last();
|
|
|
|
|
|
|
|
wxCHECK( sheet, /* void */ );
|
|
|
|
|
2024-06-06 10:40:24 +00:00
|
|
|
KIID_PATH tmpPath = Path();
|
2022-11-22 19:35:27 +00:00
|
|
|
|
|
|
|
tmpPath.pop_back();
|
|
|
|
|
2022-12-25 16:04:45 +00:00
|
|
|
sheet->addInstance( tmpPath );
|
2022-11-22 19:35:27 +00:00
|
|
|
sheet->setPageNumber( tmpPath, aPageNumber );
|
2021-12-06 12:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-19 18:33:22 +00:00
|
|
|
void SCH_SHEET_PATH::AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
|
|
|
|
const wxString& aProjectName )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
2024-04-19 18:33:22 +00:00
|
|
|
wxCHECK( !aProjectName.IsEmpty(), /* void */ );
|
|
|
|
|
2022-12-25 16:04:45 +00:00
|
|
|
SCH_SHEET_PATH newSheetPath( aPrefixSheetPath );
|
|
|
|
SCH_SHEET_PATH currentSheetPath( *this );
|
|
|
|
|
|
|
|
// Prefix the new hierarchical path.
|
|
|
|
newSheetPath = newSheetPath + currentSheetPath;
|
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
wxCHECK2( symbol, continue );
|
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
SCH_SYMBOL_INSTANCE newSymbolInstance;
|
2022-10-01 12:44:21 +00:00
|
|
|
|
2022-12-25 16:04:45 +00:00
|
|
|
if( symbol->GetInstance( newSymbolInstance, Path(), true ) )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
2024-04-19 18:33:22 +00:00
|
|
|
newSymbolInstance.m_ProjectName = aProjectName;
|
2022-10-01 12:44:21 +00:00
|
|
|
// Use an existing symbol instance for this path if it exists.
|
2024-04-19 18:33:22 +00:00
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
newSymbolInstance.m_Path = newSheetPath.Path();
|
|
|
|
symbol->AddHierarchicalReference( newSymbolInstance );
|
|
|
|
}
|
2023-12-28 23:25:47 +00:00
|
|
|
else if( !symbol->GetInstances().empty() )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
2024-04-19 18:33:22 +00:00
|
|
|
newSymbolInstance.m_ProjectName = aProjectName;
|
|
|
|
|
2022-12-25 16:04:45 +00:00
|
|
|
// Use the first symbol instance if any symbol instance data exists.
|
2023-12-28 23:25:47 +00:00
|
|
|
newSymbolInstance = symbol->GetInstances()[0];
|
2022-10-01 12:44:21 +00:00
|
|
|
newSymbolInstance.m_Path = newSheetPath.Path();
|
|
|
|
symbol->AddHierarchicalReference( newSymbolInstance );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-19 18:33:22 +00:00
|
|
|
newSymbolInstance.m_ProjectName = aProjectName;
|
|
|
|
|
2022-12-25 16:04:45 +00:00
|
|
|
// Fall back to the last saved symbol field and unit settings if there is no
|
|
|
|
// instance data.
|
|
|
|
newSymbolInstance.m_Path = newSheetPath.Path();
|
|
|
|
newSymbolInstance.m_Reference = symbol->GetField( REFERENCE_FIELD )->GetText();
|
|
|
|
newSymbolInstance.m_Unit = symbol->GetUnit();
|
2022-10-01 12:44:21 +00:00
|
|
|
symbol->AddHierarchicalReference( newSymbolInstance );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHEET_PATH::RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
wxCHECK2( symbol, continue );
|
|
|
|
|
|
|
|
SCH_SHEET_PATH fullSheetPath( aPrefixSheetPath );
|
|
|
|
SCH_SHEET_PATH currentSheetPath( *this );
|
|
|
|
|
|
|
|
// Prefix the hierarchical path of the symbol instance to be removed.
|
|
|
|
fullSheetPath = fullSheetPath + currentSheetPath;
|
|
|
|
symbol->RemoveInstance( fullSheetPath );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-27 20:01:36 +00:00
|
|
|
void SCH_SHEET_PATH::MakeFilePathRelativeToParentSheet()
|
|
|
|
{
|
|
|
|
wxCHECK( m_sheets.size() > 1, /* void */ );
|
|
|
|
|
|
|
|
wxFileName sheetFileName = Last()->GetFileName();
|
|
|
|
|
|
|
|
// If the sheet file name is absolute, then the user requested is so don't make it relative.
|
|
|
|
if( sheetFileName.IsAbsolute() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SCH_SCREEN* screen = LastScreen();
|
|
|
|
SCH_SCREEN* parentScreen = m_sheets[ m_sheets.size() - 2 ]->GetScreen();
|
|
|
|
|
|
|
|
wxCHECK( screen && parentScreen, /* void */ );
|
|
|
|
|
|
|
|
wxFileName fileName = screen->GetFileName();
|
|
|
|
wxFileName parentFileName = parentScreen->GetFileName();
|
|
|
|
|
|
|
|
// SCH_SCREEN file names must be absolute. If they are not, someone set them incorrectly
|
|
|
|
// on load or on creation.
|
|
|
|
wxCHECK( fileName.IsAbsolute() && parentFileName.IsAbsolute(), /* void */ );
|
|
|
|
|
|
|
|
if( fileName.GetPath() == parentFileName.GetPath() )
|
|
|
|
{
|
|
|
|
Last()->SetFileName( fileName.GetFullName() );
|
|
|
|
}
|
|
|
|
else if( fileName.MakeRelativeTo( parentFileName.GetPath() ) )
|
|
|
|
{
|
|
|
|
Last()->SetFileName( fileName.GetFullPath() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Last()->SetFileName( screen->GetFileName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxLogTrace( tracePathsAndFiles,
|
|
|
|
wxT( "\n File name: '%s'"
|
|
|
|
"\n parent file name '%s',"
|
|
|
|
"\n sheet '%s' file name '%s'." ),
|
|
|
|
screen->GetFileName(), parentScreen->GetFileName(), PathHumanReadable(),
|
|
|
|
Last()->GetFileName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-06 16:58:48 +00:00
|
|
|
SCH_SHEET_LIST::SCH_SHEET_LIST( SCH_SHEET* aSheet )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2021-05-27 20:01:36 +00:00
|
|
|
if( aSheet != nullptr )
|
2024-06-06 16:58:48 +00:00
|
|
|
BuildSheetList( aSheet, false );
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-05 12:24:21 +00:00
|
|
|
void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2021-05-27 20:01:36 +00:00
|
|
|
wxCHECK_RET( aSheet != nullptr, wxT( "Cannot build sheet list from undefined sheet." ) );
|
2014-08-23 15:22:50 +00:00
|
|
|
|
2020-01-27 14:38:14 +00:00
|
|
|
std::vector<SCH_SHEET*> badSheets;
|
|
|
|
|
2016-03-06 21:22:01 +00:00
|
|
|
m_currentSheetPath.push_back( aSheet );
|
2020-10-26 17:01:20 +00:00
|
|
|
m_currentSheetPath.SetVirtualPageNumber( static_cast<int>( size() ) + 1 );
|
2016-03-06 21:22:01 +00:00
|
|
|
push_back( m_currentSheetPath );
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( m_currentSheetPath.LastScreen() )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2020-10-05 12:24:21 +00:00
|
|
|
wxString parentFileName = aSheet->GetFileName();
|
2020-05-03 14:52:31 +00:00
|
|
|
std::vector<SCH_ITEM*> childSheets;
|
|
|
|
m_currentSheetPath.LastScreen()->GetSheets( &childSheets );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : childSheets )
|
2020-01-27 14:38:14 +00:00
|
|
|
{
|
2020-10-05 12:24:21 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
2020-01-27 14:38:14 +00:00
|
|
|
|
2020-10-05 12:24:21 +00:00
|
|
|
if( aCheckIntegrity )
|
|
|
|
{
|
|
|
|
if( !m_currentSheetPath.TestForRecursion( sheet->GetFileName(), parentFileName ) )
|
|
|
|
BuildSheetList( sheet, true );
|
|
|
|
else
|
|
|
|
badSheets.push_back( sheet );
|
|
|
|
}
|
2020-01-27 14:38:14 +00:00
|
|
|
else
|
2020-10-05 12:24:21 +00:00
|
|
|
{
|
2023-11-26 21:43:06 +00:00
|
|
|
// If we are not performing a full recursion test, at least check if we are in
|
|
|
|
// a simple recursion scenario to prevent stack overflow crashes
|
|
|
|
wxCHECK2_MSG( sheet->GetFileName() != aSheet->GetFileName(), continue,
|
|
|
|
wxT( "Recursion prevented in SCH_SHEET_LIST::BuildSheetList" ) );
|
|
|
|
|
2020-10-05 12:24:21 +00:00
|
|
|
BuildSheetList( sheet, false );
|
|
|
|
}
|
2020-01-27 14:38:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 12:24:21 +00:00
|
|
|
if( aCheckIntegrity )
|
2020-01-27 14:38:14 +00:00
|
|
|
{
|
2020-10-05 12:24:21 +00:00
|
|
|
for( SCH_SHEET* sheet : badSheets )
|
|
|
|
{
|
|
|
|
m_currentSheetPath.LastScreen()->Remove( sheet );
|
2021-05-28 19:07:04 +00:00
|
|
|
m_currentSheetPath.LastScreen()->SetContentModified();
|
2020-10-05 12:24:21 +00:00
|
|
|
}
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2016-03-06 21:22:01 +00:00
|
|
|
m_currentSheetPath.pop_back();
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
|
|
|
|
2020-11-29 18:30:58 +00:00
|
|
|
void SCH_SHEET_LIST::SortByPageNumbers( bool aUpdateVirtualPageNums )
|
|
|
|
{
|
2024-06-06 10:40:24 +00:00
|
|
|
for( const SCH_SHEET_PATH& path : *this )
|
|
|
|
path.CachePageNumber();
|
|
|
|
|
2021-03-22 20:55:44 +00:00
|
|
|
std::sort( begin(), end(),
|
2024-06-06 10:40:24 +00:00
|
|
|
[]( const SCH_SHEET_PATH& a, const SCH_SHEET_PATH& b ) -> bool
|
2020-11-29 18:30:58 +00:00
|
|
|
{
|
2024-06-06 10:40:24 +00:00
|
|
|
int retval = SCH_SHEET::ComparePageNum( a.GetCachedPageNumber(),
|
|
|
|
b.GetCachedPageNumber() );
|
2022-11-20 13:10:52 +00:00
|
|
|
|
|
|
|
if( retval < 0 )
|
|
|
|
return true;
|
|
|
|
else if( retval > 0 )
|
|
|
|
return false;
|
2024-06-06 10:40:24 +00:00
|
|
|
|
|
|
|
if( a.GetVirtualPageNumber() < b.GetVirtualPageNumber() )
|
|
|
|
return true;
|
|
|
|
else if( a.GetVirtualPageNumber() > b.GetVirtualPageNumber() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/// Enforce strict ordering. If the page numbers are the same, use UUIDs
|
|
|
|
return a.GetCurrentHash() < b.GetCurrentHash();
|
2020-11-29 18:30:58 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if( aUpdateVirtualPageNums )
|
|
|
|
{
|
|
|
|
int virtualPageNum = 1;
|
|
|
|
|
|
|
|
for( SCH_SHEET_PATH& sheet : *this )
|
|
|
|
sheet.SetVirtualPageNumber( virtualPageNum++ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
bool SCH_SHEET_LIST::NameExists( const wxString& aSheetName ) const
|
2020-03-13 09:53:44 +00:00
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
|
|
|
{
|
|
|
|
if( sheet.Last()->GetName() == aSheetName )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-22 20:55:44 +00:00
|
|
|
bool SCH_SHEET_LIST::PageNumberExists( const wxString& aPageNumber ) const
|
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
|
|
|
{
|
2021-12-06 12:47:18 +00:00
|
|
|
if( sheet.GetPageNumber() == aPageNumber )
|
2021-03-22 20:55:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-03 13:17:51 +00:00
|
|
|
void SCH_SHEET_LIST::TrimToPageNumbers( const std::vector<wxString>& aPageInclusions )
|
|
|
|
{
|
|
|
|
auto it = std::remove_if( begin(), end(),
|
|
|
|
[&]( SCH_SHEET_PATH sheet )
|
|
|
|
{
|
|
|
|
return std::find( aPageInclusions.begin(), aPageInclusions.end(),
|
|
|
|
sheet.GetPageNumber() )
|
|
|
|
== aPageInclusions.end();
|
|
|
|
} );
|
|
|
|
|
|
|
|
erase( it, end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
bool SCH_SHEET_LIST::IsModified() const
|
2016-02-15 20:21:18 +00:00
|
|
|
{
|
2020-03-13 09:53:44 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
2016-02-15 20:21:18 +00:00
|
|
|
{
|
2021-05-28 19:07:04 +00:00
|
|
|
if( sheet.LastScreen() && sheet.LastScreen()->IsContentModified() )
|
2016-02-15 20:21:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHEET_LIST::ClearModifyStatus()
|
|
|
|
{
|
2020-03-13 09:53:44 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
2016-02-15 20:21:18 +00:00
|
|
|
{
|
2020-03-13 09:53:44 +00:00
|
|
|
if( sheet.LastScreen() )
|
2021-05-28 19:07:04 +00:00
|
|
|
sheet.LastScreen()->SetContentModified( false );
|
2016-02-15 20:21:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
SCH_ITEM* SCH_SHEET_LIST::GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut ) const
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
|
|
|
{
|
2022-12-23 22:02:59 +00:00
|
|
|
SCH_ITEM* item = sheet.GetItem( aID );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
if( item )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
2022-12-23 22:02:59 +00:00
|
|
|
if( aPathOut )
|
|
|
|
*aPathOut = sheet;
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
// Not found; weak reference has been deleted.
|
|
|
|
return DELETED_SHEET_ITEM::GetInstance();
|
|
|
|
}
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
SCH_ITEM* SCH_SHEET_PATH::GetItem( const KIID& aID ) const
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* aItem : LastScreen()->Items() )
|
|
|
|
{
|
|
|
|
if( aItem->m_Uuid == aID )
|
|
|
|
return aItem;
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
SCH_ITEM* childMatch = nullptr;
|
|
|
|
|
|
|
|
aItem->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aChild->m_Uuid == aID )
|
|
|
|
childMatch = aChild;
|
|
|
|
} );
|
|
|
|
|
|
|
|
if( childMatch )
|
|
|
|
return childMatch;
|
2020-03-16 11:05:01 +00:00
|
|
|
}
|
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
return nullptr;
|
2020-03-16 11:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 22:22:11 +00:00
|
|
|
void SCH_SHEET_LIST::FillItemMap( std::map<KIID, EDA_ITEM*>& aMap )
|
2020-04-24 13:36:10 +00:00
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
|
|
|
|
|
|
|
for( SCH_ITEM* aItem : screen->Items() )
|
|
|
|
{
|
|
|
|
aMap[ aItem->m_Uuid ] = aItem;
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
aItem->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
aMap[ aChild->m_Uuid ] = aChild;
|
|
|
|
} );
|
2020-04-24 13:36:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
void SCH_SHEET_LIST::AnnotatePowerSymbols()
|
2016-02-15 20:18:32 +00:00
|
|
|
{
|
2017-07-20 18:23:21 +00:00
|
|
|
// List of reference for power symbols
|
|
|
|
SCH_REFERENCE_LIST references;
|
2021-04-11 15:24:11 +00:00
|
|
|
SCH_REFERENCE_LIST additionalreferences; // Todo: add as a parameter to this function
|
2017-07-20 18:23:21 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
// Map of locked symbols (not used, but needed by Annotate()
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP lockedSymbols;
|
2016-02-15 20:18:32 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
// Build the list of power symbols:
|
2020-03-13 09:53:44 +00:00
|
|
|
for( SCH_SHEET_PATH& sheet : *this )
|
2017-07-20 18:23:21 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
2017-07-20 18:23:21 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2024-06-12 17:27:17 +00:00
|
|
|
LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
|
2017-07-20 18:23:21 +00:00
|
|
|
|
2024-06-12 17:27:17 +00:00
|
|
|
if( libSymbol && libSymbol->IsPower() )
|
2017-07-20 18:23:21 +00:00
|
|
|
{
|
2024-06-03 19:41:35 +00:00
|
|
|
SCH_REFERENCE schReference( symbol, sheet );
|
2018-06-28 13:36:14 +00:00
|
|
|
references.AddItem( schReference );
|
2017-07-20 18:23:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find duplicate, and silently clear annotation of duplicate
|
|
|
|
std::map<wxString, int> ref_list; // stores the existing references
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii< references.GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
wxString curr_ref = references[ii].GetRef();
|
|
|
|
|
|
|
|
if( ref_list.find( curr_ref ) == ref_list.end() )
|
|
|
|
{
|
|
|
|
ref_list[curr_ref] = ii;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Possible duplicate, if the ref ends by a number:
|
|
|
|
if( curr_ref.Last() < '0' && curr_ref.Last() > '9' )
|
|
|
|
continue; // not annotated
|
|
|
|
|
|
|
|
// Duplicate: clear annotation by removing the number ending the ref
|
|
|
|
while( curr_ref.Last() >= '0' && curr_ref.Last() <= '9' )
|
|
|
|
curr_ref.RemoveLast();
|
|
|
|
|
|
|
|
references[ii].SetRef( curr_ref );
|
|
|
|
}
|
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
// Break full symbol reference into name (prefix) and number:
|
2017-07-20 18:23:21 +00:00
|
|
|
// example: IC1 become IC, and 1
|
|
|
|
references.SplitReferences();
|
|
|
|
|
|
|
|
// Ensure all power symbols have the reference starting by '#'
|
2021-03-19 20:27:30 +00:00
|
|
|
// (Not sure this is really useful)
|
2017-07-20 18:23:21 +00:00
|
|
|
for( unsigned ii = 0; ii< references.GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
if( references[ii].GetRef()[0] != '#' )
|
|
|
|
{
|
|
|
|
wxString new_ref = "#" + references[ii].GetRef();
|
|
|
|
references[ii].SetRef( new_ref );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recalculate and update reference numbers in schematic
|
2021-04-11 15:24:11 +00:00
|
|
|
references.Annotate( false, 0, 100, lockedSymbols, additionalreferences );
|
2017-07-20 18:23:21 +00:00
|
|
|
references.UpdateAnnotation();
|
2016-02-15 20:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-12 17:27:17 +00:00
|
|
|
void SCH_SHEET_LIST::GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols,
|
|
|
|
bool aForceIncludeOrphanSymbols ) const
|
2016-02-15 20:16:54 +00:00
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
2024-06-12 17:27:17 +00:00
|
|
|
sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
|
2016-02-15 20:16:54 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
void SCH_SHEET_LIST::GetSymbolsWithinPath( SCH_REFERENCE_LIST& aReferences,
|
|
|
|
const SCH_SHEET_PATH& aSheetPath,
|
2024-06-12 17:27:17 +00:00
|
|
|
bool aIncludePowerSymbols,
|
|
|
|
bool aForceIncludeOrphanSymbols ) const
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
|
|
|
{
|
|
|
|
if( sheet.IsContainedWithin( aSheetPath ) )
|
2024-06-12 17:27:17 +00:00
|
|
|
sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
|
2021-05-01 22:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-03 10:11:04 +00:00
|
|
|
void SCH_SHEET_LIST::GetSheetsWithinPath( std::vector<SCH_SHEET_PATH>& aSheets,
|
2021-05-01 22:56:37 +00:00
|
|
|
const SCH_SHEET_PATH& aSheetPath ) const
|
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
|
|
|
{
|
|
|
|
if( sheet.IsContainedWithin( aSheetPath ) )
|
|
|
|
aSheets.push_back( sheet );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-25 16:04:45 +00:00
|
|
|
std::optional<SCH_SHEET_PATH> SCH_SHEET_LIST::GetSheetPathByKIIDPath( const KIID_PATH& aPath,
|
|
|
|
bool aIncludeLastSheet ) const
|
2022-07-19 15:00:35 +00:00
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& sheet : *this )
|
|
|
|
{
|
2022-12-25 16:04:45 +00:00
|
|
|
KIID_PATH testPath = sheet.Path();
|
|
|
|
|
|
|
|
if( !aIncludeLastSheet )
|
|
|
|
testPath.pop_back();
|
|
|
|
|
|
|
|
if( testPath == aPath )
|
2022-07-19 15:00:35 +00:00
|
|
|
return SCH_SHEET_PATH( sheet );
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
void SCH_SHEET_LIST::GetMultiUnitSymbols( SCH_MULTI_UNIT_REFERENCE_MAP &aRefList,
|
|
|
|
bool aIncludePowerSymbols ) const
|
2016-02-15 20:14:48 +00:00
|
|
|
{
|
2024-06-03 10:11:04 +00:00
|
|
|
for( auto it = begin(); it != end(); ++it )
|
2016-02-15 20:14:48 +00:00
|
|
|
{
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP tempMap;
|
2022-07-12 03:45:21 +00:00
|
|
|
( *it ).GetMultiUnitSymbols( tempMap, aIncludePowerSymbols );
|
2016-03-06 21:22:01 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
|
2016-02-15 20:14:48 +00:00
|
|
|
{
|
|
|
|
// Merge this list into the main one
|
|
|
|
unsigned n_refs = pair.second.GetCount();
|
2016-03-06 21:22:01 +00:00
|
|
|
|
2016-02-15 20:14:48 +00:00
|
|
|
for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
|
|
|
|
aRefList[pair.first].AddItem( pair.second[thisRef] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-15 20:12:42 +00:00
|
|
|
bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
|
2020-02-29 04:03:04 +00:00
|
|
|
const wxString& aDestFileName )
|
2016-02-15 20:12:42 +00:00
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
if( empty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SCHEMATIC* sch = at( 0 ).LastScreen()->Schematic();
|
|
|
|
|
|
|
|
wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_LIST::TestForRecursion!" );
|
|
|
|
|
|
|
|
wxFileName rootFn = sch->GetFileName();
|
2016-02-15 20:12:42 +00:00
|
|
|
wxFileName destFn = aDestFileName;
|
|
|
|
|
|
|
|
if( destFn.IsRelative() )
|
|
|
|
destFn.MakeAbsolute( rootFn.GetPath() );
|
|
|
|
|
|
|
|
// Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
|
2016-03-06 21:22:01 +00:00
|
|
|
for( unsigned i = 0; i < size(); i++ )
|
2016-02-15 20:12:42 +00:00
|
|
|
{
|
|
|
|
// Test each SCH_SHEET_PATH in the source sheet.
|
2016-03-06 21:22:01 +00:00
|
|
|
for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
|
2016-02-15 20:12:42 +00:00
|
|
|
{
|
2016-03-06 21:22:01 +00:00
|
|
|
const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j];
|
2016-02-15 20:12:42 +00:00
|
|
|
|
2016-02-27 19:35:45 +00:00
|
|
|
for( unsigned k = 0; k < sheetPath->size(); k++ )
|
2016-02-15 20:12:42 +00:00
|
|
|
{
|
2016-03-06 21:22:01 +00:00
|
|
|
if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
|
|
|
|
aDestFileName ) )
|
2021-03-19 20:27:30 +00:00
|
|
|
{
|
2016-02-15 20:12:42 +00:00
|
|
|
return true;
|
2021-03-19 20:27:30 +00:00
|
|
|
}
|
2016-02-15 20:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The source sheet file can safely be added to the destination sheet file.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-20 15:39:15 +00:00
|
|
|
SCH_SHEET_PATH* SCH_SHEET_LIST::FindSheetForPath( const SCH_SHEET_PATH* aPath )
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PATH& path : *this )
|
|
|
|
{
|
|
|
|
if( path.Path() == aPath->Path() )
|
|
|
|
return &path;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-27 18:02:12 +00:00
|
|
|
SCH_SHEET_PATH SCH_SHEET_LIST::FindSheetForScreen( const SCH_SCREEN* aScreen )
|
2019-05-19 21:04:04 +00:00
|
|
|
{
|
|
|
|
for( SCH_SHEET_PATH& sheetpath : *this )
|
|
|
|
{
|
|
|
|
if( sheetpath.LastScreen() == aScreen )
|
2023-08-27 18:02:12 +00:00
|
|
|
return sheetpath;
|
2019-05-19 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
2023-08-27 18:02:12 +00:00
|
|
|
return SCH_SHEET_PATH();
|
2019-05-19 21:04:04 +00:00
|
|
|
}
|
2020-04-24 13:36:10 +00:00
|
|
|
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
SCH_SHEET_LIST SCH_SHEET_LIST::FindAllSheetsForScreen( const SCH_SCREEN* aScreen ) const
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST retval;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& sheetpath : *this )
|
|
|
|
{
|
|
|
|
if( sheetpath.LastScreen() == aScreen )
|
|
|
|
retval.push_back( sheetpath );
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-06 14:00:11 +00:00
|
|
|
void SCH_SHEET_LIST::UpdateSymbolInstanceData(
|
2023-01-04 20:39:50 +00:00
|
|
|
const std::vector<SCH_SYMBOL_INSTANCE>& aSymbolInstances )
|
2020-04-26 20:53:29 +00:00
|
|
|
{
|
2022-10-01 12:44:21 +00:00
|
|
|
for( SCH_SHEET_PATH& sheetPath : *this )
|
2022-09-29 19:24:56 +00:00
|
|
|
{
|
2022-10-01 12:44:21 +00:00
|
|
|
for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2022-09-29 19:24:56 +00:00
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
wxCHECK2( symbol, continue );
|
2022-09-29 19:24:56 +00:00
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
KIID_PATH sheetPathWithSymbolUuid = sheetPath.Path();
|
|
|
|
sheetPathWithSymbolUuid.push_back( symbol->m_Uuid );
|
2022-09-29 19:24:56 +00:00
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
auto it = std::find_if( aSymbolInstances.begin(), aSymbolInstances.end(),
|
2023-01-04 20:39:50 +00:00
|
|
|
[ sheetPathWithSymbolUuid ]( const SCH_SYMBOL_INSTANCE& r ) -> bool
|
2022-12-06 14:00:11 +00:00
|
|
|
{
|
|
|
|
return sheetPathWithSymbolUuid == r.m_Path;
|
|
|
|
} );
|
2022-09-29 19:24:56 +00:00
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
if( it == aSymbolInstances.end() )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceSchSheetPaths, "No symbol instance found for symbol '%s'",
|
|
|
|
sheetPathWithSymbolUuid.AsString() );
|
|
|
|
continue;
|
|
|
|
}
|
2022-09-29 19:24:56 +00:00
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
// Symbol instance paths are stored and looked up in memory with the root path so use
|
|
|
|
// the full path here.
|
2022-11-25 14:25:39 +00:00
|
|
|
symbol->AddHierarchicalReference( sheetPath.Path(), it->m_Reference, it->m_Unit );
|
2022-10-01 12:44:21 +00:00
|
|
|
symbol->GetField( REFERENCE_FIELD )->SetText( it->m_Reference );
|
2023-02-03 14:48:00 +00:00
|
|
|
|
|
|
|
if( !it->m_Value.IsEmpty() )
|
|
|
|
symbol->SetValueFieldText( it->m_Value );
|
|
|
|
|
|
|
|
if( !it->m_Footprint.IsEmpty() )
|
|
|
|
symbol->SetFootprintFieldText( it->m_Footprint );
|
|
|
|
|
2022-12-07 01:34:10 +00:00
|
|
|
symbol->UpdatePrefix();
|
2022-10-01 12:44:21 +00:00
|
|
|
}
|
2020-04-26 20:53:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-06 14:00:11 +00:00
|
|
|
void SCH_SHEET_LIST::UpdateSheetInstanceData( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances )
|
2020-10-18 20:30:37 +00:00
|
|
|
{
|
|
|
|
|
2022-11-22 19:35:27 +00:00
|
|
|
for( SCH_SHEET_PATH& path : *this )
|
2020-10-18 20:30:37 +00:00
|
|
|
{
|
2021-12-08 18:36:23 +00:00
|
|
|
SCH_SHEET* sheet = path.Last();
|
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
wxCHECK2( sheet && path.Last(), continue );
|
2021-12-08 18:36:23 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
auto it = std::find_if( aSheetInstances.begin(), aSheetInstances.end(),
|
2021-12-08 18:36:23 +00:00
|
|
|
[ path ]( const SCH_SHEET_INSTANCE& r ) -> bool
|
2020-10-18 20:30:37 +00:00
|
|
|
{
|
2022-10-01 12:44:21 +00:00
|
|
|
return path.Path() == r.m_Path;
|
2020-10-18 20:30:37 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if( it == aSheetInstances.end() )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, "No sheet instance found for path '%s'",
|
2022-10-01 12:44:21 +00:00
|
|
|
path.Path().AsString() );
|
2020-10-18 20:30:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-12-08 18:36:23 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, "Setting sheet '%s' instance '%s' page number '%s'",
|
2023-02-12 21:29:26 +00:00
|
|
|
( sheet->GetName().IsEmpty() ) ? wxString( wxT( "root" ) ) : sheet->GetName(),
|
2022-10-01 12:44:21 +00:00
|
|
|
path.Path().AsString(), it->m_PageNumber );
|
2022-11-22 19:35:27 +00:00
|
|
|
path.SetPageNumber( it->m_PageNumber );
|
2020-10-18 20:30:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
std::vector<KIID_PATH> SCH_SHEET_LIST::GetPaths() const
|
|
|
|
{
|
|
|
|
std::vector<KIID_PATH> paths;
|
|
|
|
|
2020-09-06 10:28:58 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheetPath : *this )
|
2020-04-26 20:53:29 +00:00
|
|
|
paths.emplace_back( sheetPath.Path() );
|
|
|
|
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-12 19:08:02 +00:00
|
|
|
std::vector<SCH_SHEET_INSTANCE> SCH_SHEET_LIST::GetSheetInstances() const
|
|
|
|
{
|
|
|
|
std::vector<SCH_SHEET_INSTANCE> retval;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& path : *this )
|
|
|
|
{
|
|
|
|
const SCH_SHEET* sheet = path.Last();
|
|
|
|
|
|
|
|
wxCHECK2( sheet, continue );
|
|
|
|
|
2021-12-08 18:36:23 +00:00
|
|
|
SCH_SHEET_INSTANCE instance;
|
2022-11-22 19:35:27 +00:00
|
|
|
SCH_SHEET_PATH tmpPath = path;
|
|
|
|
|
|
|
|
tmpPath.pop_back();
|
|
|
|
instance.m_Path = tmpPath.Path();
|
|
|
|
instance.m_PageNumber = path.GetPageNumber();
|
2021-04-12 19:08:02 +00:00
|
|
|
|
|
|
|
retval.push_back( instance );
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
bool SCH_SHEET_LIST::AllSheetPageNumbersEmpty() const
|
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& instance : *this )
|
|
|
|
{
|
2022-11-22 19:35:27 +00:00
|
|
|
if( !instance.GetPageNumber().IsEmpty() )
|
2020-10-18 20:30:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHEET_LIST::SetInitialPageNumbers()
|
|
|
|
{
|
2021-06-09 19:32:58 +00:00
|
|
|
// Don't accidentally renumber existing sheets.
|
2020-10-18 20:30:37 +00:00
|
|
|
wxCHECK( AllSheetPageNumbersEmpty(), /* void */ );
|
|
|
|
|
|
|
|
wxString tmp;
|
|
|
|
int pageNumber = 1;
|
|
|
|
|
2022-11-22 19:35:27 +00:00
|
|
|
for( SCH_SHEET_PATH& instance : *this )
|
2020-10-18 20:30:37 +00:00
|
|
|
{
|
|
|
|
tmp.Printf( "%d", pageNumber );
|
2022-11-22 19:35:27 +00:00
|
|
|
instance.SetPageNumber( tmp );
|
2020-10-18 20:30:37 +00:00
|
|
|
pageNumber += 1;
|
|
|
|
}
|
|
|
|
}
|
2022-06-21 02:22:52 +00:00
|
|
|
|
|
|
|
|
2024-04-19 18:33:22 +00:00
|
|
|
void SCH_SHEET_LIST::AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
|
|
|
|
const wxString& aProjectName )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
|
|
|
for( SCH_SHEET_PATH& sheetPath : *this )
|
2024-04-19 18:33:22 +00:00
|
|
|
sheetPath.AddNewSymbolInstances( aPrefixSheetPath, aProjectName );
|
2022-10-01 12:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHEET_LIST::RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath )
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PATH& sheetPath : *this )
|
|
|
|
sheetPath.RemoveSymbolInstances( aPrefixSheetPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHEET_LIST::AddNewSheetInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
|
|
|
|
int aLastVirtualPageNumber )
|
|
|
|
{
|
2022-12-25 16:04:45 +00:00
|
|
|
wxString pageNumber;
|
|
|
|
int lastUsedPageNumber = 1;
|
|
|
|
int nextVirtualPageNumber = aLastVirtualPageNumber;
|
|
|
|
|
|
|
|
// Fetch the list of page numbers already in use.
|
|
|
|
std::vector< wxString > usedPageNumbers;
|
|
|
|
|
|
|
|
if( aPrefixSheetPath.size() )
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST prefixHierarchy( aPrefixSheetPath.at( 0 ) );
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& path : prefixHierarchy )
|
|
|
|
{
|
|
|
|
pageNumber = path.GetPageNumber();
|
|
|
|
|
|
|
|
if( !pageNumber.IsEmpty() )
|
|
|
|
usedPageNumbers.emplace_back( pageNumber );
|
|
|
|
}
|
|
|
|
}
|
2022-10-01 12:44:21 +00:00
|
|
|
|
|
|
|
for( SCH_SHEET_PATH& sheetPath : *this )
|
2022-12-25 16:04:45 +00:00
|
|
|
{
|
2024-06-06 10:40:24 +00:00
|
|
|
KIID_PATH tmp = sheetPath.Path();
|
2022-12-25 16:04:45 +00:00
|
|
|
SCH_SHEET_PATH newSheetPath( aPrefixSheetPath );
|
|
|
|
|
|
|
|
// Prefix the new hierarchical path.
|
|
|
|
newSheetPath = newSheetPath + sheetPath;
|
|
|
|
|
|
|
|
// Sheets cannot have themselves in the path.
|
|
|
|
tmp.pop_back();
|
|
|
|
|
|
|
|
SCH_SHEET* sheet = sheetPath.Last();
|
|
|
|
|
|
|
|
wxCHECK2( sheet, continue );
|
|
|
|
|
|
|
|
nextVirtualPageNumber += 1;
|
|
|
|
|
|
|
|
SCH_SHEET_INSTANCE instance;
|
|
|
|
|
2023-08-14 17:38:26 +00:00
|
|
|
// Add the instance if it doesn't already exist
|
2024-06-06 10:40:24 +00:00
|
|
|
if( !sheet->getInstance( instance, tmp, true ) )
|
2022-12-25 16:04:45 +00:00
|
|
|
{
|
2023-08-14 17:38:26 +00:00
|
|
|
sheet->addInstance( tmp );
|
2024-06-06 10:40:24 +00:00
|
|
|
sheet->getInstance( instance, tmp, true );
|
2022-12-25 16:04:45 +00:00
|
|
|
}
|
2023-08-14 17:38:26 +00:00
|
|
|
|
|
|
|
// Get a new page number if we don't have one
|
|
|
|
if( instance.m_PageNumber.IsEmpty() )
|
2022-12-25 16:04:45 +00:00
|
|
|
{
|
|
|
|
// Generate the next available page number.
|
|
|
|
do
|
|
|
|
{
|
|
|
|
pageNumber.Printf( wxT( "%d" ), lastUsedPageNumber );
|
|
|
|
lastUsedPageNumber += 1;
|
|
|
|
} while( std::find( usedPageNumbers.begin(), usedPageNumbers.end(), pageNumber ) !=
|
|
|
|
usedPageNumbers.end() );
|
|
|
|
|
2023-08-14 17:38:26 +00:00
|
|
|
instance.m_PageNumber = pageNumber;
|
2022-12-25 16:04:45 +00:00
|
|
|
newSheetPath.SetVirtualPageNumber( nextVirtualPageNumber );
|
|
|
|
}
|
2023-08-14 17:38:26 +00:00
|
|
|
|
|
|
|
newSheetPath.SetPageNumber( instance.m_PageNumber );
|
|
|
|
usedPageNumbers.push_back( instance.m_PageNumber );
|
2022-12-25 16:04:45 +00:00
|
|
|
}
|
2022-10-01 12:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_SHEET_LIST::GetLastVirtualPageNumber() const
|
|
|
|
{
|
|
|
|
int lastVirtualPageNumber = 1;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& sheetPath : *this )
|
|
|
|
{
|
|
|
|
if( sheetPath.GetVirtualPageNumber() > lastVirtualPageNumber )
|
|
|
|
lastVirtualPageNumber = sheetPath.GetVirtualPageNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
return lastVirtualPageNumber;
|
|
|
|
}
|
|
|
|
|
2023-08-25 12:51:59 +00:00
|
|
|
|
|
|
|
bool SCH_SHEET_LIST::HasPath( const KIID_PATH& aPath ) const
|
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& path : *this )
|
|
|
|
{
|
|
|
|
if( path.Path() == aPath )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2024-01-21 16:53:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SHEET_LIST::ContainsSheet( const SCH_SHEET* aSheet ) const
|
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& path : *this )
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < path.size(); i++ )
|
|
|
|
{
|
|
|
|
if( path.at( i ) == aSheet )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|