2007-09-20 21:06:49 +00:00
|
|
|
/**************************************/
|
|
|
|
/* annotate.cpp: component annotation */
|
|
|
|
/**************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "netlist.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
/* Local Functions*/
|
2008-02-27 19:38:16 +00:00
|
|
|
static int ListeComposants( CmpListStruct* BaseListeCmp,
|
2008-02-28 19:27:25 +00:00
|
|
|
DrawSheetPath* sheet );
|
2007-12-03 06:54:19 +00:00
|
|
|
static void BreakReference( CmpListStruct* BaseListeCmp, int NbOfCmp );
|
2007-09-20 21:06:49 +00:00
|
|
|
static void ReAnnotateComponents( CmpListStruct* BaseListeCmp, int NbOfCmp );
|
|
|
|
static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp );
|
2008-02-28 19:27:25 +00:00
|
|
|
int GetLastReferenceNumber( CmpListStruct* Objet,
|
2008-04-21 06:34:56 +00:00
|
|
|
CmpListStruct* BaseListeCmp,
|
|
|
|
int NbOfCmp );
|
2007-09-20 21:06:49 +00:00
|
|
|
static int ExistUnit( CmpListStruct* Objet, int Unit,
|
|
|
|
CmpListStruct* BaseListeCmp, int NbOfCmp );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-02-28 19:27:25 +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();
|
|
|
|
int sheet_number = 1; // sheet 1 is the root sheet
|
|
|
|
DrawSheetPath* sheetpath;
|
|
|
|
|
|
|
|
/* Build the sheet list */
|
|
|
|
EDA_SheetList SheetList( g_RootSheet );
|
|
|
|
int sheet_count = SheetList.GetCount();
|
|
|
|
|
|
|
|
for( sheetpath = SheetList.GetFirst();
|
|
|
|
sheetpath != NULL;
|
|
|
|
sheetpath = SheetList.GetNext() )
|
|
|
|
{
|
|
|
|
// Read all sheets in path, but not the root sheet (jj = 1)
|
|
|
|
for( int jj = 1; jj < sheetpath->m_numSheets; jj++ )
|
|
|
|
{
|
|
|
|
DrawSheetStruct* sheet = sheetpath->m_sheets[jj];
|
|
|
|
sheet->m_SheetNumber = sheet_number++;
|
|
|
|
sheet->m_NumberOfSheets = sheet_count;
|
|
|
|
SCH_SCREEN* screen = sheet->m_AssociatedScreen;
|
|
|
|
if( screen != NULL )
|
|
|
|
{
|
|
|
|
screen->m_NumberOfScreen = sheet_count;
|
|
|
|
screen->m_Date = date;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_RootSheet->m_AssociatedScreen->m_Date = date;
|
|
|
|
g_RootSheet->m_AssociatedScreen->m_NumberOfScreen = sheet_count;
|
|
|
|
g_RootSheet->m_SheetNumber = 1;
|
|
|
|
g_RootSheet->m_NumberOfSheets = sheet_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Used to annotate the power symbols, before testing erc or computing
|
|
|
|
* netlist when a component reannotation is not necessary
|
2007-12-03 06:54:19 +00:00
|
|
|
*
|
2008-02-26 01:07:38 +00:00
|
|
|
* 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 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
/* Build the screen list (screen, not sheet) */
|
2008-02-28 19:27:25 +00:00
|
|
|
EDA_SheetList SheetList( NULL );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
|
2008-02-28 19:27:25 +00:00
|
|
|
DrawSheetPath* sheet;
|
2008-02-26 01:07:38 +00:00
|
|
|
int CmpNumber = 1;
|
|
|
|
|
|
|
|
for( sheet = SheetList.GetFirst();
|
2008-02-28 19:27:25 +00:00
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
EDA_BaseStruct* DrawList = sheet->LastDrawList();
|
2007-09-20 21:06:49 +00:00
|
|
|
for( ; DrawList != NULL; DrawList = DrawList->Pnext )
|
|
|
|
{
|
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;
|
2007-09-20 21:06:49 +00:00
|
|
|
EDA_LibComponentStruct* Entry =
|
2008-02-26 01:07:38 +00:00
|
|
|
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;
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
//DrawLibItem->ClearAnnotation(sheet); this clears all annotation :(
|
2008-02-26 01:07:38 +00:00
|
|
|
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
|
|
|
}
|
2008-02-26 01:07:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
CmpListStruct* AllocateCmpListStrct( int numcomponents )
|
|
|
|
{
|
2008-04-21 06:34:56 +00:00
|
|
|
int ii = numcomponents * sizeof(CmpListStruct);
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2008-04-21 06:34:56 +00:00
|
|
|
//allocate memory and fill this memory with zeros.
|
|
|
|
CmpListStruct* list = (CmpListStruct*) MyZMalloc( ii );
|
2008-02-26 01:07:38 +00:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-12 18:39:20 +00:00
|
|
|
/* qsort 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 14:03:20 +00:00
|
|
|
int AnnotateBy_X_Position( const void* o1, const void* o2 )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2008-02-26 01:07:38 +00:00
|
|
|
CmpListStruct* item1 = (CmpListStruct*) o1;
|
|
|
|
CmpListStruct* item2 = (CmpListStruct*) o2;
|
|
|
|
|
2008-02-28 19:27:25 +00:00
|
|
|
int ii = strnicmp( item1->m_TextRef, item2->m_TextRef, 32 );
|
2008-02-26 01:07:38 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_SheetList.Cmp( item2->m_SheetList );
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_Pos.x - item2->m_Pos.x;
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_Pos.y - item2->m_Pos.y;
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_TimeStamp - item2->m_TimeStamp;
|
|
|
|
|
|
|
|
return ii;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
|
2008-04-21 14:03:20 +00:00
|
|
|
/* qsort function to annotate items by their position.
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
int AnnotateBy_Y_Position( const void* o1, const void* o2 )
|
|
|
|
{
|
|
|
|
CmpListStruct* item1 = (CmpListStruct*) o1;
|
|
|
|
CmpListStruct* item2 = (CmpListStruct*) o2;
|
|
|
|
|
|
|
|
int ii = strnicmp( item1->m_TextRef, item2->m_TextRef, 32 );
|
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_SheetList.Cmp( item2->m_SheetList );
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_Pos.y - item2->m_Pos.y;
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_Pos.x - item2->m_Pos.x;
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_TimeStamp - item2->m_TimeStamp;
|
|
|
|
|
|
|
|
return ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
2008-02-28 19:27:25 +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
|
|
|
|
*****************************************************************************/
|
2008-02-26 01:07:38 +00:00
|
|
|
int AnnotateByValue( const void* o1, const void* o2 )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-02-26 01:07:38 +00:00
|
|
|
CmpListStruct* item1 = (CmpListStruct*) o1;
|
|
|
|
CmpListStruct* item2 = (CmpListStruct*) o2;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-28 19:27:25 +00:00
|
|
|
int ii = strnicmp( item1->m_TextRef, item2->m_TextRef, 32 );
|
2008-02-26 01:07:38 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = strnicmp( item1->m_TextValue, item2->m_TextValue, 32 );
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_Unit - item2->m_Unit;
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_SheetList.Cmp( item2->m_SheetList );
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_Pos.x - item2->m_Pos.x;
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_Pos.y - item2->m_Pos.y;
|
|
|
|
if( ii == 0 )
|
|
|
|
ii = item1->m_TimeStamp - item2->m_TimeStamp;
|
|
|
|
|
|
|
|
return ii;
|
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
|
|
|
|
*/
|
2008-02-26 01:07:38 +00:00
|
|
|
{
|
2008-04-21 06:34:56 +00:00
|
|
|
EDA_BaseStruct* strct;
|
|
|
|
SCH_SCREEN* screen;
|
|
|
|
EDA_ScreenList ScreenList;
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2008-04-21 06:34:56 +00:00
|
|
|
screen = ScreenList.GetFirst();
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2008-04-21 06:34:56 +00:00
|
|
|
if( aCurrentSheetOnly )
|
|
|
|
screen = GetScreen();
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2008-04-21 06:34:56 +00:00
|
|
|
if( screen == NULL )
|
|
|
|
return;
|
|
|
|
while( screen )
|
|
|
|
{
|
|
|
|
strct = screen->EEDrawList;
|
|
|
|
for( ; strct; strct = strct->Pnext )
|
|
|
|
{
|
|
|
|
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 );
|
2008-02-26 01:07:38 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
2008-02-28 19:27:25 +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
|
2008-02-28 19:27:25 +00:00
|
|
|
*****************************************************************************/
|
2008-02-26 01:07:38 +00:00
|
|
|
void AnnotateComponents( WinEDA_SchematicFrame* parent,
|
2008-02-28 19:27:25 +00:00
|
|
|
bool annotateSchematic,
|
2008-04-21 14:03:20 +00:00
|
|
|
int sortOption,
|
2008-02-28 19:27:25 +00:00
|
|
|
bool resetAnnotation )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
int ii, NbOfCmp;
|
2008-02-28 19:27:25 +00:00
|
|
|
DrawSheetPath* sheet;
|
2007-09-20 21:06:49 +00:00
|
|
|
CmpListStruct* BaseListeCmp;
|
|
|
|
|
|
|
|
wxBusyCursor dummy;
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/* If it is an annotation for all the components, reset previous
|
2008-04-21 06:34:56 +00:00
|
|
|
* annotation: */
|
2008-02-26 01:07:38 +00:00
|
|
|
if( resetAnnotation )
|
2008-04-21 06:34:56 +00:00
|
|
|
parent->DeleteAnnotation( !annotateSchematic, false );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
/* Build the sheet list */
|
2008-02-26 01:07:38 +00:00
|
|
|
EDA_SheetList SheetList( g_RootSheet );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-28 19:27:25 +00:00
|
|
|
/* Update the sheet number, sheet count and date */
|
|
|
|
parent->UpdateSheetNumberAndDate();
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
/* First pass: Component counting */
|
2008-02-28 19:27:25 +00:00
|
|
|
ii = 0;
|
2008-02-26 01:07:38 +00:00
|
|
|
sheet = parent->GetSheet();
|
|
|
|
if( annotateSchematic )
|
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
NbOfCmp = 0;
|
2008-02-26 01:07:38 +00:00
|
|
|
for( sheet = SheetList.GetFirst();
|
2008-02-28 19:27:25 +00:00
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2008-02-12 21:12:46 +00:00
|
|
|
NbOfCmp += ListeComposants( NULL, sheet );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else
|
2008-02-12 21:12:46 +00:00
|
|
|
NbOfCmp = ListeComposants( NULL, sheet );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
if( NbOfCmp == 0 )
|
|
|
|
return;
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
BaseListeCmp = AllocateCmpListStrct( NbOfCmp );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
/* Second pass : Init data tables */
|
2008-02-26 01:07:38 +00:00
|
|
|
if( annotateSchematic )
|
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
ii = 0;
|
2008-02-26 01:07:38 +00:00
|
|
|
for( sheet = SheetList.GetFirst();
|
2008-02-28 19:27:25 +00:00
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2008-02-26 01:07:38 +00:00
|
|
|
ii += ListeComposants( BaseListeCmp + ii, sheet );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else
|
2008-02-26 01:07:38 +00:00
|
|
|
ii = ListeComposants( BaseListeCmp, sheet );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
if( ii != NbOfCmp )
|
2008-02-26 01:07:38 +00:00
|
|
|
DisplayError( parent, wxT( "Internal error in AnnotateComponents()" ) );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-26 01:07:38 +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 */
|
2007-09-20 21:06:49 +00:00
|
|
|
BreakReference( BaseListeCmp, NbOfCmp );
|
2008-04-21 14:03:20 +00:00
|
|
|
wxString msg1;
|
|
|
|
msg1 << sortOption;
|
|
|
|
wxMessageBox(msg1);
|
|
|
|
switch( sortOption )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
qsort( BaseListeCmp, NbOfCmp, sizeof(CmpListStruct),
|
|
|
|
( int( * ) ( const void*, const void* ) )AnnotateBy_X_Position );
|
|
|
|
break;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-04-21 14:03:20 +00:00
|
|
|
case 1:
|
2008-02-26 01:07:38 +00:00
|
|
|
qsort( BaseListeCmp, NbOfCmp, sizeof(CmpListStruct),
|
2008-04-21 14:03:20 +00:00
|
|
|
( int( * ) ( const void*, const void* ) )AnnotateBy_Y_Position );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2008-02-26 01:07:38 +00:00
|
|
|
qsort( BaseListeCmp, NbOfCmp, sizeof(CmpListStruct),
|
2008-04-21 06:34:56 +00:00
|
|
|
( int( * ) ( const void*, const void* ) )AnnotateByValue );
|
2008-04-21 14:03:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
/* Recalculate reference numbers */
|
2007-09-20 21:06:49 +00:00
|
|
|
ComputeReferenceNumber( BaseListeCmp, NbOfCmp );
|
|
|
|
ReAnnotateComponents( BaseListeCmp, NbOfCmp );
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
MyFree( BaseListeCmp );
|
|
|
|
BaseListeCmp = NULL;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
/* Final control */
|
2008-02-26 01:07:38 +00:00
|
|
|
CheckAnnotate( parent, !annotateSchematic );
|
|
|
|
parent->DrawPanel->Refresh( true );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
2008-02-28 19:27:25 +00:00
|
|
|
* if BaseListeCmp == NULL : count components
|
|
|
|
* else update data table BaseListeCmp
|
|
|
|
*****************************************************************************/
|
|
|
|
int ListeComposants( CmpListStruct* BaseListeCmp, DrawSheetPath* sheet )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
int NbrCmp = 0;
|
2008-02-12 21:12:46 +00:00
|
|
|
EDA_BaseStruct* DrawList = sheet->LastDrawList();
|
2008-04-21 06:34:56 +00:00
|
|
|
SCH_COMPONENT* DrawLibItem;
|
2007-09-20 21:06:49 +00:00
|
|
|
EDA_LibComponentStruct* Entry;
|
|
|
|
|
2007-09-21 04:40:12 +00:00
|
|
|
for( ; DrawList; DrawList = DrawList->Pnext )
|
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;
|
2008-02-26 01:07:38 +00:00
|
|
|
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(),
|
2008-02-28 19:27:25 +00:00
|
|
|
wxEmptyString,
|
|
|
|
FIND_ROOT );
|
2007-09-20 21:06:49 +00:00
|
|
|
if( Entry == NULL )
|
2008-02-26 01:07:38 +00:00
|
|
|
continue;
|
2007-12-03 06:54:19 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
if( BaseListeCmp == NULL ) /* Items counting only */
|
|
|
|
{
|
2007-12-03 06:54:19 +00:00
|
|
|
NbrCmp++;
|
2008-02-26 01:07:38 +00:00
|
|
|
continue;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2007-12-03 06:54:19 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
BaseListeCmp[NbrCmp].m_Cmp = DrawLibItem;
|
|
|
|
BaseListeCmp[NbrCmp].m_NbParts = Entry->m_UnitCount;
|
2008-04-21 06:34:56 +00:00
|
|
|
BaseListeCmp[NbrCmp].m_Unit = DrawLibItem->GetUnitSelection( sheet ); // DrawLibItem->m_Multi;
|
2007-09-20 21:06:49 +00:00
|
|
|
BaseListeCmp[NbrCmp].m_PartsLocked = Entry->m_UnitSelectionLocked;
|
2008-02-26 01:07:38 +00:00
|
|
|
BaseListeCmp[NbrCmp].m_SheetList = *sheet;
|
2007-09-20 21:06:49 +00:00
|
|
|
BaseListeCmp[NbrCmp].m_IsNew = FALSE;
|
2007-12-03 06:54:19 +00:00
|
|
|
BaseListeCmp[NbrCmp].m_Pos = DrawLibItem->m_Pos;
|
|
|
|
BaseListeCmp[NbrCmp].m_TimeStamp = DrawLibItem->m_TimeStamp;
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
if( DrawLibItem->GetRef( sheet ).IsEmpty() )
|
|
|
|
DrawLibItem->SetRef( sheet, wxT( "DefRef?" ) );
|
2007-12-03 06:54:19 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
strncpy( BaseListeCmp[NbrCmp].m_TextRef,
|
2008-02-28 19:27:25 +00:00
|
|
|
CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ), 32 );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
BaseListeCmp[NbrCmp].m_NumRef = -1;
|
|
|
|
|
|
|
|
if( DrawLibItem->m_Field[VALUE].m_Text.IsEmpty() )
|
|
|
|
DrawLibItem->m_Field[VALUE].m_Text = wxT( "~" );
|
2007-12-03 06:54:19 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
strncpy( BaseListeCmp[NbrCmp].m_TextValue,
|
2008-02-28 19:27:25 +00:00
|
|
|
CONV_TO_UTF8( DrawLibItem->m_Field[VALUE].m_Text ), 32 );
|
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
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
2008-02-28 19:27:25 +00:00
|
|
|
* Update the reference component for the schematic project (or the current
|
|
|
|
* sheet)
|
|
|
|
*****************************************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
static void ReAnnotateComponents( CmpListStruct* BaseListeCmp, int NbOfCmp )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-04-21 06:34:56 +00:00
|
|
|
int ii;
|
|
|
|
char* Text;
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* DrawLibItem;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
/* Reattribution des numeros */
|
|
|
|
for( ii = 0; ii < NbOfCmp; ii++ )
|
|
|
|
{
|
|
|
|
Text = BaseListeCmp[ii].m_TextRef;
|
|
|
|
DrawLibItem = BaseListeCmp[ii].m_Cmp;
|
|
|
|
|
|
|
|
if( BaseListeCmp[ii].m_NumRef < 0 )
|
|
|
|
strcat( Text, "?" );
|
|
|
|
else
|
|
|
|
sprintf( Text + strlen( Text ), "%d", BaseListeCmp[ii].m_NumRef );
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
DrawLibItem->SetRef( &(BaseListeCmp[ii].m_SheetList),
|
2008-02-28 19:27:25 +00:00
|
|
|
CONV_FROM_UTF8( Text ) );
|
2007-09-20 21:06:49 +00:00
|
|
|
DrawLibItem->m_Multi = BaseListeCmp[ii].m_Unit;
|
2008-04-16 08:40:31 +00:00
|
|
|
DrawLibItem->SetUnitSelection( &(BaseListeCmp[ii].m_SheetList), DrawLibItem->m_Multi );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
2008-02-28 19:27:25 +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 BaseListeCmp = list of component
|
|
|
|
* @param NbOfCmp = item count in the list
|
|
|
|
*****************************************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
void BreakReference( CmpListStruct* BaseListeCmp, int NbOfCmp )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
int ii, ll;
|
|
|
|
char* Text;
|
|
|
|
|
|
|
|
for( ii = 0; ii < NbOfCmp; ii++ )
|
|
|
|
{
|
|
|
|
BaseListeCmp[ii].m_NumRef = -1;
|
|
|
|
Text = BaseListeCmp[ii].m_TextRef;
|
|
|
|
ll = strlen( Text ) - 1;
|
|
|
|
if( Text[ll] == '?' )
|
|
|
|
{
|
2007-12-03 06:54:19 +00:00
|
|
|
BaseListeCmp[ii].m_IsNew = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
if( !BaseListeCmp[ii].m_PartsLocked )
|
|
|
|
BaseListeCmp[ii].m_Unit = 0x7FFFFFFF;
|
2007-12-03 06:54:19 +00:00
|
|
|
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 )
|
|
|
|
{
|
2007-12-03 06:54:19 +00:00
|
|
|
BaseListeCmp[ii].m_IsNew = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
if( !BaseListeCmp[ii].m_PartsLocked )
|
|
|
|
BaseListeCmp[ii].m_Unit = 0x7FFFFFFF;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( ll >= 0 )
|
|
|
|
{
|
|
|
|
if( (Text[ll] <= ' ' ) || isdigit( Text[ll] ) )
|
|
|
|
ll--;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( isdigit( Text[ll + 1] ) )
|
|
|
|
BaseListeCmp[ii].m_NumRef = atoi( &Text[ll + 1] );
|
|
|
|
Text[ll + 1] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
2008-02-28 19:27:25 +00:00
|
|
|
* Compute the reference number for components without reference number
|
|
|
|
* Compute .m_NumRef member
|
|
|
|
*****************************************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
int ii, jj, LastReferenceNumber, NumberOfUnits, Unit;
|
2007-12-03 06:54:19 +00:00
|
|
|
const char* Text, * RefText, * ValText;
|
2007-09-20 21:06:49 +00:00
|
|
|
CmpListStruct* ObjRef, * ObjToTest;
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/* Components with an invisible reference (power...) always are
|
|
|
|
* re-annotated */
|
2007-09-20 21:06:49 +00:00
|
|
|
for( ii = 0; ii < NbOfCmp; ii++ )
|
|
|
|
{
|
|
|
|
Text = BaseListeCmp[ii].m_TextRef;
|
|
|
|
if( *Text == '#' )
|
|
|
|
{
|
2007-12-03 06:54:19 +00:00
|
|
|
BaseListeCmp[ii].m_IsNew = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
BaseListeCmp[ii].m_NumRef = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ValText = RefText = ""; LastReferenceNumber = 1;
|
|
|
|
for( ii = 0; ii < NbOfCmp; ii++ )
|
|
|
|
{
|
|
|
|
ObjRef = &BaseListeCmp[ii];
|
|
|
|
if( BaseListeCmp[ii].m_Flag )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Text = BaseListeCmp[ii].m_TextRef;
|
|
|
|
if( strnicmp( RefText, Text, 32 ) != 0 ) /* Nouveau Identificateur */
|
|
|
|
{
|
|
|
|
RefText = BaseListeCmp[ii].m_TextRef;
|
2008-02-26 01:07:38 +00:00
|
|
|
LastReferenceNumber = GetLastReferenceNumber( BaseListeCmp + ii,
|
2008-02-28 19:27:25 +00:00
|
|
|
BaseListeCmp,
|
|
|
|
NbOfCmp );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
/* Annotation of one part per package components (trivial case)*/
|
2007-09-20 21:06:49 +00:00
|
|
|
if( BaseListeCmp[ii].m_NbParts <= 1 )
|
|
|
|
{
|
|
|
|
if( BaseListeCmp[ii].m_IsNew )
|
|
|
|
{
|
|
|
|
LastReferenceNumber++;
|
|
|
|
BaseListeCmp[ii].m_NumRef = LastReferenceNumber;
|
|
|
|
}
|
|
|
|
BaseListeCmp[ii].m_Unit = 1;
|
|
|
|
BaseListeCmp[ii].m_Flag = 1;
|
|
|
|
BaseListeCmp[ii].m_IsNew = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/* Annotation of multi-part components ( n parts per package )
|
2008-04-21 06:34:56 +00:00
|
|
|
* (complex case) */
|
2007-09-20 21:06:49 +00:00
|
|
|
ValText = BaseListeCmp[ii].m_TextValue;
|
|
|
|
NumberOfUnits = BaseListeCmp[ii].m_NbParts;
|
|
|
|
|
|
|
|
if( BaseListeCmp[ii].m_IsNew )
|
|
|
|
{
|
2008-02-26 01:07:38 +00:00
|
|
|
LastReferenceNumber++;
|
|
|
|
BaseListeCmp[ii].m_NumRef = LastReferenceNumber;
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
if( !BaseListeCmp[ii].m_PartsLocked )
|
|
|
|
BaseListeCmp[ii].m_Unit = 1;
|
|
|
|
BaseListeCmp[ii].m_Flag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( Unit = 1; Unit <= NumberOfUnits; Unit++ )
|
|
|
|
{
|
|
|
|
if( BaseListeCmp[ii].m_Unit == Unit )
|
|
|
|
continue;
|
|
|
|
jj = ExistUnit( BaseListeCmp + ii, Unit, BaseListeCmp, NbOfCmp );
|
|
|
|
if( jj >= 0 )
|
2007-12-03 06:54:19 +00:00
|
|
|
continue; /* Unit exists for this reference */
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
/* Search a component to annotate ( same prefix, same value) */
|
|
|
|
for( jj = ii + 1; jj < NbOfCmp; jj++ )
|
|
|
|
{
|
|
|
|
ObjToTest = &BaseListeCmp[jj];
|
|
|
|
if( BaseListeCmp[jj].m_Flag )
|
|
|
|
continue;
|
|
|
|
Text = BaseListeCmp[jj].m_TextRef;
|
|
|
|
if( strnicmp( RefText, Text, 32 ) != 0 )
|
2007-12-03 06:54:19 +00:00
|
|
|
continue; // references are different
|
2007-09-20 21:06:49 +00:00
|
|
|
Text = BaseListeCmp[jj].m_TextValue;
|
|
|
|
if( strnicmp( ValText, Text, 32 ) != 0 )
|
2007-12-03 06:54:19 +00:00
|
|
|
continue; // values are different
|
2007-09-20 21:06:49 +00:00
|
|
|
if( !BaseListeCmp[jj].m_IsNew )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2008-02-28 19:27:25 +00:00
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/* Component without reference number found, annotate it if
|
2008-04-21 06:34:56 +00:00
|
|
|
* possible */
|
2008-02-28 19:27:25 +00:00
|
|
|
if( !BaseListeCmp[jj].m_PartsLocked
|
|
|
|
|| (BaseListeCmp[jj].m_Unit == Unit) )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
|
|
|
BaseListeCmp[jj].m_NumRef = BaseListeCmp[ii].m_NumRef;
|
|
|
|
BaseListeCmp[jj].m_Unit = Unit;
|
|
|
|
BaseListeCmp[jj].m_Flag = 1;
|
|
|
|
BaseListeCmp[jj].m_IsNew = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
2008-02-28 19:27:25 +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 Objet = reference item ( Objet->m_TextRef is the search pattern)
|
|
|
|
* @param BaseListeCmp = list of items
|
|
|
|
* @param NbOfCmp = items count in list of items
|
|
|
|
*****************************************************************************/
|
2008-02-26 01:07:38 +00:00
|
|
|
int GetLastReferenceNumber( CmpListStruct* Objet,
|
|
|
|
CmpListStruct* BaseListeCmp,
|
2008-02-28 19:27:25 +00:00
|
|
|
int NbOfCmp )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
CmpListStruct* LastObjet = BaseListeCmp + NbOfCmp;
|
|
|
|
int LastNumber = 0;
|
|
|
|
const char* RefText;
|
|
|
|
|
|
|
|
RefText = Objet->m_TextRef;
|
|
|
|
for( ; Objet < LastObjet; Objet++ )
|
|
|
|
{
|
2008-02-26 01:07:38 +00:00
|
|
|
/* Nouveau Identificateur */
|
|
|
|
if( strnicmp( RefText, Objet->m_TextRef, 32 ) != 0 )
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
if( LastNumber < Objet->m_NumRef )
|
|
|
|
LastNumber = Objet->m_NumRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LastNumber;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
2008-04-16 08:40:31 +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 Objet = the given CmpListStruct* item to test
|
|
|
|
* @param Unit = the given unit number to search
|
|
|
|
* @param BaseListeCmp = list of items to examine
|
|
|
|
* @param NbOfCmp = size of list
|
|
|
|
* @return index in BaseListeCmp if found or -1 if not found
|
2008-02-28 19:27:25 +00:00
|
|
|
*****************************************************************************/
|
2008-02-26 01:07:38 +00:00
|
|
|
static int ExistUnit( CmpListStruct* Objet, int Unit,
|
|
|
|
CmpListStruct* BaseListeCmp, int NbOfCmp )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
CmpListStruct* EndList = BaseListeCmp + NbOfCmp;
|
|
|
|
char* RefText, * ValText;
|
|
|
|
int NumRef, ii;
|
|
|
|
CmpListStruct* ItemToTest;
|
|
|
|
|
|
|
|
RefText = Objet->m_TextRef;
|
|
|
|
ValText = Objet->m_TextValue;
|
|
|
|
NumRef = Objet->m_NumRef;
|
2008-02-26 01:07:38 +00:00
|
|
|
for( ItemToTest = BaseListeCmp, ii = 0;
|
|
|
|
ItemToTest < EndList;
|
|
|
|
ItemToTest++, ii++ )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2008-04-21 06:34:56 +00:00
|
|
|
if( Objet == ItemToTest ) // Do not compare with itself !
|
2007-09-20 21:06:49 +00:00
|
|
|
continue;
|
2008-04-21 06:34:56 +00:00
|
|
|
if( ItemToTest->m_IsNew ) // Not already with an updated reference
|
2007-09-20 21:06:49 +00:00
|
|
|
continue;
|
2008-04-21 06:34:56 +00:00
|
|
|
if( ItemToTest->m_NumRef != NumRef ) // Not the same reference number (like 35 in R35)
|
2008-04-16 08:40:31 +00:00
|
|
|
continue;
|
|
|
|
if( strnicmp( RefText, ItemToTest->m_TextRef, 32 ) != 0 ) // Not the same reference prefix
|
2007-09-20 21:06:49 +00:00
|
|
|
continue;
|
2008-04-21 06:34:56 +00:00
|
|
|
if( ItemToTest->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
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/*****************************************************************************
|
2008-02-28 19:27:25 +00:00
|
|
|
*
|
|
|
|
* Function CheckAnnotate
|
|
|
|
* @return component count ( which are not annotated or have the same
|
|
|
|
* reference (duplicates))
|
|
|
|
* @param oneSheetOnly : true = search is made only in the current sheet
|
|
|
|
* false = search in whole hierarchy (usual search).
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2008-02-26 01:07:38 +00:00
|
|
|
int CheckAnnotate( WinEDA_SchematicFrame* frame, bool oneSheetOnly )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
int ii, error, NbOfCmp;
|
2008-02-28 19:27:25 +00:00
|
|
|
DrawSheetPath* sheet;
|
2007-09-20 21:06:49 +00:00
|
|
|
CmpListStruct* ListeCmp = NULL;
|
|
|
|
wxString Buff;
|
|
|
|
wxString msg, cmpref;
|
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
/* build the screen list */
|
2008-02-26 01:07:38 +00:00
|
|
|
EDA_SheetList SheetList( NULL );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
g_RootSheet->m_AssociatedScreen->SetModify();
|
2008-02-26 01:07:38 +00:00
|
|
|
ii = 0;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
/* first pass : count composents */
|
2008-02-26 01:07:38 +00:00
|
|
|
if( !oneSheetOnly )
|
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
NbOfCmp = 0;
|
2008-02-26 01:07:38 +00:00
|
|
|
for( sheet = SheetList.GetFirst();
|
2008-02-28 19:27:25 +00:00
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2008-02-12 21:12:46 +00:00
|
|
|
NbOfCmp += ListeComposants( NULL, sheet );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else
|
2008-02-26 01:07:38 +00:00
|
|
|
NbOfCmp = ListeComposants( NULL, frame->GetSheet() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
if( NbOfCmp == 0 )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
|
|
|
|
/* Second pass : create the list of components */
|
2008-02-26 01:07:38 +00:00
|
|
|
ListeCmp = AllocateCmpListStrct( NbOfCmp );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
if( !oneSheetOnly )
|
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
ii = 0;
|
2008-02-26 01:07:38 +00:00
|
|
|
for( sheet = SheetList.GetFirst();
|
2008-02-28 19:27:25 +00:00
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2008-02-12 21:12:46 +00:00
|
|
|
ii += ListeComposants( ListeCmp + ii, sheet );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else
|
2008-02-26 01:07:38 +00:00
|
|
|
ListeComposants( ListeCmp, frame->GetSheet() );
|
|
|
|
|
|
|
|
qsort( ListeCmp, NbOfCmp, sizeof(CmpListStruct), AnnotateByValue );
|
|
|
|
|
|
|
|
/* Break full components reference in name (prefix) and number: example:
|
2008-04-21 06:34:56 +00:00
|
|
|
* IC1 become IC, and 1 */
|
2007-09-20 21:06:49 +00:00
|
|
|
BreakReference( ListeCmp, NbOfCmp );
|
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
/* count not yet annotated items */
|
2007-09-20 21:06:49 +00:00
|
|
|
error = 0;
|
|
|
|
for( ii = 0; ii < NbOfCmp - 1; ii++ )
|
|
|
|
{
|
2007-12-03 06:54:19 +00:00
|
|
|
msg.Empty();
|
2007-09-21 04:40:12 +00:00
|
|
|
Buff.Empty();
|
2007-12-03 06:54:19 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
if( ListeCmp[ii].m_IsNew )
|
|
|
|
{
|
|
|
|
if( ListeCmp[ii].m_NumRef >= 0 )
|
|
|
|
Buff << ListeCmp[ii].m_NumRef;
|
|
|
|
else
|
|
|
|
Buff = wxT( "?" );
|
2007-12-03 06:54:19 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
cmpref = CONV_FROM_UTF8( ListeCmp[ii].m_TextRef );
|
2008-02-26 01:07:38 +00:00
|
|
|
msg.Printf( _( "item not annotated: %s%s" ),
|
2008-02-28 19:27:25 +00:00
|
|
|
cmpref.GetData(), Buff.GetData() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
if( (ListeCmp[ii].m_Unit > 0) && (ListeCmp[ii].m_Unit < 0x7FFFFFFF) )
|
|
|
|
{
|
|
|
|
Buff.Printf( _( "( unit %d)" ), ListeCmp[ii].m_Unit );
|
|
|
|
msg << Buff;
|
|
|
|
}
|
|
|
|
DisplayError( NULL, msg );
|
2007-12-03 06:54:19 +00:00
|
|
|
error++;
|
2007-09-21 04:40:12 +00:00
|
|
|
break;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
// Annotate error
|
|
|
|
if( MAX( ListeCmp[ii].m_NbParts, 1 ) < ListeCmp[ii].m_Unit )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
|
|
|
if( ListeCmp[ii].m_NumRef >= 0 )
|
|
|
|
Buff << ListeCmp[ii].m_NumRef;
|
|
|
|
else
|
|
|
|
Buff = wxT( "?" );
|
|
|
|
|
|
|
|
cmpref = CONV_FROM_UTF8( ListeCmp[ii].m_TextRef );
|
2008-02-26 01:07:38 +00:00
|
|
|
msg.Printf( _( "Error item %s%s" ), cmpref.GetData(),
|
2008-02-28 19:27:25 +00:00
|
|
|
Buff.GetData() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
Buff.Printf( _( " unit %d and no more than %d parts" ),
|
2008-02-28 19:27:25 +00:00
|
|
|
ListeCmp[ii].m_Unit, ListeCmp[ii].m_NbParts );
|
2007-09-20 21:06:49 +00:00
|
|
|
msg << Buff;
|
|
|
|
DisplayError( frame, msg );
|
2007-12-03 06:54:19 +00:00
|
|
|
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)
|
2007-09-20 21:06:49 +00:00
|
|
|
for( ii = 0; (ii < NbOfCmp - 1) && (error < 4); ii++ )
|
|
|
|
{
|
2007-12-03 06:54:19 +00:00
|
|
|
msg.Empty();
|
2007-09-21 04:40:12 +00:00
|
|
|
Buff.Empty();
|
2007-12-03 06:54:19 +00:00
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
if( (stricmp( ListeCmp[ii].m_TextRef,
|
2008-02-28 19:27:25 +00:00
|
|
|
ListeCmp[ii + 1].m_TextRef ) != 0)
|
|
|
|
|| ( ListeCmp[ii].m_NumRef != ListeCmp[ii + 1].m_NumRef ) )
|
2007-09-20 21:06:49 +00:00
|
|
|
continue;
|
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
/* Same reference found */
|
|
|
|
|
|
|
|
/* If same unit, error ! */
|
|
|
|
if( ListeCmp[ii].m_Unit == ListeCmp[ii + 1].m_Unit )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
|
|
|
if( ListeCmp[ii].m_NumRef >= 0 )
|
|
|
|
Buff << ListeCmp[ii].m_NumRef;
|
|
|
|
else
|
|
|
|
Buff = wxT( "?" );
|
|
|
|
|
|
|
|
cmpref = CONV_FROM_UTF8( ListeCmp[ii].m_TextRef );
|
|
|
|
msg.Printf( _( "Multiple item %s%s" ),
|
2008-02-28 19:27:25 +00:00
|
|
|
cmpref.GetData(), Buff.GetData() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
if( (ListeCmp[ii].m_Unit > 0) && (ListeCmp[ii].m_Unit < 0x7FFFFFFF) )
|
|
|
|
{
|
|
|
|
Buff.Printf( _( " (unit %d)" ), ListeCmp[ii].m_Unit );
|
|
|
|
msg << Buff;
|
|
|
|
}
|
|
|
|
DisplayError( frame, msg );
|
2007-12-03 06:54:19 +00:00
|
|
|
error++;
|
2007-09-21 04:40:12 +00:00
|
|
|
continue;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/* Test error if units are different but number of parts per package
|
|
|
|
* too hight (ex U3 ( 1 part) and we find U3B the is an error) */
|
2007-09-20 21:06:49 +00:00
|
|
|
if( ListeCmp[ii].m_NbParts != ListeCmp[ii + 1].m_NbParts )
|
|
|
|
{
|
|
|
|
if( ListeCmp[ii].m_NumRef >= 0 )
|
|
|
|
Buff << ListeCmp[ii].m_NumRef;
|
|
|
|
else
|
|
|
|
Buff = wxT( "?" );
|
|
|
|
|
|
|
|
cmpref = CONV_FROM_UTF8( ListeCmp[ii].m_TextRef );
|
2008-02-26 01:07:38 +00:00
|
|
|
msg.Printf( _( "Multiple item %s%s" ),
|
2008-02-28 19:27:25 +00:00
|
|
|
cmpref.GetData(), Buff.GetData() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
if( (ListeCmp[ii].m_Unit > 0) && (ListeCmp[ii].m_Unit < 0x7FFFFFFF) )
|
|
|
|
{
|
|
|
|
Buff.Printf( _( " (unit %d)" ), ListeCmp[ii].m_Unit );
|
|
|
|
msg << Buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayError( frame, msg );
|
|
|
|
error++;
|
|
|
|
}
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
/* Error if values are different between units, for the same reference */
|
|
|
|
if( stricmp( ListeCmp[ii].m_TextValue,
|
2008-02-28 19:27:25 +00:00
|
|
|
ListeCmp[ii + 1].m_TextValue ) != 0 )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
|
|
|
wxString nextcmpref, cmpvalue, nextcmpvalue;
|
|
|
|
cmpref = CONV_FROM_UTF8( ListeCmp[ii].m_TextRef );
|
|
|
|
nextcmpref = CONV_FROM_UTF8( ListeCmp[ii + 1].m_TextRef );
|
|
|
|
cmpvalue = CONV_FROM_UTF8( ListeCmp[ii].m_TextValue );
|
|
|
|
nextcmpvalue = CONV_FROM_UTF8( ListeCmp[ii + 1].m_TextValue );
|
|
|
|
msg.Printf( _( "Diff values for %s%d%c (%s) and %s%d%c (%s)" ),
|
2008-02-28 19:27:25 +00:00
|
|
|
cmpref.GetData(),
|
|
|
|
ListeCmp[ii].m_NumRef,
|
|
|
|
ListeCmp[ii].m_Unit + 'A' - 1,
|
|
|
|
cmpvalue.GetData(), nextcmpref.GetData(),
|
|
|
|
ListeCmp[ii + 1].m_NumRef,
|
|
|
|
ListeCmp[ii + 1].m_Unit + 'A' - 1,
|
|
|
|
nextcmpvalue.GetData() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
DisplayError( frame, msg );
|
|
|
|
error++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFree( ListeCmp );
|
|
|
|
return error;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|