2015-02-21 08:11:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2011 jean-pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
|
2021-03-25 21:13:01 +00:00
|
|
|
* Copyright (C) 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.
|
2015-02-21 08:11:58 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SCH_REFERENCE_LIST_H_
|
|
|
|
#define _SCH_REFERENCE_LIST_H_
|
|
|
|
|
2021-01-27 23:06:43 +00:00
|
|
|
#include <map>
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <lib_symbol.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2016-02-15 20:16:54 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2015-02-21 08:11:58 +00:00
|
|
|
#include <sch_text.h>
|
2021-01-24 22:25:32 +00:00
|
|
|
#include <erc_settings.h>
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2022-07-19 16:13:30 +00:00
|
|
|
|
|
|
|
/** Schematic annotation scope options. */
|
|
|
|
enum ANNOTATE_SCOPE_T
|
|
|
|
{
|
|
|
|
ANNOTATE_ALL, ///< Annotate the full schematic
|
|
|
|
ANNOTATE_CURRENT_SHEET, ///< Annotate the current sheet
|
|
|
|
ANNOTATE_SELECTION ///< Annotate the selection
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Schematic annotation order options. */
|
|
|
|
enum ANNOTATE_ORDER_T
|
|
|
|
{
|
|
|
|
SORT_BY_X_POSITION, ///< Annotate by X position from left to right.
|
|
|
|
SORT_BY_Y_POSITION, ///< Annotate by Y position from top to bottom.
|
|
|
|
UNSORTED, ///< Annotate by position of symbol in the schematic sheet
|
|
|
|
///< object list.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Schematic annotation type options. */
|
|
|
|
enum ANNOTATE_ALGO_T
|
|
|
|
{
|
|
|
|
INCREMENTAL_BY_REF, ///< Annotate incrementally using the first free reference number.
|
|
|
|
SHEET_NUMBER_X_100, ///< Annotate using the first free reference number starting at
|
|
|
|
///< the sheet number * 100.
|
|
|
|
SHEET_NUMBER_X_1000, ///< Annotate using the first free reference number starting at
|
|
|
|
///< the sheet number * 1000.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* A helper to define a symbol's reference designator in a schematic.
|
|
|
|
*
|
|
|
|
* This helper is required in a complex hierarchy because a symbol can be used more than once
|
|
|
|
* and its reference depends on the sheet path. This class is used to flatten the schematic
|
|
|
|
* hierarchy for annotation, net list generation, and bill of material generation.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
|
|
|
class SCH_REFERENCE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SCH_REFERENCE() :
|
2020-11-15 16:08:31 +00:00
|
|
|
m_sheetPath()
|
2015-02-21 08:11:58 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
m_rootSymbol = nullptr;
|
|
|
|
m_libPart = nullptr;
|
2020-11-15 16:08:31 +00:00
|
|
|
m_unit = 0;
|
|
|
|
m_isNew = false;
|
|
|
|
m_numRef = 0;
|
|
|
|
m_flag = 0;
|
|
|
|
m_sheetNum = 0;
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
SCH_REFERENCE( SCH_SYMBOL* aSymbol, LIB_SYMBOL* aLibSymbol, const SCH_SHEET_PATH& aSheetPath );
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* GetSymbol() const { return m_rootSymbol; }
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* GetLibPart() const { return m_libPart; }
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
const SCH_SHEET_PATH& GetSheetPath() const { return m_sheetPath; }
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
SCH_SHEET_PATH& GetSheetPath() { return m_sheetPath; }
|
2020-01-29 16:33:57 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
int GetUnit() const { return m_unit; }
|
|
|
|
void SetUnit( int aUnit ) { m_unit = aUnit; }
|
2020-04-26 20:53:29 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
const wxString GetValue() const { return m_value; }
|
|
|
|
void SetValue( const wxString& aValue ) { m_value = aValue; }
|
2020-08-29 13:41:47 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
const wxString GetFootprint() const { return m_footprint; }
|
|
|
|
void SetFootprint( const wxString& aFP ) { m_footprint = aFP; }
|
2020-08-29 13:41:47 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
void SetSheetNumber( int aSheetNumber ) { m_sheetNum = aSheetNumber; }
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2022-11-03 10:15:23 +00:00
|
|
|
/**
|
|
|
|
* @return the sheet path containing the symbol item
|
|
|
|
*/
|
2020-01-29 16:33:57 +00:00
|
|
|
const wxString GetPath() const
|
|
|
|
{
|
2022-10-01 12:44:21 +00:00
|
|
|
return m_sheetPath.PathAsString();
|
2020-01-29 16:33:57 +00:00
|
|
|
}
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2022-11-03 10:15:23 +00:00
|
|
|
/**
|
|
|
|
* @return the full patb of the symbol item
|
|
|
|
*/
|
|
|
|
const wxString GetFullPath() const
|
|
|
|
{
|
|
|
|
return m_sheetPath.PathAsString() + m_symbolUuid.AsString();
|
|
|
|
}
|
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
/**
|
2021-06-09 19:32:58 +00:00
|
|
|
* Update the annotation of the symbol according the current object state.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
|
|
|
void Annotate();
|
|
|
|
|
2023-01-03 21:08:36 +00:00
|
|
|
/**
|
|
|
|
* Verify the reference should always be automatically annotated.
|
|
|
|
*
|
|
|
|
* @return true if the symbol reference should always be automatically annotated otherwise
|
|
|
|
* false.
|
|
|
|
*/
|
|
|
|
bool AlwaysAnnotate() const;
|
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Attempt to split the reference designator into a name (U) and number (1).
|
|
|
|
*
|
|
|
|
* If the last character is '?' or not a digit, the reference is tagged as not annotated.
|
2021-04-27 14:52:32 +00:00
|
|
|
* For symbols with multiple parts per package that are not already annotated, keeps the unit
|
|
|
|
* number the same. E.g. U?A or U?B
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
|
|
|
void Split();
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
/**
|
|
|
|
* Determine if this reference needs to be split or if it likely already has been
|
|
|
|
*
|
|
|
|
* @return true if this reference hasn't been split yet
|
|
|
|
*/
|
|
|
|
bool IsSplitNeeded();
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
void SetRef( const wxString& aReference ) { m_ref = aReference; }
|
|
|
|
wxString GetRef() const { return m_ref; }
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
void SetRefStr( const std::string& aReference ) { m_ref = aReference; }
|
|
|
|
const char* GetRefStr() const { return m_ref.c_str(); }
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Return reference name with unit altogether
|
2021-09-01 18:45:10 +00:00
|
|
|
wxString GetFullRef() const
|
2020-01-29 16:33:57 +00:00
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
if( GetSymbol()->GetUnitCount() > 1 )
|
2022-04-19 18:19:47 +00:00
|
|
|
return GetRef() + GetRefNumber() + LIB_SYMBOL::SubReference( GetUnit() );
|
2020-01-29 16:33:57 +00:00
|
|
|
else
|
2022-04-19 18:19:47 +00:00
|
|
|
return GetRef() + GetRefNumber();
|
2020-01-29 16:33:57 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
wxString GetRefNumber() const
|
|
|
|
{
|
|
|
|
wxString ref;
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
if( m_numRef < 0 )
|
2018-05-11 09:32:54 +00:00
|
|
|
return wxT( "?" );
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
// To avoid a risk of duplicate, for power symbols the ref number is 0nnn instead of nnn.
|
|
|
|
// Just because sometimes only power symbols are annotated
|
2018-04-17 10:34:48 +00:00
|
|
|
if( GetLibPart() && GetLibPart()->IsPower() )
|
|
|
|
ref = wxT( "0" );
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
return ref << m_numRef;
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
int CompareValue( const SCH_REFERENCE& item ) const
|
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
return m_value.Cmp( item.m_value );
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CompareRef( const SCH_REFERENCE& item ) const
|
|
|
|
{
|
2022-07-14 16:55:24 +00:00
|
|
|
return m_ref.CmpNoCase( item.m_ref );
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
2016-02-15 20:14:48 +00:00
|
|
|
int CompareLibName( const SCH_REFERENCE& item ) const
|
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
return m_rootSymbol->GetLibId().GetLibItemName().compare(
|
|
|
|
item.m_rootSymbol->GetLibId().GetLibItemName() );
|
2016-02-15 20:14:48 +00:00
|
|
|
}
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2015-03-23 11:45:31 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return whether this reference refers to the same symbol instance (symbol and sheet) as
|
2020-11-15 16:08:31 +00:00
|
|
|
* another.
|
2015-03-23 11:45:31 +00:00
|
|
|
*/
|
2016-02-15 20:14:48 +00:00
|
|
|
bool IsSameInstance( const SCH_REFERENCE& other ) const
|
|
|
|
{
|
2021-04-11 15:24:11 +00:00
|
|
|
// Only compare symbol and path.
|
|
|
|
// We may have changed the unit number or the designator but
|
|
|
|
// can still be referencing the same instance.
|
2020-11-15 16:08:31 +00:00
|
|
|
return GetSymbol() == other.GetSymbol()
|
|
|
|
&& GetSheetPath().Path() == other.GetSheetPath().Path();
|
2016-02-15 20:14:48 +00:00
|
|
|
}
|
2015-03-23 11:45:31 +00:00
|
|
|
|
2016-02-15 20:14:48 +00:00
|
|
|
bool IsUnitsLocked()
|
|
|
|
{
|
2021-05-01 22:39:16 +00:00
|
|
|
if( m_libPart )
|
|
|
|
return m_libPart->UnitsLocked();
|
|
|
|
else
|
|
|
|
return true; // Assume units locked when we don't have a library
|
2016-02-15 20:14:48 +00:00
|
|
|
}
|
2021-03-25 21:13:01 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SCH_REFERENCE_LIST;
|
|
|
|
|
|
|
|
/// Symbol reference prefix, without number (for IC1, this is IC) )
|
2022-07-14 16:55:24 +00:00
|
|
|
wxString m_ref; // it's private, use the accessors please
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* m_rootSymbol; ///< The symbol associated the reference object.
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* m_libPart; ///< The source symbol from a library.
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I m_symbolPos; ///< The physical position of the symbol in schematic
|
2021-03-25 21:13:01 +00:00
|
|
|
///< used to annotate by X or Y position
|
|
|
|
int m_unit; ///< The unit number for symbol with multiple parts
|
|
|
|
///< per package.
|
|
|
|
wxString m_value; ///< The symbol value.
|
|
|
|
wxString m_footprint; ///< The footprint assigned.
|
|
|
|
SCH_SHEET_PATH m_sheetPath; ///< The sheet path for this reference.
|
|
|
|
bool m_isNew; ///< True if not yet annotated.
|
|
|
|
int m_sheetNum; ///< The sheet number for the reference.
|
|
|
|
KIID m_symbolUuid; ///< UUID of the symbol.
|
|
|
|
int m_numRef; ///< The numeric part of the reference designator.
|
|
|
|
int m_flag;
|
2015-02-21 08:11:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-24 22:25:32 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Define a standard error handler for annotation errors.
|
2021-01-24 22:25:32 +00:00
|
|
|
*/
|
|
|
|
typedef std::function<void( ERCE_T aType, const wxString& aMsg, SCH_REFERENCE* aItemA,
|
|
|
|
SCH_REFERENCE* aItemB )> ANNOTATION_ERROR_HANDLER;
|
|
|
|
|
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Container to create a flattened list of symbols because in a complex hierarchy, a symbol
|
2015-02-21 08:11:58 +00:00
|
|
|
* can be used more than once and its reference designator is dependent on the sheet path for
|
2021-03-25 21:13:01 +00:00
|
|
|
* the same symbol.
|
|
|
|
*
|
|
|
|
* This flattened list is used for netlist generation, BOM generation, and schematic annotation.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
|
|
|
class SCH_REFERENCE_LIST
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SCH_REFERENCE_LIST()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_REFERENCE& operator[]( int aIndex )
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
return m_flatList[ aIndex ];
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
const SCH_REFERENCE& operator[]( int aIndex ) const
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
return m_flatList[ aIndex ];
|
2021-03-06 09:27:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 10:31:53 +00:00
|
|
|
void Clear()
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
m_flatList.clear();
|
2020-09-06 10:31:53 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
size_t GetCount() const { return m_flatList.size(); }
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
SCH_REFERENCE& GetItem( int aIdx ) { return m_flatList[aIdx]; }
|
|
|
|
const SCH_REFERENCE& GetItem( int aIdx ) const { return m_flatList[aIdx]; }
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
void AddItem( const SCH_REFERENCE& aItem ) { m_flatList.push_back( aItem ); }
|
2015-02-21 08:11:58 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Remove an item from the list of references.
|
2015-02-21 08:11:58 +00:00
|
|
|
*
|
|
|
|
* @param aIndex is the index of the item to be removed.
|
|
|
|
*/
|
|
|
|
void RemoveItem( unsigned int aIndex );
|
|
|
|
|
2021-04-11 15:24:11 +00:00
|
|
|
/**
|
|
|
|
* Return true if aItem exists in this list
|
|
|
|
* @param aItem Reference to check
|
|
|
|
* @return true if aItem exists in this list
|
|
|
|
*/
|
2022-04-17 21:23:22 +00:00
|
|
|
bool Contains( const SCH_REFERENCE& aItem ) const;
|
2021-04-11 15:24:11 +00:00
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
/* Sort functions:
|
2020-11-15 16:08:31 +00:00
|
|
|
* Sort functions are used to sort symbols for annotation or BOM generation. Because
|
|
|
|
* sorting depends on what we want to do, there are many sort functions.
|
2015-02-21 08:11:58 +00:00
|
|
|
* Note:
|
2020-11-15 16:08:31 +00:00
|
|
|
* When creating BOM, symbols are fully annotated. References are something like U3,
|
2021-01-26 15:23:37 +00:00
|
|
|
* U5 or R4, R8. When annotating, some or all symbols are not annotated, i.e. ref is
|
2020-11-15 16:08:31 +00:00
|
|
|
* only U or R, with no number.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-03-25 21:13:01 +00:00
|
|
|
* Attempt to split all reference designators into a name (U) and number (1).
|
|
|
|
*
|
|
|
|
* If the last character is '?' or not a digit, the reference is tagged as not annotated.
|
2021-04-27 14:52:32 +00:00
|
|
|
* For symbols with multiple parts, keeps the unit number intact
|
2015-02-21 08:11:58 +00:00
|
|
|
* @see SCH_REFERENCE::Split()
|
|
|
|
*/
|
|
|
|
void SplitReferences()
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < GetCount(); ii++ )
|
2022-10-06 22:39:49 +00:00
|
|
|
m_flatList[ii].Split();
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-17 21:23:22 +00:00
|
|
|
/**
|
|
|
|
* Treat all symbols in this list as non-annotated. Does not update annotation state of the
|
|
|
|
* symbols.
|
|
|
|
* @see SCH_REFERENCE_LIST::UpdateAnnotation
|
|
|
|
*/
|
2023-01-23 21:16:38 +00:00
|
|
|
void RemoveAnnotation()
|
2022-04-17 21:23:22 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < GetCount(); ii++ )
|
2023-01-23 21:16:38 +00:00
|
|
|
m_flatList[ii].m_isNew = true;
|
2022-04-17 21:23:22 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Update the symbol references for the schematic project (or the current sheet).
|
|
|
|
*
|
|
|
|
* @note This function does not calculate the reference numbers stored in m_numRef so it
|
|
|
|
* must be called after calculation of new reference numbers.
|
|
|
|
*
|
2015-02-21 08:11:58 +00:00
|
|
|
* @see SCH_REFERENCE::Annotate()
|
|
|
|
*/
|
|
|
|
void UpdateAnnotation()
|
|
|
|
{
|
|
|
|
/* update the reference numbers */
|
|
|
|
for( unsigned ii = 0; ii < GetCount(); ii++ )
|
2022-10-06 22:39:49 +00:00
|
|
|
m_flatList[ii].Annotate();
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
2021-05-01 22:39:16 +00:00
|
|
|
/**
|
2022-07-19 17:00:24 +00:00
|
|
|
* @brief Forces reannotation of the provided references. Will also reannotate
|
|
|
|
* associated multi-unit symbols.
|
2021-05-01 22:39:16 +00:00
|
|
|
*
|
2022-07-19 17:00:24 +00:00
|
|
|
* @param aSortOption Define the annotation order. See #ANNOTATE_ORDER_T.
|
|
|
|
* @param aAlgoOption Define the annotation style. See #ANNOTATE_ALGO_T.
|
|
|
|
* @param aStartNumber The start number for non-sheet-based annotation styles.
|
2021-05-01 22:39:16 +00:00
|
|
|
* @param aAdditionalReferences Additional references to check for duplicates
|
2022-07-19 17:00:24 +00:00
|
|
|
* @param aStartAtCurrent Use m_numRef for each reference as the start number (overrides
|
|
|
|
* aStartNumber)
|
2022-07-20 15:39:15 +00:00
|
|
|
* @param aHierarchy Optional sheet path hierarchy for resetting the references'
|
|
|
|
* sheet numbers based on their sheet's place in the hierarchy. Set
|
|
|
|
* nullptr if not desired.
|
2021-05-01 22:39:16 +00:00
|
|
|
*/
|
2022-07-19 17:00:24 +00:00
|
|
|
void 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
|
|
|
|
2022-07-19 17:00:24 +00:00
|
|
|
/**
|
|
|
|
* Convenience function for the Paste Unique functionality. Do not use as a general
|
|
|
|
* reannotation method.
|
|
|
|
*
|
|
|
|
* Replaces any duplicate reference designators with the next available number after the
|
|
|
|
* present number regardless of configured annotation options.
|
|
|
|
*
|
|
|
|
* Multi-unit symbols are reannotated together.
|
|
|
|
*/
|
|
|
|
void ReannotateDuplicates( const SCH_REFERENCE_LIST& aAdditionalReferences );
|
2022-07-19 16:13:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Annotate the references by the provided options.
|
|
|
|
*
|
|
|
|
* @param aSortOption Define the annotation order. See #ANNOTATE_ORDER_T.
|
|
|
|
* @param aAlgoOption Define the annotation style. See #ANNOTATE_ALGO_T.
|
|
|
|
* @param aStartNumber The start number for non-sheet-based annotation styles.
|
|
|
|
* @param appendUndo True if the annotation operation should be added to an existing undo,
|
|
|
|
* false if it should be separately undo-able.
|
|
|
|
* @param aLockedUnitMap A SCH_MULTI_UNIT_REFERENCE_MAP of reference designator wxStrings
|
|
|
|
* to SCH_REFERENCE_LISTs. May be an empty map. If not empty, any multi-unit parts
|
|
|
|
* found in this map will be annotated as a group rather than individually.
|
|
|
|
* @param aAdditionalReferences Additional references to check for duplicates
|
|
|
|
* @param aStartAtCurrent Use m_numRef for each reference as the start number (overrides
|
|
|
|
* aStartNumber)
|
|
|
|
*/
|
|
|
|
void AnnotateByOptions( enum ANNOTATE_ORDER_T aSortOption,
|
|
|
|
enum ANNOTATE_ALGO_T aAlgoOption,
|
|
|
|
int aStartNumber,
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap,
|
|
|
|
const SCH_REFERENCE_LIST& aAdditionalRefs,
|
|
|
|
bool aStartAtCurrent );
|
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Set the reference designators in the list that have not been annotated.
|
|
|
|
*
|
2021-03-25 21:13:01 +00:00
|
|
|
* If a the sheet number is 2 and \a aSheetIntervalId is 100, then the first reference
|
|
|
|
* designator would be 201 and the last reference designator would be 299 when no overlap
|
|
|
|
* occurs with sheet number 3. If there are 150 items in sheet number 2, then items are
|
|
|
|
* referenced U201 to U351, and items in sheet 3 start from U352
|
|
|
|
*
|
2015-02-21 08:11:58 +00:00
|
|
|
* @param aUseSheetNum Set to true to start annotation for each sheet at the sheet number
|
|
|
|
* times \a aSheetIntervalId. Otherwise annotate incrementally.
|
|
|
|
* @param aSheetIntervalId The per sheet reference designator multiplier.
|
2018-02-18 20:44:33 +00:00
|
|
|
* @param aStartNumber The number to start with if NOT numbering based on sheet number.
|
2015-03-23 11:45:31 +00:00
|
|
|
* @param aLockedUnitMap A SCH_MULTI_UNIT_REFERENCE_MAP of reference designator wxStrings
|
|
|
|
* to SCH_REFERENCE_LISTs. May be an empty map. If not empty, any multi-unit parts
|
|
|
|
* found in this map will be annotated as a group rather than individually.
|
2021-04-11 15:24:11 +00:00
|
|
|
* @param aAdditionalRefs Additional references to use for checking that there a reference
|
|
|
|
* designator doesn't already exist. The caller must ensure that none of the references
|
|
|
|
* in aAdditionalRefs exist in this list.
|
2021-05-01 22:39:16 +00:00
|
|
|
* @param aStartAtCurrent Use m_numRef for each reference as the start number (overrides
|
|
|
|
aStartNumber)
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
2018-02-18 20:44:33 +00:00
|
|
|
void 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 = false );
|
2015-02-21 08:11:58 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Check for annotations errors.
|
2021-03-25 21:13:01 +00:00
|
|
|
*
|
2015-02-21 08:11:58 +00:00
|
|
|
* The following annotation error conditions are tested:
|
2021-03-25 21:13:01 +00:00
|
|
|
* - Symbols not annotated.
|
|
|
|
* - Symbols having the same reference designator (duplicates).
|
|
|
|
* - Symbols with multiple parts per package having different reference designators.
|
|
|
|
* - Symbols with multiple parts per package with invalid part count.
|
|
|
|
*
|
2021-01-24 22:25:32 +00:00
|
|
|
* @param aErrorHandler A handler for errors.
|
2015-02-21 08:11:58 +00:00
|
|
|
* @return The number of errors found.
|
|
|
|
*/
|
2021-01-24 22:25:32 +00:00
|
|
|
int CheckAnnotation( ANNOTATION_ERROR_HANDLER aErrorHandler );
|
2015-02-21 08:11:58 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Sort the list of references by X position.
|
2021-03-25 21:13:01 +00:00
|
|
|
*
|
2020-11-15 16:08:31 +00:00
|
|
|
* Symbols are sorted as follows:
|
2021-03-25 21:13:01 +00:00
|
|
|
* - Numeric value of reference designator.
|
|
|
|
* - Sheet number.
|
|
|
|
* - X coordinate position.
|
|
|
|
* - Y coordinate position.
|
|
|
|
* - Time stamp.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
|
|
|
void SortByXCoordinate()
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
sort( m_flatList.begin(), m_flatList.end(), sortByXPosition );
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Sort the list of references by Y position.
|
2021-03-25 21:13:01 +00:00
|
|
|
*
|
2020-11-15 16:08:31 +00:00
|
|
|
* Symbols are sorted as follows:
|
2021-03-25 21:13:01 +00:00
|
|
|
* - Numeric value of reference designator.
|
|
|
|
* - Sheet number.
|
|
|
|
* - Y coordinate position.
|
|
|
|
* - X coordinate position.
|
|
|
|
* - Time stamp.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
|
|
|
void SortByYCoordinate()
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
sort( m_flatList.begin(), m_flatList.end(), sortByYPosition );
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Sort the flat list by Time Stamp (sheet path + timestamp).
|
|
|
|
*
|
2015-02-21 08:11:58 +00:00
|
|
|
* Useful to detect duplicate Time Stamps
|
|
|
|
*/
|
|
|
|
void SortByTimeStamp()
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
sort( m_flatList.begin(), m_flatList.end(), sortByTimeStamp );
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Sort the list of references by value.
|
2021-03-25 21:13:01 +00:00
|
|
|
*
|
2020-11-15 16:08:31 +00:00
|
|
|
* Symbols are sorted in the following order:
|
2021-03-25 21:13:01 +00:00
|
|
|
* - Numeric value of reference designator.
|
|
|
|
* - Value of symbol.
|
|
|
|
* - Unit number when symbol has multiple parts.
|
|
|
|
* - Sheet number.
|
|
|
|
* - X coordinate position.
|
|
|
|
* - Y coordinate position.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
|
|
|
void SortByRefAndValue()
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
sort( m_flatList.begin(), m_flatList.end(), sortByRefAndValue );
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Sort the list of references by reference.
|
2021-03-25 21:13:01 +00:00
|
|
|
*
|
2020-11-15 16:08:31 +00:00
|
|
|
* Symbols are sorted in the following order:
|
2021-03-25 21:13:01 +00:00
|
|
|
* - Numeric value of reference designator.
|
|
|
|
* - Unit number when symbol has multiple parts.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
|
|
|
void SortByReferenceOnly()
|
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
sort( m_flatList.begin(), m_flatList.end(), sortByReferenceOnly );
|
2015-02-21 08:11:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 17:31:36 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Search the list for a symbol with a given reference.
|
2020-07-16 17:31:36 +00:00
|
|
|
*/
|
|
|
|
int FindRef( const wxString& aPath ) const;
|
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Search the sorted list of symbols for a another symbol with the same reference and a
|
2020-11-15 16:08:31 +00:00
|
|
|
* given part unit. Use this method to manage symbols with multiple parts per package.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2021-03-25 21:13:01 +00:00
|
|
|
* @param aIndex is the index in aSymbolsList for of given #SCH_REFERENCE item to test.
|
|
|
|
* @param aUnit is the given unit number to search.
|
2022-04-17 21:23:22 +00:00
|
|
|
* @param aIncludeNew true to include references with the "new" flag in the search.
|
2021-03-25 21:13:01 +00:00
|
|
|
* @return index in aSymbolsList if found or -1 if not found.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
2022-04-17 21:23:22 +00:00
|
|
|
int FindUnit( size_t aIndex, int aUnit, bool aIncludeNew = false ) const;
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2020-01-29 16:33:57 +00:00
|
|
|
/**
|
2022-11-03 10:15:23 +00:00
|
|
|
* Search the list for a symbol with the given KIID path (as string).
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2022-11-03 10:15:23 +00:00
|
|
|
* @param aFullPath is the path of the symbol item to search.
|
|
|
|
* @return an index in m_flatList if found or -1 if not found.
|
2020-01-29 16:33:57 +00:00
|
|
|
*/
|
2022-11-03 10:15:23 +00:00
|
|
|
int FindRefByFullPath( const wxString& aFullPath ) const;
|
2020-01-29 16:33:57 +00:00
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Add all the reference designator numbers greater than \a aMinRefId to \a aIdList
|
2015-02-21 08:11:58 +00:00
|
|
|
* skipping the reference at \a aIndex.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2021-03-25 21:13:01 +00:00
|
|
|
* @param aIndex is the current symbol's index to use for reference prefix filtering.
|
|
|
|
* @param aIdList is the buffer to fill.
|
|
|
|
* @param aMinRefId is the minimum ID value to store. All values < aMinRefId are ignored.
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
2022-04-17 21:23:22 +00:00
|
|
|
void GetRefsInUse( int aIndex, std::vector<int>& aIdList, int aMinRefId ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all the unit numbers for a given reference, comparing library reference, value,
|
|
|
|
* reference number and reference prefix.
|
|
|
|
*
|
|
|
|
* @param aRef is the index of a symbol to use for reference prefix and number filtering.
|
|
|
|
*/
|
|
|
|
std::vector<int> GetUnitsMatchingRef( const SCH_REFERENCE& aRef ) const;
|
2015-02-21 08:11:58 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-17 21:23:22 +00:00
|
|
|
* Return the first unused reference number from the properties given in aRef, ensuring
|
|
|
|
* all of the units in aRequiredUnits are also unused.
|
2015-02-21 08:11:58 +00:00
|
|
|
*
|
|
|
|
* @param aIndex The index of the reference item used for the search pattern.
|
|
|
|
* @param aMinValue The minimum value for the current search.
|
2022-04-17 21:23:22 +00:00
|
|
|
* @param aRequiredUnits List of units to ensure are free
|
2015-02-21 08:11:58 +00:00
|
|
|
*/
|
2022-04-17 21:23:22 +00:00
|
|
|
int FindFirstUnusedReference( const SCH_REFERENCE& aRef, int aMinValue,
|
|
|
|
const std::vector<int>& aRequiredUnits ) const;
|
2015-02-21 08:11:58 +00:00
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
std::vector<SCH_SYMBOL_INSTANCE> GetSymbolInstances() const;
|
2021-04-12 19:08:02 +00:00
|
|
|
|
2016-06-24 10:55:54 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void Show( const char* aPrefix = "" )
|
|
|
|
{
|
|
|
|
printf( "%s\n", aPrefix );
|
|
|
|
|
2022-10-06 22:39:49 +00:00
|
|
|
for( unsigned i=0; i < m_flatList.size(); ++i )
|
2016-06-24 10:55:54 +00:00
|
|
|
{
|
2022-10-06 22:39:49 +00:00
|
|
|
SCH_REFERENCE& schref = m_flatList[i];
|
2016-06-24 10:55:54 +00:00
|
|
|
|
|
|
|
printf( " [%-2d] ref:%-8s num:%-3d lib_part:%s\n",
|
2020-11-15 16:08:31 +00:00
|
|
|
i,
|
2022-07-14 16:55:24 +00:00
|
|
|
schref.m_ref.ToStdString().c_str(),
|
2020-11-15 16:08:31 +00:00
|
|
|
schref.m_numRef,
|
|
|
|
TO_UTF8( schref.GetLibPart()->GetName() ) );
|
2016-06-24 10:55:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-05-13 11:06:46 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return a shorthand string representing all the references in the list. For instance,
|
2018-05-13 11:06:46 +00:00
|
|
|
* "R1, R2, R4 - R7, U1"
|
2023-03-03 13:43:40 +00:00
|
|
|
* @param spaced Add spaces between references
|
2018-05-13 11:06:46 +00:00
|
|
|
*/
|
2023-03-15 00:03:57 +00:00
|
|
|
static wxString Shorthand( std::vector<SCH_REFERENCE> aList, const wxString& refDelimiter,
|
|
|
|
const wxString& refRangeDelimiter );
|
2018-05-13 11:06:46 +00:00
|
|
|
|
2020-01-29 16:33:57 +00:00
|
|
|
friend class BACK_ANNOTATION;
|
2018-05-13 11:06:46 +00:00
|
|
|
|
2015-02-21 08:11:58 +00:00
|
|
|
private:
|
|
|
|
static bool sortByRefAndValue( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
|
|
|
|
|
|
|
|
static bool sortByXPosition( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
|
|
|
|
|
|
|
|
static bool sortByYPosition( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
|
|
|
|
|
|
|
|
static bool sortByTimeStamp( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
|
|
|
|
|
|
|
|
static bool sortByReferenceOnly( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Search for the first free reference number in \a aListId of reference numbers in use.
|
|
|
|
*
|
2015-02-21 08:11:58 +00:00
|
|
|
* This function just searches for a hole in a list of incremented numbers, this list must
|
|
|
|
* be sorted by increasing values and each value can be stored only once. The new value
|
|
|
|
* is added to the list.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2015-02-21 08:11:58 +00:00
|
|
|
* @see BuildRefIdInUseList to prepare this list
|
|
|
|
* @param aIdList The buffer that contains the reference numbers in use.
|
|
|
|
* @param aFirstValue The first expected free value
|
|
|
|
* @return The first free (not yet used) value.
|
|
|
|
*/
|
2022-04-17 21:23:22 +00:00
|
|
|
static int createFirstFreeRefId( std::vector<int>& aIdList, int aFirstValue );
|
2020-01-29 16:33:57 +00:00
|
|
|
|
|
|
|
// Used for sorting static sortByTimeStamp function
|
|
|
|
friend class BACK_ANNOTATE;
|
2023-01-03 21:08:36 +00:00
|
|
|
|
|
|
|
std::vector<SCH_REFERENCE> m_flatList;
|
2015-02-21 08:11:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _SCH_REFERENCE_LIST_H_
|