kicad/eeschema/annotate.cpp

783 lines
27 KiB
C++
Raw Normal View History

2007-09-20 21:06:49 +00:00
/**************************************/
/* annotate.cpp: component annotation */
/**************************************/
2007-05-06 16:03:28 +00:00
#include <algorithm> // to use sort vector
#include <vector>
#include "fctsys.h"
#include "common.h"
#include "program.h"
#include "libcmp.h"
2007-05-06 16:03:28 +00:00
#include "protos.h"
#include "netlist.h"
2007-05-06 16:03:28 +00:00
/* Local Functions*/
static int AddComponentsInSheetToList( std::vector <OBJ_CMP_TO_LIST>& aComponentsList,
DrawSheetPath* sheet );
static void BreakReference( std::vector <OBJ_CMP_TO_LIST>& aComponentsList );
static void ReAnnotateComponents( std::vector <OBJ_CMP_TO_LIST>& aComponentsList );
static void ComputeReferenceNumber( std::vector <OBJ_CMP_TO_LIST>& aComponentsList );
int GetLastReferenceNumber( int aObjet,
std::vector <OBJ_CMP_TO_LIST>& aComponentsList );
static int ExistUnit( int aObjet, int aUnit,
std::vector <OBJ_CMP_TO_LIST>& aComponentsList );
2007-05-06 16:03:28 +00:00
/******************************************************/
void WinEDA_SchematicFrame::UpdateSheetNumberAndDate()
/******************************************************/
/* Set a sheet number, the sheet count for sheets in the whole schematic
* and update the date in all screens
*/
{
wxString date = GenDate();
EDA_ScreenList s_list;
// Set the date
for( SCH_SCREEN* screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() )
screen->m_Date = date;
// Set sheet counts
SetSheetNumberAndCount();
}
/*****************************************************************************
* Used to annotate the power symbols, before testing erc or computing
* netlist when a component reannotation is not necessary
*
* In order to avoid conflicts the reference number starts with a 0. A
* PWR with id 12 is named PWR12 in global annotation and PWR012 by the
* Power annotation.
****************************************************************************/
void ReAnnotatePowerSymbolsOnly( void )
{
/* Build the screen list (screen, not sheet) */
EDA_SheetList SheetList( NULL );
2007-09-20 21:06:49 +00:00
DrawSheetPath* sheet;
int CmpNumber = 1;
for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
2007-09-20 21:06:49 +00:00
{
EDA_BaseStruct* DrawList = sheet->LastDrawList();
for( ; DrawList != NULL; DrawList = DrawList->Next() )
2007-09-20 21:06:49 +00:00
{
2008-03-20 01:50:21 +00:00
if( DrawList->Type() != TYPE_SCH_COMPONENT )
2007-09-20 21:06:49 +00:00
continue;
2008-04-21 06:34:56 +00:00
SCH_COMPONENT* DrawLibItem =
2008-03-20 01:50:21 +00:00
(SCH_COMPONENT*) DrawList;
EDA_LibComponentStruct* Entry = FindLibPart(
DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
2007-09-20 21:06:49 +00:00
if( (Entry == NULL) || (Entry->m_Options != ENTRY_POWER) )
continue;
//DrawLibItem->ClearAnnotation(sheet); this clears all annotation :(
wxString refstr = DrawLibItem->m_PrefixString;
//str will be "C?" or so after the ClearAnnotation call.
while( refstr.Last() == '?' )
refstr.RemoveLast();
if( !refstr.StartsWith( wxT( "#" ) ) )
refstr = wxT( "#" ) + refstr;
refstr << wxT( "0" ) << CmpNumber;
DrawLibItem->SetRef( sheet, refstr );
2007-09-20 21:06:49 +00:00
CmpNumber++;
}
}
2007-05-06 16:03:28 +00:00
}
/* sort function to annotate items by their position.
2008-04-21 06:34:56 +00:00
* Components are sorted
* by reference
* if same reference: by sheet
* if same sheet, by X pos
* if same X pos, by Y pos
* if same Y pos, by time stamp
2008-04-21 06:34:56 +00:00
*/
static bool AnnotateBy_X_Position( const OBJ_CMP_TO_LIST& item1, const OBJ_CMP_TO_LIST& item2 )
{
int ii = item1.CompareRef( item2 );
if( ii == 0 )
ii = item1.m_SheetPath.Cmp( item2.m_SheetPath );
if( ii == 0 )
ii = item1.m_RootCmp->m_Pos.x - item2.m_RootCmp->m_Pos.x;
if( ii == 0 )
ii = item1.m_RootCmp->m_Pos.y - item2.m_RootCmp->m_Pos.y;
if( ii == 0 )
ii = item1.m_TimeStamp - item2.m_TimeStamp;
return ii < 0;
}
/* sort function to annotate items by their position.
2008-04-21 14:03:20 +00:00
* Components are sorted
* by reference
* if same reference: by sheet
* if same sheet, by Y pos
* if same Y pos, by X pos
* if same X pos, by time stamp
2008-04-21 14:03:20 +00:00
*/
static bool AnnotateBy_Y_Position( const OBJ_CMP_TO_LIST& item1, const OBJ_CMP_TO_LIST& item2 )
2008-04-21 14:03:20 +00:00
{
int ii = item1.CompareRef( item2 );
2008-04-21 14:03:20 +00:00
if( ii == 0 )
ii = item1.m_SheetPath.Cmp( item2.m_SheetPath );
2008-04-21 14:03:20 +00:00
if( ii == 0 )
ii = item1.m_RootCmp->m_Pos.y - item2.m_RootCmp->m_Pos.y;
2008-04-21 14:03:20 +00:00
if( ii == 0 )
ii = item1.m_RootCmp->m_Pos.x - item2.m_RootCmp->m_Pos.x;
2008-04-21 14:03:20 +00:00
if( ii == 0 )
ii = item1.m_TimeStamp - item2.m_TimeStamp;
2008-04-21 14:03:20 +00:00
return ii < 0;
2008-04-21 14:03:20 +00:00
}
/*****************************************************************************
* qsort function to annotate items by value
* Components are sorted
* by reference
* if same reference: by value
* if same value: by unit number
* if same unit number, by sheet
* if same sheet, by time stamp
*****************************************************************************/
static bool AnnotateByValue( const OBJ_CMP_TO_LIST& item1, const OBJ_CMP_TO_LIST& item2 )
2007-05-06 16:03:28 +00:00
{
int ii = item1.CompareRef( item2 );
if( ii == 0 )
ii = item1.CompareValue( item2 );
if( ii == 0 )
ii = item1.m_Unit - item2.m_Unit;
if( ii == 0 )
ii = item1.m_SheetPath.Cmp( item2.m_SheetPath );
if( ii == 0 )
ii = item1.m_RootCmp->m_Pos.x - item2.m_RootCmp->m_Pos.x;
if( ii == 0 )
ii = item1.m_RootCmp->m_Pos.y - item2.m_RootCmp->m_Pos.y;
if( ii == 0 )
ii = item1.m_TimeStamp - item2.m_TimeStamp;
return ii < 0;
2007-05-06 16:03:28 +00:00
}
2008-04-21 06:34:56 +00:00
/**************************************************************************************/
void WinEDA_SchematicFrame::DeleteAnnotation( bool aCurrentSheetOnly, bool aRedraw )
/**************************************************************************************/
/** Function DeleteAnnotation
* Remove current component annotations
* @param aCurrentSheetOnly : if false: remove all annotations, else remove annotation relative to the current sheet only
* @param aRedraw : true to refresh display
*/
{
SCH_ITEM* strct;
SCH_SCREEN* screen;
EDA_ScreenList ScreenList;
2008-04-21 06:34:56 +00:00
screen = ScreenList.GetFirst();
2008-04-21 06:34:56 +00:00
if( aCurrentSheetOnly )
screen = GetScreen();
2008-04-21 06:34:56 +00:00
if( screen == NULL )
return;
while( screen )
{
strct = screen->EEDrawList;
for( ; strct; strct = strct->Next() )
2008-04-21 06:34:56 +00:00
{
if( strct->Type() == TYPE_SCH_COMPONENT )
{
if( aCurrentSheetOnly )
( (SCH_COMPONENT*) strct )->ClearAnnotation( m_CurrentSheet );
else
( (SCH_COMPONENT*) strct )->ClearAnnotation( NULL );
}
}
screen->SetModify();
if( aCurrentSheetOnly )
break;
screen = ScreenList.GetNext();
}
//update the References
m_CurrentSheet->UpdateAllScreenReferences();
if( aRedraw )
DrawPanel->Refresh( true );
}
2007-09-20 21:06:49 +00:00
/*****************************************************************************
* AnnotateComponents:
*
* Compute the annotation of the components for the whole project, or the
* current sheet only. All the components or the new ones only will be
* annotated.
2008-04-12 18:39:20 +00:00
* @param parent = Schematic frame
* @param annotateSchematic : true = entire schematic annotation, false = current scheet only
2008-04-21 14:03:20 +00:00
* @param sortOption : 0 = annotate by sorting X position,
* 1 = annotate by sorting Y position,
* 2 = annotate by sorting value
2008-04-12 18:39:20 +00:00
* @param resetAnnotation : true = remove previous annotation false = anotate new components only
*****************************************************************************/
void AnnotateComponents( WinEDA_SchematicFrame* parent,
bool annotateSchematic,
2008-04-21 14:03:20 +00:00
int sortOption,
bool resetAnnotation )
2007-05-06 16:03:28 +00:00
{
std::vector <OBJ_CMP_TO_LIST> ComponentsList;
2007-09-20 21:06:49 +00:00
wxBusyCursor dummy;
2007-09-20 21:06:49 +00:00
/* If it is an annotation for all the components, reset previous
2008-04-21 06:34:56 +00:00
* annotation: */
if( resetAnnotation )
2008-04-21 06:34:56 +00:00
parent->DeleteAnnotation( !annotateSchematic, false );
2007-09-20 21:06:49 +00:00
/* Build the sheet list */
EDA_SheetList SheetList( g_RootSheet );
2007-09-20 21:06:49 +00:00
/* Update the sheet number, sheet count and date */
parent->UpdateSheetNumberAndDate();
2007-09-20 21:06:49 +00:00
/* Build component list */
if( annotateSchematic )
{
DrawSheetPath* sheet;
for( sheet = SheetList.GetFirst();
sheet != NULL;
sheet = SheetList.GetNext() )
AddComponentsInSheetToList( ComponentsList, sheet );
2007-09-20 21:06:49 +00:00
}
else
AddComponentsInSheetToList( ComponentsList, parent->GetSheet() );
2007-09-20 21:06:49 +00:00
/* Break full components reference in name (prefix) and number:
2008-04-21 06:34:56 +00:00
* example: IC1 become IC, and 1 */
BreakReference( ComponentsList );
2008-04-21 14:03:20 +00:00
switch( sortOption )
{
case 0:
sort( ComponentsList.begin(), ComponentsList.end(), AnnotateBy_X_Position );
2008-04-21 14:03:20 +00:00
break;
2007-09-20 21:06:49 +00:00
2008-04-21 14:03:20 +00:00
case 1:
sort( ComponentsList.begin(), ComponentsList.end(), AnnotateBy_Y_Position );
2008-04-21 14:03:20 +00:00
break;
case 2:
sort( ComponentsList.begin(), ComponentsList.end(), AnnotateByValue );
2008-04-21 14:03:20 +00:00
break;
}
2007-09-20 21:06:49 +00:00
/* Recalculate reference numbers */
ComputeReferenceNumber( ComponentsList );
ReAnnotateComponents( ComponentsList );
2007-09-20 21:06:49 +00:00
/* Final control (just in case ... )*/
CheckAnnotate( parent, !annotateSchematic );
parent->DrawPanel->Refresh( true );
2007-05-06 16:03:28 +00:00
}
/*******************************************************************************************************/
int AddComponentsInSheetToList( std::vector <OBJ_CMP_TO_LIST>& aComponentsList, DrawSheetPath* aSheet )
/********************************************************************************************************/
/** function AddComponentsInSheetToList()
* Add a OBJ_CMP_TO_LIST object in aComponentsList for each component found in sheet
* @param aComponentsList = a std::vector list to fill
* @param the DrawSheetPath sheet to analyse
*/
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
int NbrCmp = 0;
EDA_BaseStruct* DrawList = aSheet->LastDrawList();
2008-04-21 06:34:56 +00:00
SCH_COMPONENT* DrawLibItem;
2007-09-20 21:06:49 +00:00
EDA_LibComponentStruct* Entry;
for( ; DrawList != NULL; DrawList = DrawList->Next() )
2007-09-20 21:06:49 +00:00
{
2008-03-20 01:50:21 +00:00
if( DrawList->Type() == TYPE_SCH_COMPONENT )
2007-09-20 21:06:49 +00:00
{
2008-03-20 01:50:21 +00:00
DrawLibItem = (SCH_COMPONENT*) DrawList;
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(),
wxEmptyString,
FIND_ROOT );
2007-09-20 21:06:49 +00:00
if( Entry == NULL )
continue;
OBJ_CMP_TO_LIST new_object;
new_object.m_RootCmp = DrawLibItem;
new_object.m_Entry = Entry;
new_object.m_Unit = DrawLibItem->GetUnitSelection( aSheet );
new_object.m_SheetPath = *aSheet;
new_object.m_IsNew = false;
new_object.m_Flag = 0;
new_object.m_TimeStamp = DrawLibItem->m_TimeStamp;
if( DrawLibItem->GetRef( aSheet ).IsEmpty() )
DrawLibItem->SetRef( aSheet, wxT( "DefRef?" ) );
strncpy( new_object.m_Reference, CONV_TO_UTF8( DrawLibItem->GetRef( aSheet ) ), 32 );
new_object.m_NumRef = -1;
2007-09-20 21:06:49 +00:00
if( DrawLibItem->GetField( VALUE )->m_Text.IsEmpty() )
DrawLibItem->GetField( VALUE )->m_Text = wxT( "~" );
2007-09-20 21:06:49 +00:00
new_object.m_Value = &DrawLibItem->GetField( VALUE )->m_Text;
aComponentsList.push_back( new_object );
2007-09-20 21:06:49 +00:00
NbrCmp++;
}
}
return NbrCmp;
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
/*****************************************************************************
* Update the reference component for the schematic project (or the current
* sheet)
*****************************************************************************/
static void ReAnnotateComponents( std::vector <OBJ_CMP_TO_LIST>& aComponentsList )
2007-05-06 16:03:28 +00:00
{
/* update the reference numbers */
for( unsigned ii = 0; ii < aComponentsList.size(); ii++ )
2007-09-20 21:06:49 +00:00
{
char* Text = aComponentsList[ii].m_Reference;
SCH_COMPONENT* component = aComponentsList[ii].m_RootCmp;
2007-09-20 21:06:49 +00:00
if( aComponentsList[ii].m_NumRef < 0 )
2007-09-20 21:06:49 +00:00
strcat( Text, "?" );
else
sprintf( Text + strlen( Text ), "%d", aComponentsList[ii].m_NumRef );
2007-09-20 21:06:49 +00:00
component->SetRef( &(aComponentsList[ii].m_SheetPath), CONV_FROM_UTF8( Text ) );
component->m_Multi = aComponentsList[ii].m_Unit;
component->SetUnitSelection( &(aComponentsList[ii].m_SheetPath),
aComponentsList[ii].m_Unit );
2007-09-20 21:06:49 +00:00
}
2007-05-06 16:03:28 +00:00
}
/*****************************************************************************
* Split component reference designators into a name (prefix) and number.
* Example: IC1 becomes IC and 1 in the .m_NumRef member.
* For multi part per package components not already annotated, set .m_Unit
* to a max value (0x7FFFFFFF).
*
* @param aComponentsList = list of component
* @param NbOfCmp = item count in the list
*****************************************************************************/
void BreakReference( std::vector <OBJ_CMP_TO_LIST>& aComponentsList )
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
char* Text;
for( unsigned ii = 0; ii < aComponentsList.size(); ii++ )
2007-09-20 21:06:49 +00:00
{
aComponentsList[ii].m_NumRef = -1;
Text = aComponentsList[ii].m_Reference;
int ll = strlen( Text ) - 1;
2007-09-20 21:06:49 +00:00
if( Text[ll] == '?' )
{
aComponentsList[ii].m_IsNew = true;
if( !aComponentsList[ii].IsPartsLocked() )
aComponentsList[ii].m_Unit = 0x7FFFFFFF;
Text[ll] = 0;
2007-09-21 04:40:12 +00:00
continue;
2007-09-20 21:06:49 +00:00
}
if( isdigit( Text[ll] ) == 0 )
{
aComponentsList[ii].m_IsNew = true;
if( !aComponentsList[ii].IsPartsLocked() )
aComponentsList[ii].m_Unit = 0x7FFFFFFF;
2007-09-20 21:06:49 +00:00
continue;
}
while( ll >= 0 )
{
if( (Text[ll] <= ' ' ) || isdigit( Text[ll] ) )
ll--;
else
{
if( isdigit( Text[ll + 1] ) )
aComponentsList[ii].m_NumRef = atoi( &Text[ll + 1] );
2007-09-20 21:06:49 +00:00
Text[ll + 1] = 0;
break;
}
}
}
2007-05-06 16:03:28 +00:00
}
/*****************************************************************************
* Compute the reference number for components without reference number
* Compute .m_NumRef member
*****************************************************************************/
static void ComputeReferenceNumber( std::vector <OBJ_CMP_TO_LIST>& aComponentsList )
2007-05-06 16:03:28 +00:00
{
int LastReferenceNumber, NumberOfUnits, Unit;
2007-09-20 21:06:49 +00:00
/* Components with an invisible reference (power...) always are re-annotated.
* So set theirs .m_IsNew member to true
*/
for( unsigned ii = 0; ii < aComponentsList.size(); ii++ )
2007-09-20 21:06:49 +00:00
{
if( aComponentsList[ii].m_Reference[0] == '#' )
2007-09-20 21:06:49 +00:00
{
aComponentsList[ii].m_IsNew = true;
aComponentsList[ii].m_NumRef = 0;
2007-09-20 21:06:49 +00:00
}
}
/* calculate index of the first component with the same reference prefix than the current component.
* all of component having the same reference prefix will receive a reference number with consecutives values:
* IC .. will be set to IC4, IC4, IC5 ...
*/
unsigned first = 0;
/* calculate the last used number for this reference prefix: */
LastReferenceNumber = GetLastReferenceNumber( first, aComponentsList );
for( unsigned ii = 0; ii < aComponentsList.size(); ii++ )
2007-09-20 21:06:49 +00:00
{
if( aComponentsList[ii].m_Flag )
2007-09-20 21:06:49 +00:00
continue;
if( aComponentsList[first].CompareRef( aComponentsList[ii] ) != 0 ) /* New reference found: we need a new ref number for this reference */
2007-09-20 21:06:49 +00:00
{
first = ii;
LastReferenceNumber = GetLastReferenceNumber( ii, aComponentsList );
2007-09-20 21:06:49 +00:00
}
/* Annotation of one part per package components (trivial case)*/
if( aComponentsList[ii].m_Entry->m_UnitCount <= 1 )
2007-09-20 21:06:49 +00:00
{
if( aComponentsList[ii].m_IsNew )
2007-09-20 21:06:49 +00:00
{
LastReferenceNumber++;
aComponentsList[ii].m_NumRef = LastReferenceNumber;
2007-09-20 21:06:49 +00:00
}
aComponentsList[ii].m_Unit = 1;
aComponentsList[ii].m_Flag = 1;
aComponentsList[ii].m_IsNew = false;
2007-09-20 21:06:49 +00:00
continue;
}
/* Annotation of multi-part components ( n parts per package )
2008-04-21 06:34:56 +00:00
* (complex case) */
NumberOfUnits = aComponentsList[ii].m_Entry->m_UnitCount;
2007-09-20 21:06:49 +00:00
if( aComponentsList[ii].m_IsNew )
2007-09-20 21:06:49 +00:00
{
LastReferenceNumber++;
aComponentsList[ii].m_NumRef = LastReferenceNumber;
if( !aComponentsList[ii].IsPartsLocked() )
aComponentsList[ii].m_Unit = 1;
aComponentsList[ii].m_Flag = 1;
2007-09-20 21:06:49 +00:00
}
/* search for others units of this component.
* we search for others parts that have the same value and the same reference prefix (ref without ref number)
*/
2007-09-20 21:06:49 +00:00
for( Unit = 1; Unit <= NumberOfUnits; Unit++ )
{
if( aComponentsList[ii].m_Unit == Unit )
2007-09-20 21:06:49 +00:00
continue;
int found = ExistUnit( ii, Unit, aComponentsList );
if( found >= 0 )
continue; /* this unit exists for this reference (unit already annotated) */
2007-09-20 21:06:49 +00:00
/* Search a component to annotate ( same prefix, same value, not annotated) */
for( unsigned jj = ii + 1; jj < aComponentsList.size(); jj++ )
2007-09-20 21:06:49 +00:00
{
if( aComponentsList[jj].m_Flag ) // already tested
continue;
if( aComponentsList[ii].CompareRef( aComponentsList[jj] ) != 0 ) // references are different
2007-09-20 21:06:49 +00:00
continue;
if( aComponentsList[jj].CompareValue( aComponentsList[ii] ) != 0 )
continue; // values are different
if( !aComponentsList[jj].m_IsNew )
2007-09-20 21:06:49 +00:00
continue;
/* Component without reference number found, annotate it if possible */
if( !aComponentsList[jj].IsPartsLocked() || (aComponentsList[jj].m_Unit == Unit) )
2007-09-20 21:06:49 +00:00
{
aComponentsList[jj].m_NumRef = aComponentsList[ii].m_NumRef;
aComponentsList[jj].m_Unit = Unit;
aComponentsList[jj].m_Flag = 1;
aComponentsList[jj].m_IsNew = false;
2007-09-20 21:06:49 +00:00
break;
}
}
}
}
2007-05-06 16:03:28 +00:00
}
/*****************************************************************************
* Search the last used (greatest) reference number in the component list
* for the prefix reference given by Objet
* The component list must be sorted.
*
* @param aObjet = reference item ( aComponentsList[aObjet].m_TextRef is the search pattern)
* @param aComponentsList = list of items
*****************************************************************************/
int GetLastReferenceNumber( int aObjet, std::vector <OBJ_CMP_TO_LIST>& aComponentsList )
2007-05-06 16:03:28 +00:00
{
int LastNumber = 0;
2007-09-20 21:06:49 +00:00
for( unsigned ii = 0; ii < aComponentsList.size(); ii++ )
2007-09-20 21:06:49 +00:00
{
/* Nouveau Identificateur */
if( aComponentsList[aObjet].CompareRef( aComponentsList[ii] ) != 0 )
continue;
if( LastNumber < aComponentsList[ii].m_NumRef )
LastNumber = aComponentsList[ii].m_NumRef;
2007-09-20 21:06:49 +00:00
}
return LastNumber;
2007-05-06 16:03:28 +00:00
}
/*****************************************************************************
* Search in the sorted list of components, for a given componen,t an other component
* with the same reference and a given part unit.
* Mainly used to manage multiple parts per package components
* @param aObjet = index in aComponentsList for the given OBJ_CMP_TO_LIST item to test
* @param Unit = the given unit number to search
* @param aComponentsList = list of items to examine
* @return index in aComponentsList if found or -1 if not found
*****************************************************************************/
static int ExistUnit( int aObjet, int Unit,
std::vector <OBJ_CMP_TO_LIST>& aComponentsList )
2007-05-06 16:03:28 +00:00
{
int NumRef;
NumRef = aComponentsList[aObjet].m_NumRef;
for( unsigned ii = 0; ii < aComponentsList.size(); ii++ )
2007-09-20 21:06:49 +00:00
{
if( aObjet == (int) ii ) // Do not compare with itself !
2007-09-20 21:06:49 +00:00
continue;
if( aComponentsList[ii].m_IsNew ) // Not already with an updated reference
2007-09-20 21:06:49 +00:00
continue;
if( aComponentsList[ii].m_NumRef != NumRef ) // Not the same reference number (like 35 in R35)
continue;
if( aComponentsList[aObjet].CompareRef( aComponentsList[ii] ) != 0 ) // Not the same reference prefix
2007-09-20 21:06:49 +00:00
continue;
if( aComponentsList[ii].m_Unit == Unit ) // A part with the same reference and the given unit is found
2007-09-20 21:06:49 +00:00
{
return ii;
}
}
return -1;
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
/*******************************************************************/
int CheckAnnotate( WinEDA_SchematicFrame* frame, bool oneSheetOnly )
/*******************************************************************/
/**
* Function CheckAnnotate
* Check errors relatives to annotation:
* components not annotated
* components having the same reference (duplicates)
* for multiple parts per package components :
* part number > number of parts
* different values between parts
* @return errors count
* @param oneSheetOnly : true = search is made only in the current sheet
* false = search in whole hierarchy (usual search).
*/
2007-05-06 16:03:28 +00:00
{
int error;
wxString Buff;
wxString msg, cmpref;
2007-09-20 21:06:49 +00:00
/* build the screen list */
EDA_SheetList SheetList( NULL );
2007-09-20 21:06:49 +00:00
std::vector <OBJ_CMP_TO_LIST> ComponentsList;
2007-09-20 21:06:49 +00:00
g_RootSheet->m_AssociatedScreen->SetModify();
2007-09-20 21:06:49 +00:00
/* Build the list of components */
if( !oneSheetOnly )
{
DrawSheetPath* sheet;
for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
AddComponentsInSheetToList( ComponentsList, sheet );
2007-09-20 21:06:49 +00:00
}
else
AddComponentsInSheetToList( ComponentsList, frame->GetSheet() );
sort( ComponentsList.begin(), ComponentsList.end(), AnnotateByValue );
/* Break full components reference in name (prefix) and number: example:
2008-04-21 06:34:56 +00:00
* IC1 become IC, and 1 */
BreakReference( ComponentsList );
2007-09-20 21:06:49 +00:00
/* count not yet annotated items */
2007-09-20 21:06:49 +00:00
error = 0;
int imax = ComponentsList.size() - 1;
for( int ii = 0; ii < imax; ii++ )
2007-09-20 21:06:49 +00:00
{
msg.Empty();
2007-09-21 04:40:12 +00:00
Buff.Empty();
if( ComponentsList[ii].m_IsNew )
2007-09-20 21:06:49 +00:00
{
if( ComponentsList[ii].m_NumRef >= 0 )
Buff << ComponentsList[ii].m_NumRef;
2007-09-20 21:06:49 +00:00
else
Buff = wxT( "?" );
cmpref = CONV_FROM_UTF8( ComponentsList[ii].m_Reference );
msg.Printf( _( "item not annotated: %s%s" ),
cmpref.GetData(), Buff.GetData() );
2007-09-20 21:06:49 +00:00
if( (ComponentsList[ii].m_Unit > 0) && (ComponentsList[ii].m_Unit < 0x7FFFFFFF) )
2007-09-20 21:06:49 +00:00
{
Buff.Printf( _( "( unit %d)" ), ComponentsList[ii].m_Unit );
2007-09-20 21:06:49 +00:00
msg << Buff;
}
DisplayError( frame, msg );
error++;
2007-09-21 04:40:12 +00:00
break;
2007-09-20 21:06:49 +00:00
}
// Annotate error
if( MAX( ComponentsList[ii].m_Entry->m_UnitCount, 1 ) < ComponentsList[ii].m_Unit )
2007-09-20 21:06:49 +00:00
{
if( ComponentsList[ii].m_NumRef >= 0 )
Buff << ComponentsList[ii].m_NumRef;
2007-09-20 21:06:49 +00:00
else
Buff = wxT( "?" );
cmpref = CONV_FROM_UTF8( ComponentsList[ii].m_Reference );
msg.Printf( _( "Error item %s%s" ), cmpref.GetData(),
Buff.GetData() );
2007-09-20 21:06:49 +00:00
Buff.Printf( _( " unit %d and no more than %d parts" ),
ComponentsList[ii].m_Unit, ComponentsList[ii].m_Entry->m_UnitCount );
2007-09-20 21:06:49 +00:00
msg << Buff;
DisplayError( frame, msg );
error++;
2007-09-21 04:40:12 +00:00
break;
2007-09-20 21:06:49 +00:00
}
}
if( error )
return error;
2007-09-21 04:40:12 +00:00
// count the duplicated elements (if all are annotated)
for( int ii = 0; (ii < imax) && (error < 4); ii++ )
2007-09-20 21:06:49 +00:00
{
msg.Empty();
2007-09-21 04:40:12 +00:00
Buff.Empty();
if( (ComponentsList[ii].CompareRef(ComponentsList[ii + 1]) != 0)
|| ( ComponentsList[ii].m_NumRef != ComponentsList[ii + 1].m_NumRef ) )
2007-09-20 21:06:49 +00:00
continue;
/* Same reference found. If same unit, error !
*/
if( ComponentsList[ii].m_Unit == ComponentsList[ii + 1].m_Unit )
2007-09-20 21:06:49 +00:00
{
if( ComponentsList[ii].m_NumRef >= 0 )
Buff << ComponentsList[ii].m_NumRef;
2007-09-20 21:06:49 +00:00
else
Buff = wxT( "?" );
cmpref = CONV_FROM_UTF8( ComponentsList[ii].m_Reference );
2007-09-20 21:06:49 +00:00
msg.Printf( _( "Multiple item %s%s" ),
cmpref.GetData(), Buff.GetData() );
2007-09-20 21:06:49 +00:00
if( (ComponentsList[ii].m_Unit > 0) && (ComponentsList[ii].m_Unit < 0x7FFFFFFF) )
2007-09-20 21:06:49 +00:00
{
Buff.Printf( _( " (unit %d)" ), ComponentsList[ii].m_Unit );
2007-09-20 21:06:49 +00:00
msg << Buff;
}
DisplayError( frame, msg );
error++;
2007-09-21 04:40:12 +00:00
continue;
2007-09-20 21:06:49 +00:00
}
/* Test error if units are different but number of parts per package
* too hight (ex U3 ( 1 part) and we find U3B this is an error) */
if( ComponentsList[ii].m_Entry->m_UnitCount != ComponentsList[ii + 1].m_Entry->m_UnitCount )
2007-09-20 21:06:49 +00:00
{
if( ComponentsList[ii].m_NumRef >= 0 )
Buff << ComponentsList[ii].m_NumRef;
2007-09-20 21:06:49 +00:00
else
Buff = wxT( "?" );
cmpref = CONV_FROM_UTF8( ComponentsList[ii].m_Reference );
msg.Printf( _( "Multiple item %s%s" ),
cmpref.GetData(), Buff.GetData() );
2007-09-20 21:06:49 +00:00
if( (ComponentsList[ii].m_Unit > 0) && (ComponentsList[ii].m_Unit < 0x7FFFFFFF) )
2007-09-20 21:06:49 +00:00
{
Buff.Printf( _( " (unit %d)" ), ComponentsList[ii].m_Unit );
2007-09-20 21:06:49 +00:00
msg << Buff;
}
DisplayError( frame, msg );
error++;
}
/* Error if values are different between units, for the same reference */
int next = ii+1;
if( ComponentsList[ii].CompareValue( ComponentsList[next] ) != 0 )
2007-09-20 21:06:49 +00:00
{
wxString nextcmpref;
cmpref = CONV_FROM_UTF8( ComponentsList[ii].m_Reference );
nextcmpref = CONV_FROM_UTF8( ComponentsList[next].m_Reference );
#if defined (KICAD_GOST)
msg.Printf( _( "Diff values for %s%d.%c (%s) and %s%d.%c (%s)" ),
cmpref.GetData(),
ComponentsList[ii].m_NumRef,
ComponentsList[ii].m_Unit + '1' - 1,
ComponentsList[ii].m_Value->GetData(), nextcmpref.GetData(),
ComponentsList[next].m_NumRef,
ComponentsList[next].m_Unit + '1' - 1,
ComponentsList[next].m_Value->GetData() );
#else
2007-09-20 21:06:49 +00:00
msg.Printf( _( "Diff values for %s%d%c (%s) and %s%d%c (%s)" ),
cmpref.GetData(),
ComponentsList[ii].m_NumRef,
ComponentsList[ii].m_Unit + 'A' - 1,
ComponentsList[ii].m_Value->GetData(), nextcmpref.GetData(),
ComponentsList[next].m_NumRef,
ComponentsList[next].m_Unit + 'A' - 1,
ComponentsList[next].m_Value->GetData() );
#endif
2007-09-20 21:06:49 +00:00
DisplayError( frame, msg );
error++;
}
}
return error;
2007-05-06 16:03:28 +00:00
}