/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2011 jean-pierre Charras
* Copyright (C) 1992-2011 Wayne Stambaugh
* Copyright (C) 1992-2021 KiCad Developers, see authors.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef _SCH_REFERENCE_LIST_H_
#define _SCH_REFERENCE_LIST_H_
#include
#include
#include
#include
#include
#include
#include
* @param aErrorHandler A handler for errors.
* @return The number of errors found.
*/
int CheckAnnotation( ANNOTATION_ERROR_HANDLER aErrorHandler );
/**
* Sort the list of references by X position.
*
* Symbols are sorted as follows:
*
* - Numeric value of reference designator.
* - Sheet number.
* - X coordinate position.
* - Y coordinate position.
* - Time stamp.
*
*
*/
void SortByXCoordinate()
{
sort( flatList.begin(), flatList.end(), sortByXPosition );
}
/**
* Sort the list of references by Y position.
*
* Symbols are sorted as follows:
*
* - Numeric value of reference designator.
* - Sheet number.
* - Y coordinate position.
* - X coordinate position.
* - Time stamp.
*
*
*/
void SortByYCoordinate()
{
sort( flatList.begin(), flatList.end(), sortByYPosition );
}
/**
* Sort the flat list by Time Stamp (sheet path + timestamp).
*
* Useful to detect duplicate Time Stamps
*/
void SortByTimeStamp()
{
sort( flatList.begin(), flatList.end(), sortByTimeStamp );
}
/**
* Sort the list of references by value.
*
* Symbols are sorted in the following order:
*
* - Numeric value of reference designator.
* - Value of symbol.
* - Unit number when symbol has multiple parts.
* - Sheet number.
* - X coordinate position.
* - Y coordinate position.
*
*
*/
void SortByRefAndValue()
{
sort( flatList.begin(), flatList.end(), sortByRefAndValue );
}
/**
* Sort the list of references by reference.
*
* Symbols are sorted in the following order:
*
* - Numeric value of reference designator.
* - Unit number when symbol has multiple parts.
*
*
*/
void SortByReferenceOnly()
{
sort( flatList.begin(), flatList.end(), sortByReferenceOnly );
}
/**
* Search the list for a symbol with a given reference.
*/
int FindRef( const wxString& aPath ) const;
/**
* Search the sorted list of symbols for a another symbol with the same reference and a
* given part unit. Use this method to manage symbols with multiple parts per package.
*
* @param aIndex = index in aSymbolsList for of given SCH_REFERENCE item to test.
* @param aUnit = the given unit number to search
* @return index in aSymbolsList if found or -1 if not found
*/
int FindUnit( size_t aIndex, int aUnit );
/**
* Search the list for a symbol with the given KIID path.
*
* @param aPath path to search
* @return index in aSymbolsList if found or -1 if not found
*/
int FindRefByPath( const wxString& aPath ) const;
/**
* Add all the reference designator numbers greater than \a aMinRefId to \a aIdList
* skipping the reference at \a aIndex.
*
* @param aIndex = the current symbol's index to use for reference prefix filtering.
* @param aIdList = the buffer to fill
* @param aMinRefId = the min id value to store. all values < aMinRefId are ignored
*/
void GetRefsInUse( int aIndex, std::vector< int >& aIdList, int aMinRefId );
/**
* Return the last used (greatest) reference number in the reference list for the prefix
* used by the symbol pointed to by \a aIndex. The symbol list must be sorted.
*
* @param aIndex The index of the reference item used for the search pattern.
* @param aMinValue The minimum value for the current search.
*/
int GetLastReference( int aIndex, int aMinValue );
#if defined(DEBUG)
void Show( const char* aPrefix = "" )
{
printf( "%s\n", aPrefix );
for( unsigned i=0; i < flatList.size(); ++i )
{
SCH_REFERENCE& schref = flatList[i];
printf( " [%-2d] ref:%-8s num:%-3d lib_part:%s\n",
i,
schref.m_ref.c_str(),
schref.m_numRef,
TO_UTF8( schref.GetLibPart()->GetName() ) );
}
}
#endif
/**
* Return a shorthand string representing all the references in the list. For instance,
* "R1, R2, R4 - R7, U1"
*/
static wxString Shorthand( std::vector aList );
friend class BACK_ANNOTATION;
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 );
/**
* Search for the first free reference number in \a aListId of reference numbers in use.
*
* 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.
*
* @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.
*/
int CreateFirstFreeRefId( std::vector& aIdList, int aFirstValue );
// Used for sorting static sortByTimeStamp function
friend class BACK_ANNOTATE;
};
#endif // _SCH_REFERENCE_LIST_H_