/*
* 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-2018 KiCad Developers, see authors.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file eeschema/sch_reference_list.h
*/
#ifndef _SCH_REFERENCE_LIST_H_
#define _SCH_REFERENCE_LIST_H_
#include
#include
#include
#include
#include
#include
* @param aReporter A sink for error messages. Use NULL_REPORTER if you don't need errors.
* @return The number of errors found.
*/
int CheckAnnotation( REPORTER& aReporter );
/**
* @brief Check components having same references designator. Must be called with references
* sorted by timestamp \ref SortByTimeStamp()
* @param aReporter A sink for error messages. Use NULL_REPORTER if you don't need errors.
* @return The number of errors found.
*/
int checkForDuplicatedElements( REPORTER& aReporter );
/**
* Function sortByXCoordinate
* sorts the list of references by X position.
*
* Components are sorted as follows:
*
* - Numeric value of reference designator.
* - Sheet number.
* - X coordinate position.
* - Y coordinate position.
* - Time stamp.
*
*
*/
void SortByXCoordinate()
{
sort( componentFlatList.begin(), componentFlatList.end(), sortByXPosition );
}
/**
* Function sortByYCoordinate
* sorts the list of references by Y position.
*
* Components are sorted as follows:
*
* - Numeric value of reference designator.
* - Sheet number.
* - Y coordinate position.
* - X coordinate position.
* - Time stamp.
*
*
*/
void SortByYCoordinate()
{
sort( componentFlatList.begin(), componentFlatList.end(), sortByYPosition );
}
/**
* Function SortComponentsByTimeStamp
* sort the flat list by Time Stamp (sheet path + timestamp).
* Useful to detect duplicate Time Stamps
*/
void SortByTimeStamp()
{
sort( componentFlatList.begin(), componentFlatList.end(), sortByTimeStamp );
}
/**
* Function SortByRefAndValue
* sorts the list of references by value.
*
* Components are sorted in the following order:
*
* - Numeric value of reference designator.
* - Value of component.
* - Unit number when component has multiple parts.
* - Sheet number.
* - X coordinate position.
* - Y coordinate position.
*
*
*/
void SortByRefAndValue()
{
sort( componentFlatList.begin(), componentFlatList.end(), sortByRefAndValue );
}
/**
* Function SortByReferenceOnly
* sorts the list of references by reference.
*
* Components are sorted in the following order:
*
* - Numeric value of reference designator.
* - Unit number when component has multiple parts.
*
*
*/
void SortByReferenceOnly()
{
sort( componentFlatList.begin(), componentFlatList.end(), sortByReferenceOnly );
}
/**
* searches the sorted list of components for a another component with the same
* reference and a given part unit. Use this method to manage components with
* multiple parts per package.
* @param aIndex = index in aComponentsList for of given SCH_REFERENCE item to test.
* @param aUnit = the given unit number to search
* @return index in aComponentsList if found or -1 if not found
*/
int FindUnit( size_t aIndex, int aUnit );
/**
* @brief Searches unit with designated path
* @param aPath path to search
* @return index in aComponentsList if found or -1 if not found
*/
int FindRefByPath( const wxString& aPath ) const;
/**
* Function GetRefsInUse
* adds all the reference designator numbers greater than \a aMinRefId to \a aIdList
* skipping the reference at \a aIndex.
* @param aIndex = the current component 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 );
/**
* Function GetLastReference
* returns the last used (greatest) reference number in the reference list
* for the prefix reference given by \a aIndex. The component 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; iGetName() )
);
}
}
#endif
/**
* Function Shorthand
* Returns a shorthand string representing all the references in the list. For instance,
* "R1, R2, R4 - R7, U1"
* @param aList
*/
static wxString Shorthand( std::vector aList );
friend class BACK_ANNOTATION;
private:
/* sort functions used to sort componentFlatList
*/
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 );
/**
* Function CreateFirstFreeRefId
* searches 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_