2011-02-28 18:36:19 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2011-02-28 18:36:19 +00:00
|
|
|
*
|
2018-05-08 07:46:25 +00:00
|
|
|
* Copyright (C) 1992-2018 jean-pierre Charras <jp.charras at wanadoo.fr>
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright (C) 1992-2011 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-01-03 21:08:36 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-02-28 18:36:19 +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
|
|
|
|
*/
|
|
|
|
|
2021-01-24 22:25:32 +00:00
|
|
|
/**
|
2023-04-19 11:51:26 +00:00
|
|
|
* @file sch_reference_list.cpp
|
2021-06-10 14:10:55 +00:00
|
|
|
* @brief functions to create a symbol flat list and to annotate schematic.
|
2021-01-24 22:25:32 +00:00
|
|
|
*/
|
|
|
|
|
2019-01-29 10:50:50 +00:00
|
|
|
#include <sch_reference_list.h>
|
2022-04-17 21:23:22 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2012-02-23 23:57:29 +00:00
|
|
|
#include <wx/regex.h>
|
2013-12-13 16:27:30 +00:00
|
|
|
#include <algorithm>
|
2011-02-28 18:36:19 +00:00
|
|
|
#include <vector>
|
2018-05-08 07:46:25 +00:00
|
|
|
#include <unordered_set>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2021-09-01 16:25:08 +00:00
|
|
|
#include <string_utils.h>
|
2021-01-24 22:25:32 +00:00
|
|
|
#include <erc_settings.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-01-29 10:50:50 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2012-02-23 12:54:54 +00:00
|
|
|
void SCH_REFERENCE_LIST::RemoveItem( unsigned int aIndex )
|
2012-02-22 21:37:34 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
if( aIndex < m_flatList.size() )
|
|
|
|
m_flatList.erase( m_flatList.begin() + aIndex );
|
2012-02-22 21:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
bool SCH_REFERENCE_LIST::Contains( const SCH_REFERENCE& aItem ) const
|
2021-04-11 15:24:11 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < GetCount(); ii++ )
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
if( m_flatList[ii].IsSameInstance( aItem ) )
|
2021-04-11 15:24:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
bool SCH_REFERENCE_LIST::sortByXPosition( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
int ii = item1.CompareRef( item2 );
|
|
|
|
|
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_sheetNum - item2.m_sheetNum;
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_symbolPos.x - item2.m_symbolPos.x;
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_symbolPos.y - item2.m_symbolPos.y;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
|
2020-02-20 12:11:04 +00:00
|
|
|
else
|
|
|
|
return ii < 0;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
|
|
|
|
bool SCH_REFERENCE_LIST::sortByYPosition( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
int ii = item1.CompareRef( item2 );
|
|
|
|
|
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_sheetNum - item2.m_sheetNum;
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_symbolPos.y - item2.m_symbolPos.y;
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_symbolPos.x - item2.m_symbolPos.x;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
|
2020-02-20 12:11:04 +00:00
|
|
|
else
|
|
|
|
return ii < 0;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_REFERENCE_LIST::sortByRefAndValue( const SCH_REFERENCE& item1,
|
|
|
|
const SCH_REFERENCE& item2 )
|
|
|
|
{
|
|
|
|
int ii = item1.CompareRef( item2 );
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1.CompareValue( item2 );
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_unit - item2.m_unit;
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_sheetNum - item2.m_sheetNum;
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_symbolPos.x - item2.m_symbolPos.x;
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_symbolPos.y - item2.m_symbolPos.y;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
|
2020-02-20 12:11:04 +00:00
|
|
|
else
|
|
|
|
return ii < 0;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_REFERENCE_LIST::sortByReferenceOnly( const SCH_REFERENCE& item1,
|
|
|
|
const SCH_REFERENCE& item2 )
|
|
|
|
{
|
2021-09-01 16:25:08 +00:00
|
|
|
int ii = StrNumCmp( item1.GetRef(), item2.GetRef(), false );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
ii = item1.m_unit - item2.m_unit;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
|
2020-02-20 12:11:04 +00:00
|
|
|
else
|
|
|
|
return ii < 0;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_REFERENCE_LIST::sortByTimeStamp( const SCH_REFERENCE& item1,
|
|
|
|
const SCH_REFERENCE& item2 )
|
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
int ii = item1.m_sheetPath.Cmp( item2.m_sheetPath );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
2020-11-15 16:08:31 +00:00
|
|
|
return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
|
2020-02-20 12:11:04 +00:00
|
|
|
else
|
|
|
|
return ii < 0;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2022-11-03 10:15:23 +00:00
|
|
|
int SCH_REFERENCE_LIST::FindRefByFullPath( const wxString& aFullPath ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
for( size_t i = 0; i < m_flatList.size(); ++i )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-11-03 10:15:23 +00:00
|
|
|
if( m_flatList[i].GetFullPath() == aFullPath )
|
2020-02-20 12:11:04 +00:00
|
|
|
return i;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2020-02-20 12:11:04 +00:00
|
|
|
|
|
|
|
return -1;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-16 17:31:36 +00:00
|
|
|
int SCH_REFERENCE_LIST::FindRef( const wxString& aRef ) const
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
for( size_t i = 0; i < m_flatList.size(); ++i )
|
2020-07-16 17:31:36 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
if( m_flatList[i].GetRef() == aRef )
|
2020-07-16 17:31:36 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
void SCH_REFERENCE_LIST::GetRefsInUse( int aIndex, std::vector< int >& aIdList,
|
|
|
|
int aMinRefId ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
aIdList.clear();
|
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
for( const SCH_REFERENCE& ref : m_flatList )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-04-11 15:24:11 +00:00
|
|
|
// Don't add new references to the list as we will reannotate those
|
2022-10-06 22:39:49 +00:00
|
|
|
if( m_flatList[aIndex].CompareRef( ref ) == 0 && ref.m_numRef >= aMinRefId && !ref.m_isNew )
|
2020-11-15 16:08:31 +00:00
|
|
|
aIdList.push_back( ref.m_numRef );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
std::sort( aIdList.begin(), aIdList.end() );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Ensure each reference number appears only once. If there are symbols with
|
2011-02-28 18:36:19 +00:00
|
|
|
// multiple parts per package the same number will be stored for each part.
|
2022-04-17 21:23:22 +00:00
|
|
|
alg::remove_duplicates( aIdList );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<int> SCH_REFERENCE_LIST::GetUnitsMatchingRef( const SCH_REFERENCE& aRef ) const
|
|
|
|
{
|
|
|
|
std::vector<int> unitsList;
|
|
|
|
|
|
|
|
// Always add this reference to the list
|
|
|
|
unitsList.push_back( aRef.m_unit );
|
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
for( SCH_REFERENCE ref : m_flatList )
|
2022-04-17 21:23:22 +00:00
|
|
|
{
|
|
|
|
if( ref.CompareValue( aRef ) != 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ref.CompareLibName( aRef ) != 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Split if needed before comparing ref and number
|
|
|
|
if( ref.IsSplitNeeded() )
|
|
|
|
ref.Split();
|
|
|
|
|
|
|
|
if( ref.CompareRef( aRef ) != 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ref.m_numRef != aRef.m_numRef )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
unitsList.push_back( ref.m_unit );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort( unitsList.begin(), unitsList.end() );
|
|
|
|
|
|
|
|
// Ensure each reference number appears only once. If there are symbols with
|
|
|
|
// multiple parts per package the same number will be stored for each part.
|
|
|
|
alg::remove_duplicates( unitsList );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
return unitsList;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
int SCH_REFERENCE_LIST::FindFirstUnusedReference( const SCH_REFERENCE& aRef, int aMinValue,
|
|
|
|
const std::vector<int>& aRequiredUnits ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-04-17 21:23:22 +00:00
|
|
|
// Create a map of references indexed by reference number, only including those with the same
|
|
|
|
// reference prefix as aRef
|
|
|
|
std::map<int, std::vector<SCH_REFERENCE>> refNumberMap;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
for( const SCH_REFERENCE& ref : m_flatList )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
// search only for the current reference prefix:
|
2022-04-17 21:23:22 +00:00
|
|
|
if( ref.CompareRef( aRef ) != 0 )
|
2011-02-28 18:36:19 +00:00
|
|
|
continue;
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
if( ref.m_isNew )
|
|
|
|
continue; // It will be reannotated
|
|
|
|
|
|
|
|
refNumberMap[ref.m_numRef].push_back( ref );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start at the given minimum value
|
|
|
|
int minFreeNumber = aMinValue;
|
|
|
|
|
|
|
|
for( ; refNumberMap[minFreeNumber].size() > 0; ++minFreeNumber )
|
|
|
|
{
|
|
|
|
auto isNumberInUse = [&]() -> bool
|
|
|
|
{
|
|
|
|
for( const int& unit : aRequiredUnits )
|
|
|
|
{
|
|
|
|
for( const SCH_REFERENCE& ref : refNumberMap[minFreeNumber] )
|
|
|
|
{
|
|
|
|
if( ref.CompareLibName( aRef ) || ref.CompareValue( aRef )
|
|
|
|
|| ref.GetUnit() == unit )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( !isNumberInUse() )
|
|
|
|
return minFreeNumber;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
return minFreeNumber;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
std::vector<SCH_SYMBOL_INSTANCE> SCH_REFERENCE_LIST::GetSymbolInstances() const
|
2021-04-12 19:08:02 +00:00
|
|
|
{
|
2023-01-04 20:39:50 +00:00
|
|
|
std::vector<SCH_SYMBOL_INSTANCE> retval;
|
2021-04-12 19:08:02 +00:00
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
for( const SCH_REFERENCE& ref : m_flatList )
|
2021-04-12 19:08:02 +00:00
|
|
|
{
|
2023-01-04 20:39:50 +00:00
|
|
|
SCH_SYMBOL_INSTANCE instance;
|
2022-10-01 12:44:21 +00:00
|
|
|
instance.m_Path = ref.GetSheetPath().Path();
|
2021-04-12 19:08:02 +00:00
|
|
|
instance.m_Reference = ref.GetRef();
|
|
|
|
instance.m_Unit = ref.GetUnit();
|
|
|
|
|
|
|
|
retval.push_back( instance );
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
int SCH_REFERENCE_LIST::createFirstFreeRefId( std::vector<int>& aIdList, int aFirstValue )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
int expectedId = aFirstValue;
|
|
|
|
|
|
|
|
// We search for expected Id a value >= aFirstValue.
|
|
|
|
// Skip existing Id < aFirstValue
|
|
|
|
unsigned ii = 0;
|
|
|
|
|
|
|
|
for( ; ii < aIdList.size(); ii++ )
|
|
|
|
{
|
|
|
|
if( expectedId <= aIdList[ii] )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ids are sorted by increasing value, from aFirstValue
|
|
|
|
// So we search from aFirstValue the first not used value, i.e. the first hole in list.
|
|
|
|
for( ; ii < aIdList.size(); ii++ )
|
|
|
|
{
|
|
|
|
if( expectedId != aIdList[ii] ) // This id is not yet used.
|
|
|
|
{
|
|
|
|
// Insert this free Id, in order to keep list sorted
|
|
|
|
aIdList.insert( aIdList.begin() + ii, expectedId );
|
|
|
|
return expectedId;
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedId++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All existing Id are tested, and all values are found in use.
|
|
|
|
// So Create a new one.
|
|
|
|
aIdList.push_back( expectedId );
|
|
|
|
return expectedId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-08 07:46:25 +00:00
|
|
|
// A helper function to build a full reference string of a SCH_REFERENCE item
|
2018-07-10 15:51:14 +00:00
|
|
|
wxString buildFullReference( const SCH_REFERENCE& aItem, int aUnitNumber = -1 )
|
2018-05-08 07:46:25 +00:00
|
|
|
{
|
|
|
|
wxString fullref;
|
|
|
|
fullref = aItem.GetRef() + aItem.GetRefNumber();
|
2018-07-10 15:51:14 +00:00
|
|
|
|
|
|
|
if( aUnitNumber < 0 )
|
|
|
|
fullref << ".." << aItem.GetUnit();
|
|
|
|
else
|
|
|
|
fullref << ".." << aUnitNumber;
|
2018-05-08 07:46:25 +00:00
|
|
|
|
|
|
|
return fullref;
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2022-07-19 17:00:24 +00:00
|
|
|
void SCH_REFERENCE_LIST::ReannotateByOptions( ANNOTATE_ORDER_T aSortOption,
|
|
|
|
ANNOTATE_ALGO_T aAlgoOption,
|
|
|
|
int aStartNumber,
|
|
|
|
const SCH_REFERENCE_LIST& aAdditionalRefs,
|
2022-07-20 15:39:15 +00:00
|
|
|
bool aStartAtCurrent,
|
|
|
|
SCH_SHEET_LIST* aHierarchy )
|
2021-05-01 22:39:16 +00:00
|
|
|
{
|
|
|
|
SplitReferences();
|
|
|
|
|
|
|
|
// All multi-unit symbols always locked to ensure consistent re-annotation
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP lockedSymbols;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < GetCount(); i++ )
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
SCH_REFERENCE& ref = m_flatList[i];
|
2021-05-01 22:39:16 +00:00
|
|
|
wxString refstr = ref.GetSymbol()->GetRef( &ref.GetSheetPath() );
|
|
|
|
|
2022-07-20 15:39:15 +00:00
|
|
|
// Update sheet numbers based on the reference's sheet's position within the full
|
|
|
|
// hierarchy; we do this now before we annotate so annotation by sheet number * X
|
|
|
|
// works correctly.
|
|
|
|
if( aHierarchy )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH* path = aHierarchy->FindSheetForPath( &ref.GetSheetPath() );
|
|
|
|
wxASSERT_MSG( path, wxT( "Attempting to annotate item on sheet not part of the hierarchy?" ) );
|
|
|
|
|
|
|
|
ref.SetSheetNumber( path->GetVirtualPageNumber() );
|
|
|
|
}
|
|
|
|
|
2021-05-01 22:39:16 +00:00
|
|
|
// Never lock unassigned references
|
|
|
|
if( refstr[refstr.Len() - 1] == '?' )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ref.m_isNew = true; // We want to reannotate all references
|
2022-04-17 21:23:22 +00:00
|
|
|
|
|
|
|
lockedSymbols[refstr].AddItem( ref );
|
2021-05-01 22:39:16 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 17:00:24 +00:00
|
|
|
AnnotateByOptions( aSortOption, aAlgoOption, aStartNumber, lockedSymbols, aAdditionalRefs,
|
|
|
|
aStartAtCurrent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_REFERENCE_LIST::ReannotateDuplicates( const SCH_REFERENCE_LIST& aAdditionalReferences )
|
|
|
|
{
|
2022-07-20 15:39:15 +00:00
|
|
|
ReannotateByOptions( UNSORTED, INCREMENTAL_BY_REF, 0, aAdditionalReferences, true, nullptr );
|
2021-05-01 22:39:16 +00:00
|
|
|
}
|
2018-05-08 07:46:25 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
|
2022-07-19 16:13:30 +00:00
|
|
|
void SCH_REFERENCE_LIST::AnnotateByOptions( ANNOTATE_ORDER_T aSortOption,
|
|
|
|
ANNOTATE_ALGO_T aAlgoOption,
|
|
|
|
int aStartNumber,
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap,
|
|
|
|
const SCH_REFERENCE_LIST& aAdditionalRefs,
|
|
|
|
bool aStartAtCurrent )
|
|
|
|
{
|
|
|
|
switch( aSortOption )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case SORT_BY_X_POSITION: SortByXCoordinate(); break;
|
|
|
|
case SORT_BY_Y_POSITION: SortByYCoordinate(); break;
|
|
|
|
}
|
|
|
|
|
2022-07-20 12:54:14 +00:00
|
|
|
bool useSheetNum;
|
|
|
|
int idStep;
|
2022-07-19 16:13:30 +00:00
|
|
|
|
|
|
|
switch( aAlgoOption )
|
|
|
|
{
|
|
|
|
default:
|
2022-07-20 12:54:14 +00:00
|
|
|
case INCREMENTAL_BY_REF:
|
|
|
|
useSheetNum = false;
|
|
|
|
idStep = 1;
|
|
|
|
break;
|
2022-07-19 16:13:30 +00:00
|
|
|
|
2022-07-20 12:54:14 +00:00
|
|
|
case SHEET_NUMBER_X_100:
|
|
|
|
useSheetNum = true;
|
|
|
|
idStep = 100;
|
|
|
|
aStartAtCurrent = false; // Not implemented for sheet # * 100
|
|
|
|
break;
|
2022-07-19 16:13:30 +00:00
|
|
|
|
|
|
|
case SHEET_NUMBER_X_1000:
|
|
|
|
useSheetNum = true;
|
|
|
|
idStep = 1000;
|
2022-07-20 12:54:14 +00:00
|
|
|
aStartAtCurrent = false; // Not implemented for sheet # * 1000
|
2022-07-19 16:13:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Annotate( useSheetNum, idStep, aStartNumber, aLockedUnitMap, aAdditionalRefs, aStartAtCurrent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-18 20:44:33 +00:00
|
|
|
void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, int aStartNumber,
|
2021-04-11 15:24:11 +00:00
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap,
|
2021-05-01 22:39:16 +00:00
|
|
|
const SCH_REFERENCE_LIST& aAdditionalRefs, bool aStartAtCurrent )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
if ( m_flatList.size() == 0 )
|
2011-02-28 18:36:19 +00:00
|
|
|
return;
|
|
|
|
|
2021-05-01 22:39:16 +00:00
|
|
|
size_t originalSize = GetCount();
|
2021-04-11 15:24:11 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// For multi units symbols, store the list of already used full references.
|
|
|
|
// The algorithm tries to allocate the new reference to symbols having the same
|
2021-04-27 14:52:32 +00:00
|
|
|
// old reference.
|
|
|
|
// This algo works fine as long as the previous annotation has no duplicates.
|
2021-07-16 20:13:26 +00:00
|
|
|
// But when a hierarchy is reannotated with this option, the previous annotation can
|
2021-04-27 14:52:32 +00:00
|
|
|
// have duplicate references, and obviously we must fix these duplicate.
|
|
|
|
// therefore do not try to allocate a full reference more than once when trying
|
|
|
|
// to keep this order of multi units.
|
|
|
|
// inUseRefs keep trace of previously allocated references
|
|
|
|
std::unordered_set<wxString> inUseRefs;
|
|
|
|
|
2021-04-11 15:24:11 +00:00
|
|
|
for( size_t i = 0; i < aAdditionalRefs.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE additionalRef = aAdditionalRefs[i];
|
|
|
|
additionalRef.Split();
|
2021-04-27 14:52:32 +00:00
|
|
|
|
|
|
|
// Add the additional reference to the multi-unit set if annotated
|
|
|
|
if( !additionalRef.m_isNew )
|
|
|
|
inUseRefs.insert( buildFullReference( additionalRef ) );
|
|
|
|
|
|
|
|
// We don't want to reannotate the additional references even if not annotated
|
|
|
|
// so we change the m_isNew flag to be false after splitting
|
2021-04-11 15:24:11 +00:00
|
|
|
additionalRef.m_isNew = false;
|
|
|
|
AddItem( additionalRef ); //add to this container
|
|
|
|
}
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
int LastReferenceNumber = 0;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
/* calculate index of the first symbol with the same reference prefix
|
|
|
|
* than the current symbol. All symbols having the same reference
|
2011-02-28 18:36:19 +00:00
|
|
|
* prefix will receive a reference number with consecutive values:
|
|
|
|
* IC .. will be set to IC4, IC4, IC5 ...
|
|
|
|
*/
|
|
|
|
unsigned first = 0;
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// calculate the last used number for this reference prefix:
|
2018-02-18 20:44:33 +00:00
|
|
|
int minRefId;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
// when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
|
|
|
|
if( aUseSheetNum )
|
2022-10-06 22:39:49 +00:00
|
|
|
minRefId = m_flatList[first].m_sheetNum * aSheetIntervalId + 1;
|
2018-02-18 20:44:33 +00:00
|
|
|
else
|
|
|
|
minRefId = aStartNumber + 1;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
for( unsigned ii = 0; ii < m_flatList.size(); ii++ )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
auto& ref_unit = m_flatList[ii];
|
2019-10-26 14:52:57 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
if( ref_unit.m_flag )
|
2011-02-28 18:36:19 +00:00
|
|
|
continue;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Check whether this symbol is in aLockedUnitMap.
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_REFERENCE_LIST* lockedList = nullptr;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap )
|
2015-03-23 11:45:31 +00:00
|
|
|
{
|
|
|
|
unsigned n_refs = pair.second.GetCount();
|
2018-07-10 15:51:14 +00:00
|
|
|
|
2015-03-23 11:45:31 +00:00
|
|
|
for( unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE &thisRef = pair.second[thisRefI];
|
|
|
|
|
2019-10-26 14:52:57 +00:00
|
|
|
if( thisRef.IsSameInstance( ref_unit ) )
|
2015-03-23 11:45:31 +00:00
|
|
|
{
|
|
|
|
lockedList = &pair.second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-07-16 20:13:26 +00:00
|
|
|
|
|
|
|
if( lockedList != nullptr )
|
|
|
|
break;
|
2015-03-23 11:45:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
if( ( m_flatList[first].CompareRef( ref_unit ) != 0 )
|
|
|
|
|| ( aUseSheetNum && ( m_flatList[first].m_sheetNum != ref_unit.m_sheetNum ) ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// New reference found: we need a new ref number for this reference
|
2011-02-28 18:36:19 +00:00
|
|
|
first = ii;
|
2018-05-08 07:46:25 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
// when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
|
|
|
|
if( aUseSheetNum )
|
2020-11-15 16:08:31 +00:00
|
|
|
minRefId = ref_unit.m_sheetNum * aSheetIntervalId + 1;
|
2018-02-18 20:44:33 +00:00
|
|
|
else
|
|
|
|
minRefId = aStartNumber + 1;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2021-05-01 22:39:16 +00:00
|
|
|
// Find references greater than current reference (unless not annotated)
|
|
|
|
if( aStartAtCurrent && ref_unit.m_numRef > 0 )
|
|
|
|
minRefId = ref_unit.m_numRef;
|
|
|
|
|
2023-04-08 19:28:45 +00:00
|
|
|
wxCHECK( ref_unit.GetLibPart(), /* void */ );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Annotation of one part per package symbols (trivial case).
|
2019-10-26 14:52:57 +00:00
|
|
|
if( ref_unit.GetLibPart()->GetUnitCount() <= 1 )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
if( ref_unit.m_isNew )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-04-17 21:23:22 +00:00
|
|
|
std::vector<int> idList;
|
|
|
|
GetRefsInUse( first, idList, minRefId );
|
|
|
|
LastReferenceNumber = createFirstFreeRefId( idList, minRefId );
|
2020-11-15 16:08:31 +00:00
|
|
|
ref_unit.m_numRef = LastReferenceNumber;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
ref_unit.m_flag = 1;
|
|
|
|
ref_unit.m_isNew = false;
|
2011-02-28 18:36:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// If this symbol is in aLockedUnitMap, copy the annotation to all
|
|
|
|
// symbols that are not it
|
2021-07-16 20:13:26 +00:00
|
|
|
if( lockedList != nullptr )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2015-03-23 11:45:31 +00:00
|
|
|
unsigned n_refs = lockedList->GetCount();
|
2022-04-17 21:23:22 +00:00
|
|
|
std::vector<int> units = lockedList->GetUnitsMatchingRef( ref_unit );
|
2018-05-08 07:46:25 +00:00
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
if( ref_unit.m_isNew )
|
2015-03-23 11:45:31 +00:00
|
|
|
{
|
2022-04-17 21:23:22 +00:00
|
|
|
LastReferenceNumber = FindFirstUnusedReference( ref_unit, minRefId, units );
|
|
|
|
ref_unit.m_numRef = LastReferenceNumber;
|
|
|
|
ref_unit.m_isNew = false;
|
|
|
|
ref_unit.m_flag = 1;
|
|
|
|
}
|
2018-05-08 07:46:25 +00:00
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
for( unsigned lockedRefI = 0; lockedRefI < n_refs; ++lockedRefI )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE& lockedRef = ( *lockedList )[lockedRefI];
|
|
|
|
|
|
|
|
if( lockedRef.IsSameInstance( ref_unit ) )
|
2015-03-23 11:45:31 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
// This is the symbol we're currently annotating. Hold the unit!
|
2022-04-17 21:23:22 +00:00
|
|
|
ref_unit.m_unit = lockedRef.m_unit;
|
2023-01-03 21:08:36 +00:00
|
|
|
|
2018-07-10 15:51:14 +00:00
|
|
|
// lock this new full reference
|
2019-10-26 14:52:57 +00:00
|
|
|
inUseRefs.insert( buildFullReference( ref_unit ) );
|
2015-03-23 11:45:31 +00:00
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
if( lockedRef.CompareValue( ref_unit ) != 0 )
|
2018-05-08 07:46:25 +00:00
|
|
|
continue;
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
if( lockedRef.CompareLibName( ref_unit ) != 0 )
|
2018-05-08 07:46:25 +00:00
|
|
|
continue;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Find the matching symbol
|
2022-10-06 22:39:49 +00:00
|
|
|
for( unsigned jj = ii + 1; jj < m_flatList.size(); jj++ )
|
2015-03-23 11:45:31 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
if( !lockedRef.IsSameInstance( m_flatList[jj] ) )
|
2018-05-08 07:46:25 +00:00
|
|
|
continue;
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
wxString ref_candidate = buildFullReference( ref_unit, lockedRef.m_unit );
|
2018-05-08 07:46:25 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// propagate the new reference and unit selection to the "old" symbol,
|
2018-05-08 07:46:25 +00:00
|
|
|
// if this new full reference is not already used (can happens when initial
|
2021-06-10 14:10:55 +00:00
|
|
|
// multiunits symbols have duplicate references)
|
2018-05-08 07:46:25 +00:00
|
|
|
if( inUseRefs.find( ref_candidate ) == inUseRefs.end() )
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
m_flatList[jj].m_numRef = ref_unit.m_numRef;
|
|
|
|
m_flatList[jj].m_isNew = false;
|
|
|
|
m_flatList[jj].m_flag = 1;
|
2023-01-03 21:08:36 +00:00
|
|
|
|
2018-05-08 07:46:25 +00:00
|
|
|
// lock this new full reference
|
|
|
|
inUseRefs.insert( ref_candidate );
|
|
|
|
break;
|
|
|
|
}
|
2015-03-23 11:45:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-17 21:23:22 +00:00
|
|
|
else if( ref_unit.m_isNew )
|
2015-03-23 11:45:31 +00:00
|
|
|
{
|
2022-04-17 21:23:22 +00:00
|
|
|
// Reference belonging to multi-unit symbol that has not yet been annotated. We don't
|
|
|
|
// know what group this might belong to, so just find the first unused reference for
|
|
|
|
// this specific unit. The other units will be annotated in the following passes.
|
|
|
|
std::vector<int> units = { ref_unit.GetUnit() };
|
|
|
|
LastReferenceNumber = FindFirstUnusedReference( ref_unit, minRefId, units );
|
|
|
|
ref_unit.m_numRef = LastReferenceNumber;
|
|
|
|
ref_unit.m_isNew = false;
|
|
|
|
ref_unit.m_flag = 1;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-11 15:24:11 +00:00
|
|
|
|
|
|
|
// Remove aAdditionalRefs references
|
2021-05-01 14:27:07 +00:00
|
|
|
for( size_t i = originalSize; i < ( aAdditionalRefs.GetCount() + originalSize ); i++ )
|
2021-04-11 15:24:11 +00:00
|
|
|
RemoveItem( originalSize );
|
|
|
|
|
|
|
|
wxASSERT( originalSize == GetCount() ); // Make sure we didn't make a mistake
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
|
2021-01-24 22:25:32 +00:00
|
|
|
int SCH_REFERENCE_LIST::CheckAnnotation( ANNOTATION_ERROR_HANDLER aHandler )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
wxString tmp;
|
2022-10-06 22:39:49 +00:00
|
|
|
wxString tmp2;
|
2011-02-28 18:36:19 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
SortByRefAndValue();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
// Split reference designators into name (prefix) and number: IC1 becomes IC, and 1.
|
2011-02-28 18:36:19 +00:00
|
|
|
SplitReferences();
|
|
|
|
|
|
|
|
// count not yet annotated items or annotation error.
|
2022-10-06 22:39:49 +00:00
|
|
|
for( unsigned ii = 0; ii < m_flatList.size(); ii++ )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
msg.Empty();
|
|
|
|
tmp.Empty();
|
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
if( m_flatList[ii].m_isNew ) // Not yet annotated
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
if( m_flatList[ii].m_numRef >= 0 )
|
|
|
|
tmp << m_flatList[ii].m_numRef;
|
2011-02-28 18:36:19 +00:00
|
|
|
else
|
|
|
|
tmp = wxT( "?" );
|
|
|
|
|
2023-01-01 10:21:05 +00:00
|
|
|
if( ( m_flatList[ii].m_unit > 0 ) && ( m_flatList[ii].m_unit < 0x7FFFFFFF )
|
|
|
|
&& m_flatList[ii].GetLibPart()->GetUnitCount() > 1 )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-09-15 22:43:00 +00:00
|
|
|
msg.Printf( _( "Item not annotated: %s%s (unit %d)" ),
|
2022-10-06 22:39:49 +00:00
|
|
|
m_flatList[ii].GetRef(),
|
2018-09-12 22:50:21 +00:00
|
|
|
tmp,
|
2022-10-06 22:39:49 +00:00
|
|
|
m_flatList[ii].m_unit );
|
2013-04-09 17:49:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
msg.Printf( _( "Item not annotated: %s%s" ), m_flatList[ii].GetRef(), tmp );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
aHandler( ERCE_UNANNOTATED, msg, &m_flatList[ii], nullptr );
|
2011-02-28 18:36:19 +00:00
|
|
|
error++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-24 22:25:32 +00:00
|
|
|
// Error if unit number selected does not exist (greater than the number of units in
|
2021-06-10 14:10:55 +00:00
|
|
|
// the symbol). This can happen if a symbol has changed in a library after a
|
2021-01-24 22:25:32 +00:00
|
|
|
// previous annotation.
|
2022-10-06 22:39:49 +00:00
|
|
|
if( std::max( m_flatList[ii].GetLibPart()->GetUnitCount(), 1 ) < m_flatList[ii].m_unit )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
if( m_flatList[ii].m_numRef >= 0 )
|
|
|
|
tmp << m_flatList[ii].m_numRef;
|
2011-02-28 18:36:19 +00:00
|
|
|
else
|
|
|
|
tmp = wxT( "?" );
|
|
|
|
|
2022-09-15 22:43:00 +00:00
|
|
|
msg.Printf( _( "Error: symbol %s%s%s (unit %d) exceeds units defined (%d)" ),
|
2022-10-06 22:39:49 +00:00
|
|
|
m_flatList[ii].GetRef(),
|
2018-09-12 22:50:21 +00:00
|
|
|
tmp,
|
2022-10-06 22:39:49 +00:00
|
|
|
LIB_SYMBOL::SubReference( m_flatList[ii].m_unit ),
|
|
|
|
m_flatList[ii].m_unit,
|
|
|
|
m_flatList[ii].GetLibPart()->GetUnitCount() );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
aHandler( ERCE_EXTRA_UNITS, msg, &m_flatList[ii], nullptr );
|
2011-02-28 18:36:19 +00:00
|
|
|
error++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// count the duplicated elements (if all are annotated)
|
2022-10-06 22:39:49 +00:00
|
|
|
int imax = m_flatList.size() - 1;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2018-09-12 22:50:21 +00:00
|
|
|
for( int ii = 0; ii < imax; ii++ )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
msg.Empty();
|
|
|
|
tmp.Empty();
|
2022-10-06 22:39:49 +00:00
|
|
|
tmp2.Empty();
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
SCH_REFERENCE& first = m_flatList[ii];
|
|
|
|
SCH_REFERENCE& second = m_flatList[ii + 1];
|
|
|
|
|
|
|
|
if( ( first.CompareRef( second ) != 0 )
|
|
|
|
|| ( first.m_numRef != second.m_numRef ) )
|
2021-01-24 22:25:32 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
continue;
|
2021-01-24 22:25:32 +00:00
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
// Same reference found. If same unit, error!
|
2022-10-06 22:39:49 +00:00
|
|
|
if( first.m_unit == second.m_unit )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
if( first.m_numRef >= 0 )
|
|
|
|
tmp << first.m_numRef;
|
2011-02-28 18:36:19 +00:00
|
|
|
else
|
|
|
|
tmp = wxT( "?" );
|
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
msg.Printf( _( "Duplicate items %s%s%s\n" ),
|
|
|
|
first.GetRef(),
|
|
|
|
tmp,
|
2023-01-01 10:21:05 +00:00
|
|
|
first.GetLibPart()->GetUnitCount() > 1 ?
|
2023-02-12 21:29:26 +00:00
|
|
|
LIB_SYMBOL::SubReference( first.m_unit ) : wxString( wxT( "" ) ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
aHandler( ERCE_DUPLICATE_REFERENCE, msg, &first, &m_flatList[ii+1] );
|
2011-02-28 18:36:19 +00:00
|
|
|
error++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test error if units are different but number of parts per package
|
|
|
|
* too high (ex U3 ( 1 part) and we find U3B this is an error) */
|
2022-10-06 22:39:49 +00:00
|
|
|
if( first.GetLibPart()->GetUnitCount() != second.GetLibPart()->GetUnitCount() )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
if( first.m_numRef >= 0 )
|
|
|
|
tmp << first.m_numRef;
|
2011-02-28 18:36:19 +00:00
|
|
|
else
|
|
|
|
tmp = wxT( "?" );
|
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
if( second.m_numRef >= 0 )
|
|
|
|
tmp2 << second.m_numRef;
|
2013-04-09 17:49:01 +00:00
|
|
|
else
|
2022-10-06 22:39:49 +00:00
|
|
|
tmp2 = wxT( "?" );
|
|
|
|
|
|
|
|
msg.Printf( _( "Differing unit counts for item %s%s%s and %s%s%s\n" ),
|
|
|
|
first.GetRef(),
|
|
|
|
tmp,
|
|
|
|
LIB_SYMBOL::SubReference( first.m_unit ),
|
|
|
|
second.GetRef(),
|
|
|
|
tmp2,
|
|
|
|
LIB_SYMBOL::SubReference( second.m_unit ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
aHandler( ERCE_DUPLICATE_REFERENCE, msg, &first, &second );
|
2011-02-28 18:36:19 +00:00
|
|
|
error++;
|
2022-10-06 22:39:49 +00:00
|
|
|
continue;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// Error if values are different between units, for the same reference
|
2022-10-06 22:39:49 +00:00
|
|
|
if( first.CompareValue( second ) != 0 )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-06-12 19:43:22 +00:00
|
|
|
msg.Printf( _( "Different values for %s%d%s (%s) and %s%d%s (%s)" ),
|
2022-10-06 22:39:49 +00:00
|
|
|
first.GetRef(),
|
|
|
|
first.m_numRef,
|
|
|
|
LIB_SYMBOL::SubReference( first.m_unit ),
|
|
|
|
first.m_value,
|
|
|
|
second.GetRef(),
|
|
|
|
second.m_numRef,
|
|
|
|
LIB_SYMBOL::SubReference( second.m_unit ),
|
|
|
|
second.m_value );
|
|
|
|
|
|
|
|
aHandler( ERCE_DIFFERENT_UNIT_VALUE, msg, &first, &second );
|
2011-02-28 18:36:19 +00:00
|
|
|
error++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
SCH_REFERENCE::SCH_REFERENCE( SCH_SYMBOL* aSymbol, LIB_SYMBOL* aLibSymbol,
|
2020-05-12 11:53:45 +00:00
|
|
|
const SCH_SHEET_PATH& aSheetPath )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( aSymbol != nullptr );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2020-11-17 21:36:17 +00:00
|
|
|
m_rootSymbol = aSymbol;
|
2021-06-10 18:51:46 +00:00
|
|
|
m_libPart = aLibSymbol; // Warning: can be nullptr for orphan symbols
|
|
|
|
// (i.e. with a symbol library not found)
|
2020-11-15 16:08:31 +00:00
|
|
|
m_unit = aSymbol->GetUnitSelection( &aSheetPath );
|
2023-05-05 13:21:56 +00:00
|
|
|
m_footprint = aSymbol->GetFootprintFieldText( true, &aSheetPath, false );
|
2020-11-15 16:08:31 +00:00
|
|
|
m_sheetPath = aSheetPath;
|
|
|
|
m_isNew = false;
|
|
|
|
m_flag = 0;
|
|
|
|
m_symbolUuid = aSymbol->m_Uuid;
|
|
|
|
m_symbolPos = aSymbol->GetPosition();
|
|
|
|
m_sheetNum = 0;
|
|
|
|
|
|
|
|
if( aSymbol->GetRef( &aSheetPath ).IsEmpty() )
|
|
|
|
aSymbol->SetRef( &aSheetPath, wxT( "DefRef?" ) );
|
|
|
|
|
|
|
|
wxString ref = aSymbol->GetRef( &aSheetPath );
|
2016-06-24 10:55:54 +00:00
|
|
|
SetRef( ref );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
m_numRef = -1;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
if( aSymbol->GetValueFieldText( false, &aSheetPath, false ).IsEmpty() )
|
2022-11-25 14:25:39 +00:00
|
|
|
aSymbol->SetValueFieldText( wxT( "~" ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
m_value = aSymbol->GetValueFieldText( false, &aSheetPath, false );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_REFERENCE::Annotate()
|
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
if( m_numRef < 0 )
|
|
|
|
m_ref += '?';
|
2011-02-28 18:36:19 +00:00
|
|
|
else
|
2020-11-15 16:08:31 +00:00
|
|
|
m_ref = TO_UTF8( GetRef() << GetRefNumber() );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
m_rootSymbol->SetRef( &m_sheetPath, FROM_UTF8( m_ref.c_str() ) );
|
|
|
|
m_rootSymbol->SetUnit( m_unit );
|
|
|
|
m_rootSymbol->SetUnitSelection( &m_sheetPath, m_unit );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-03 21:08:36 +00:00
|
|
|
bool SCH_REFERENCE::AlwaysAnnotate() const
|
|
|
|
{
|
|
|
|
wxCHECK( m_rootSymbol && m_rootSymbol->GetLibSymbolRef()
|
|
|
|
&& !m_rootSymbol->GetRef( &m_sheetPath ).IsEmpty(), false );
|
|
|
|
|
|
|
|
return m_rootSymbol->GetLibSymbolRef()->IsPower()
|
|
|
|
|| m_rootSymbol->GetRef( &m_sheetPath )[0] == wxUniChar( '#' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
void SCH_REFERENCE::Split()
|
|
|
|
{
|
|
|
|
std::string refText = GetRefStr();
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
m_numRef = -1;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
int ll = refText.length() - 1;
|
|
|
|
|
|
|
|
if( refText[ll] == '?' )
|
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
m_isNew = true;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
refText.erase( ll ); // delete last char
|
|
|
|
|
|
|
|
SetRefStr( refText );
|
|
|
|
}
|
|
|
|
else if( isdigit( refText[ll] ) == 0 )
|
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
m_isNew = true;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while( ll >= 0 )
|
|
|
|
{
|
2016-02-15 20:16:54 +00:00
|
|
|
if( (refText[ll] <= ' ' ) || isdigit( refText[ll] ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
ll--;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( isdigit( refText[ll + 1] ) )
|
|
|
|
{
|
|
|
|
// null terminated C string into cp
|
|
|
|
const char* cp = refText.c_str() + ll + 1;
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
m_numRef = atoi( cp );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refText.erase( ll+1 ); // delete from ll+1 to end
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetRefStr( refText );
|
|
|
|
}
|
|
|
|
}
|
2018-05-13 11:06:46 +00:00
|
|
|
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
bool SCH_REFERENCE::IsSplitNeeded()
|
|
|
|
{
|
|
|
|
std::string refText = GetRefStr();
|
|
|
|
|
|
|
|
int ll = refText.length() - 1;
|
|
|
|
|
|
|
|
return ( refText[ll] == '?' ) || isdigit( refText[ll] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
wxString SCH_REFERENCE_LIST::Shorthand( std::vector<SCH_REFERENCE> aList,
|
|
|
|
const wxString& refDelimiter,
|
|
|
|
const wxString& refRangeDelimiter )
|
2018-05-13 11:06:46 +00:00
|
|
|
{
|
|
|
|
wxString retVal;
|
2018-10-07 23:14:07 +00:00
|
|
|
size_t i = 0;
|
2018-05-13 11:06:46 +00:00
|
|
|
|
|
|
|
while( i < aList.size() )
|
|
|
|
{
|
|
|
|
wxString ref = aList[ i ].GetRef();
|
2020-11-15 16:08:31 +00:00
|
|
|
int numRef = aList[ i ].m_numRef;
|
2018-05-13 11:06:46 +00:00
|
|
|
|
2018-09-14 11:58:50 +00:00
|
|
|
size_t range = 1;
|
2018-05-13 11:06:46 +00:00
|
|
|
|
2018-09-14 11:58:50 +00:00
|
|
|
while( i + range < aList.size()
|
|
|
|
&& aList[ i + range ].GetRef() == ref
|
2020-11-15 16:08:31 +00:00
|
|
|
&& aList[ i + range ].m_numRef == int( numRef + range ) )
|
2018-09-14 11:58:50 +00:00
|
|
|
{
|
|
|
|
range++;
|
2023-03-15 00:03:57 +00:00
|
|
|
|
|
|
|
if( range == 2 && refRangeDelimiter.IsEmpty() )
|
|
|
|
break;
|
2018-09-14 11:58:50 +00:00
|
|
|
}
|
2018-05-13 11:06:46 +00:00
|
|
|
|
|
|
|
if( !retVal.IsEmpty() )
|
2023-03-15 00:03:57 +00:00
|
|
|
retVal << refDelimiter;
|
2018-05-13 11:06:46 +00:00
|
|
|
|
2018-09-14 11:58:50 +00:00
|
|
|
if( range == 1 )
|
2018-05-13 11:06:46 +00:00
|
|
|
{
|
|
|
|
retVal << ref << aList[ i ].GetRefNumber();
|
|
|
|
}
|
2023-03-15 00:03:57 +00:00
|
|
|
else if( range == 2 || refRangeDelimiter.IsEmpty() )
|
2018-10-25 22:37:00 +00:00
|
|
|
{
|
|
|
|
retVal << ref << aList[ i ].GetRefNumber();
|
2023-03-15 00:03:57 +00:00
|
|
|
retVal << refDelimiter;
|
2018-10-25 22:37:00 +00:00
|
|
|
retVal << ref << aList[ i + 1 ].GetRefNumber();
|
|
|
|
}
|
2018-05-13 11:06:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
retVal << ref << aList[ i ].GetRefNumber();
|
2023-03-15 00:03:57 +00:00
|
|
|
retVal << refRangeDelimiter;
|
2018-09-14 11:58:50 +00:00
|
|
|
retVal << ref << aList[ i + ( range - 1 ) ].GetRefNumber();
|
2018-05-13 11:06:46 +00:00
|
|
|
}
|
|
|
|
|
2018-09-14 11:58:50 +00:00
|
|
|
i+= range;
|
2018-05-13 11:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|