File: annotate.cpp

package info (click to toggle)
kicad 0.0.20060829-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 56,544 kB
  • ctags: 9,194
  • sloc: cpp: 88,990; ansic: 4,790; makefile: 88; sh: 39
file content (695 lines) | stat: -rw-r--r-- 20,823 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
	/**************************************/
	/* annotate.cpp: component annotation */
	/**************************************/

#include "annotate_dialog.cpp"

#include "netlist.h"
#include "protos.h"

/* fonctions exportees */
int ListeComposants( CmpListStruct * BaseListeCmp, SCH_SCREEN *Window, int NumSheet);
int AnnotTriComposant(CmpListStruct *Objet1, CmpListStruct *Objet2);
void BreakReference( CmpListStruct * BaseListeCmp,int NbOfCmp );

/* fonctions locales */
static void ReNumComposants( CmpListStruct * BaseListeCmp,int NbOfCmp );
static void ComputeReferenceNumber( CmpListStruct * BaseListeCmp,int NbOfCmp);
static int GetLastReferenceNumber(CmpListStruct *Objet, CmpListStruct * BaseListeCmp,
														int NbOfCmp);
static int ExistUnit(CmpListStruct *Objet, int Unit,
								 CmpListStruct * BaseListeCmp,int NbOfCmp);

/* Variable locales */
static bool AnnotProject = TRUE;


/******************************************************************/
void InstallAnnotateFrame(WinEDA_DrawFrame *parent, wxPoint & pos)
/******************************************************************/
{
	WinEDA_AnnotateFrame * frame = new WinEDA_AnnotateFrame(parent);
	frame->ShowModal(); frame->Destroy();
}


/******************************************************************/
void WinEDA_AnnotateFrame::AnnotateComponents(wxCommandEvent& event)
/******************************************************************/
/*
	Compute the annotation of the components for the whole projeect, or the current sheet only.
	All the components or the new ones only will be annotated.
*/
{
int NbSheet, ii , NbOfCmp;
SCH_SCREEN *Window;
CmpListStruct * BaseListeCmp;

	wxBusyCursor dummy;

	AnnotProject = (m_AnnotProjetCtrl->GetSelection() == 0) ? TRUE : FALSE;

	/* If it is an annotation for all the components, reset previous annotation: */
	if( m_AnnotNewCmpCtrl->GetSelection() == 0 ) DeleteAnnotation(event);
	if (m_Abort ) return;

	/* Update sheet numbers */
	Window = ScreenSch;
	Window->SetModify();

	/* Count hierarchy sheet number*/
	for ( NbSheet = 0 ; Window != NULL; Window = (SCH_SCREEN*)Window->Pnext )
		NbSheet++;

	Window = ScreenSch;
	for ( ii = 1; Window != NULL; Window = (SCH_SCREEN*)Window->Pnext, ii++ )
	{
		Window->m_SheetNumber = ii; Window->m_NumberOfSheet = NbSheet;
		Window->m_Date = GenDate();		/* Update the sheet date */
	}

	/* First pass: Component counting */

	Window = (SCH_SCREEN*) m_Parent->m_CurrentScreen;
	if( AnnotProject == TRUE )
	{
		NbOfCmp = 0; Window = ScreenSch;
		for ( ; Window != NULL; Window = (SCH_SCREEN*)Window->Pnext )
		{
			NbOfCmp += ListeComposants(NULL, Window, Window->m_SheetNumber);
		}
	}
	else NbOfCmp = ListeComposants(NULL, Window, Window->m_SheetNumber);

	if( NbOfCmp == 0 )
	{
		wxBell();
		return;
	}

	ii = sizeof(CmpListStruct) * NbOfCmp;
	BaseListeCmp = (CmpListStruct *) MyZMalloc(ii);

	/* Second pass : Int data tables */
	if( AnnotProject == TRUE )
	{
		ii = 0; Window = ScreenSch;
		for ( ; Window != NULL; Window = (SCH_SCREEN*)Window->Pnext )
		{
			ii += ListeComposants(BaseListeCmp + ii,
									Window, Window->m_SheetNumber);
		}
	}

	else ii = ListeComposants(BaseListeCmp, Window, Window->m_SheetNumber);

	if( ii != NbOfCmp )
		DisplayError(this, wxT("Internal error in AnnotateComponents()"));

	/* Separation des Numeros de la reference: IC1 -> IC, et 1 dans .m_NumRef */
	BreakReference(BaseListeCmp, NbOfCmp);

	qsort( BaseListeCmp, NbOfCmp, sizeof(CmpListStruct),
				(int(*)(const void*, const void*))AnnotTriComposant);

	/* Recalcul des numeros de reference */
	ComputeReferenceNumber(BaseListeCmp, NbOfCmp);
	ReNumComposants(BaseListeCmp, NbOfCmp);

	MyFree(BaseListeCmp); BaseListeCmp = NULL;

	/* Final control */
	CheckAnnotate(m_Parent, AnnotProject ? FALSE : TRUE);

	m_Parent->DrawPanel->Refresh(TRUE);	/* Refresh screen */
	Close();
}


/********************************************************************/
void WinEDA_AnnotateFrame::DeleteAnnotation(wxCommandEvent& event)
/********************************************************************/
/* Clear the current annotation for the whole project or only for the current sheet
	Update sheet number and number of sheets
*/
{
int NbSheet, ii;
SCH_SCREEN * screen;
EDA_SchComponentStruct *DrawLibItem;

	if( !IsOK(this, _("Previous Annotation will be deleted. Continue ?") ) )
	{
		m_Abort = TRUE; return;
	}

	AnnotProject = (m_AnnotProjetCtrl->GetSelection() == 0) ? TRUE : FALSE;
	m_Abort = FALSE;

	/* Update the sheet number and number of sheets*/
	screen = ScreenSch;
	screen->SetModify();

	/* Count hierarchy sheets*/
	for ( NbSheet = 0 ; screen != NULL; screen = (SCH_SCREEN*)screen->Pnext )
		NbSheet++;

	screen = ScreenSch;
	for ( ii = 1; screen != NULL; screen = (SCH_SCREEN*)screen->Pnext, ii++ )
	{
		screen->m_SheetNumber = ii;			/* Update the sheet number */
		screen->m_NumberOfSheet = NbSheet;	/* Update the number of sheets */
		screen->m_Date = GenDate();			/* Update the sheet date */
	}

	if( AnnotProject == TRUE ) screen = ScreenSch;
	else screen = (SCH_SCREEN*) m_Parent->m_CurrentScreen;

	for ( ; screen != NULL; screen = (SCH_SCREEN*)screen->Pnext )
	{
		EDA_BaseStruct *DrawList = screen->EEDrawList;
		for ( ; DrawList != NULL ; DrawList = DrawList->Pnext )
		{
			if ( DrawList->m_StructType == DRAW_LIB_ITEM_STRUCT_TYPE )
			{
				DrawLibItem = (EDA_SchComponentStruct *) DrawList;
				DrawLibItem->ClearAnnotation();
			}
		}
		if( ! AnnotProject ) break;
	}

	m_Parent->DrawPanel->Refresh(TRUE);
	Close();
}


/************************************************************************************/
int ListeComposants(CmpListStruct * BaseListeCmp, SCH_SCREEN *Window, int NumSheet)
/***********************************************************************************/
/*	if BaseListeCmp == NULL : Components counting
	else update data table BaseListeCmp
*/
{
int NbrCmp = 0;
EDA_BaseStruct *DrawList = Window->EEDrawList;
EDA_SchComponentStruct *DrawLibItem;
EDA_LibComponentStruct *Entry;

	DrawList = Window->EEDrawList;

	while ( DrawList )
		{
		switch( DrawList->m_StructType )
			{
			case DRAW_SEGMENT_STRUCT_TYPE :
			case DRAW_JUNCTION_STRUCT_TYPE :
			case DRAW_TEXT_STRUCT_TYPE :
			case DRAW_LABEL_STRUCT_TYPE :
			case DRAW_GLOBAL_LABEL_STRUCT_TYPE :
				break;

			case DRAW_LIB_ITEM_STRUCT_TYPE :
				DrawLibItem = (EDA_SchComponentStruct *) DrawList;
  				Entry = FindLibPart(DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT);
 				if( Entry == NULL) break;
				if ( BaseListeCmp == NULL )	/* Items counting only */
				{
					NbrCmp++; break;
				}
				BaseListeCmp[NbrCmp].m_Cmp = DrawLibItem;
				BaseListeCmp[NbrCmp].m_NbParts = Entry->m_UnitCount;
				BaseListeCmp[NbrCmp].m_Unit = DrawLibItem->m_Multi;
				BaseListeCmp[NbrCmp].m_PartsLocked = Entry->m_UnitSelectionLocked;
				BaseListeCmp[NbrCmp].m_Sheet = NumSheet;
				BaseListeCmp[NbrCmp].m_IsNew = FALSE;
				BaseListeCmp[NbrCmp].m_TimeStamp = DrawLibItem->m_TimeStamp;
				if( DrawLibItem->m_Field[REFERENCE].m_Text.IsEmpty() )
					DrawLibItem->m_Field[REFERENCE].m_Text = wxT("DefRef?");
				strncpy( BaseListeCmp[NbrCmp].m_TextRef,
						CONV_TO_UTF8(DrawLibItem->m_Field[REFERENCE].m_Text), 32);

				BaseListeCmp[NbrCmp].m_NumRef = -1;

				if( DrawLibItem->m_Field[VALUE].m_Text.IsEmpty() )
					DrawLibItem->m_Field[VALUE].m_Text = wxT("~");
				strncpy( BaseListeCmp[NbrCmp].m_TextValue,
						CONV_TO_UTF8(DrawLibItem->m_Field[VALUE].m_Text), 32);
				NbrCmp++;
				break;

			case DRAW_PICK_ITEM_STRUCT_TYPE :
			case DRAW_POLYLINE_STRUCT_TYPE :
			case DRAW_BUSENTRY_STRUCT_TYPE :
			case DRAW_SHEET_STRUCT_TYPE :
			case DRAW_SHEETLABEL_STRUCT_TYPE :
			case DRAW_MARKER_STRUCT_TYPE :
			case DRAW_NOCONNECT_STRUCT_TYPE :
				break;

			default :
				break;
			}

		DrawList = DrawList->Pnext;
		}

return(NbrCmp);
}

/*****************************************************************/
int AnnotTriComposant(CmpListStruct *Objet1, CmpListStruct *Objet2)
/****************************************************************/
/* function used par qsort() for sorting the list
	Composants 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
**/
{
int ii;

	ii = strnicmp( Objet1->m_TextRef, Objet2->m_TextRef, 32 );

	if ( ii == 0 ) ii = strnicmp( Objet1->m_TextValue, Objet2->m_TextValue, 32 );
	if ( ii == 0 ) ii = Objet1->m_Unit - Objet2->m_Unit;
	if ( ii == 0 ) ii = Objet1->m_Sheet - Objet2->m_Sheet;
	if ( ii == 0 ) ii = Objet1->m_TimeStamp - Objet2->m_TimeStamp;

	return(ii);
}


/********************************************************************/
static void ReNumComposants( CmpListStruct * BaseListeCmp, int NbOfCmp)
/********************************************************************/
/* Update the reference component for the schematic project (or the current sheet)
*/
{
int ii;
char *Text;
EDA_SchComponentStruct *DrawLibItem;

	/* 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 );

		DrawLibItem->m_Field[REFERENCE].m_Text = CONV_FROM_UTF8(Text);
		DrawLibItem->m_Multi = BaseListeCmp[ii].m_Unit;
	}
}



/**************************************************************/
void BreakReference( CmpListStruct * BaseListeCmp, int NbOfCmp)
/**************************************************************/

/* Modifie dans BaseListeCmp la reference des composants en supprimant la
	partie nombre de la partie texte.
Place le nombre dans .m_NumRef
Pour les composants multiples non encore annotes, met .m_Unit a sa valeur max
	Utilise:
		BaseListeCmp
		NbOfCmp
*/
{
int ii, ll;
char * Text;

	/* Separation des Numeros de la reference: IC1 -> IC, et 1 dans .m_NumRef */
	for ( ii = 0; ii < NbOfCmp ; ii++ )
	{
		BaseListeCmp[ii].m_NumRef = - 1;
		Text = BaseListeCmp[ii].m_TextRef;
		ll = strlen( Text ) - 1;
		if( Text[ll] == '?' )
		{
			BaseListeCmp[ii].m_IsNew = TRUE;
			if ( ! BaseListeCmp[ii].m_PartsLocked )
				BaseListeCmp[ii].m_Unit = 0x7FFFFFFF;
			Text[ll] = 0; continue;
		}

		if( isdigit(Text[ll]) == 0 )
		{
			BaseListeCmp[ii].m_IsNew = TRUE;
			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;
			}
		}
	}
}


/*****************************************************************************/
static void ComputeReferenceNumber( CmpListStruct * BaseListeCmp, int NbOfCmp)
/*****************************************************************************/
/* Compute the reference number for components without reference number
	Compute	.m_NumRef member
*/
{
int ii, jj, LastReferenceNumber, NumberOfUnits, Unit;
char * Text, * RefText, *ValText;
CmpListStruct * ObjRef, * ObjToTest;

	/* Components with an invisible reference (power...) always are re-annotated*/
	for ( ii = 0; ii < NbOfCmp ; ii++ )
	{
		Text = BaseListeCmp[ii].m_TextRef;
		if (*Text == '#')
		{
			BaseListeCmp[ii].m_IsNew = TRUE;
			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;
			LastReferenceNumber = GetLastReferenceNumber(BaseListeCmp + ii, BaseListeCmp, NbOfCmp);
		}

		/* Annotation of mono-part components ( 1 part per package ) (trivial case)*/
		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;
		}

		/* Annotation of multi-part components ( n parts per package ) (complex case) */
		ValText = BaseListeCmp[ii].m_TextValue;
		NumberOfUnits = BaseListeCmp[ii].m_NbParts;

		if ( BaseListeCmp[ii].m_IsNew )
		{
			LastReferenceNumber++; BaseListeCmp[ii].m_NumRef = LastReferenceNumber;
			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 ) continue;	/* Unit exists for this reference */

			/* 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 ) break;	// references are different
				Text = BaseListeCmp[jj].m_TextValue;
				if( strnicmp(ValText, Text, 32) != 0 ) break;	// values are different
				if ( ! BaseListeCmp[jj].m_IsNew )
				{
					//BaseListeCmp[jj].m_Flag = 1;
					continue;
				}
				/* Component without reference number found, annotate it if possible */
				if ( ! BaseListeCmp[jj].m_PartsLocked || (BaseListeCmp[jj].m_Unit == Unit) )
				{
					BaseListeCmp[jj].m_NumRef = BaseListeCmp[ii].m_NumRef;
					BaseListeCmp[jj].m_Unit = Unit;
					BaseListeCmp[jj].m_Flag = 1;
					BaseListeCmp[jj].m_IsNew = FALSE;
					break;
				}
			}
		}
	}
}


/*************************************************************************************************/
static int GetLastReferenceNumber(CmpListStruct *Objet, CmpListStruct * BaseListeCmp, int NbOfCmp)
/*************************************************************************************************/
/* Recherche le plus grand numero de reference dans les composants
	de meme prefixe de reference que celui pointe par Objet
	la liste des composants est supposee triee
*/
{
CmpListStruct * LastObjet = BaseListeCmp + NbOfCmp;
int LastNumber = 0;
const char * RefText;

	RefText = Objet->m_TextRef;
	for ( ; Objet < LastObjet; Objet++ )
	{
		if( strnicmp(RefText, Objet->m_TextRef, 32) != 0 ) /* Nouveau Identificateur */
			break;
		if( LastNumber < Objet->m_NumRef ) LastNumber = Objet->m_NumRef;
	}
	return(LastNumber);
}


/*****************************************************************/
static int ExistUnit(CmpListStruct *Objet, int Unit,
						CmpListStruct * BaseListeCmp, int NbOfCmp)
/****************************************************************/
/* Recherche dans la liste triee des composants, pour les composants
	multiples s'il existe pour le composant de reference Objet,
	une unite de numero Unit
		Retourne index dans BaseListeCmp si oui
		retourne -1 si non
*/
{
CmpListStruct * EndList = BaseListeCmp + NbOfCmp;
char * RefText, * ValText;
int NumRef, ii;
CmpListStruct *ItemToTest;

	RefText = Objet->m_TextRef;
	ValText = Objet->m_TextValue;
	NumRef = Objet->m_NumRef;
	for ( ItemToTest = BaseListeCmp, ii = 0; ItemToTest < EndList; ItemToTest++, ii++ )
	{
		if ( Objet == ItemToTest ) continue;
		if ( ItemToTest->m_IsNew ) continue;  /* non affecte */
		if ( ItemToTest->m_NumRef != NumRef ) continue;
		if( strnicmp(RefText, ItemToTest->m_TextRef, 32) != 0 ) /* Nouveau Identificateur */
			continue;
		if( ItemToTest->m_Unit == Unit)
		{
			return(ii);
		}
	}
	return(-1);
}

/************************************************************/
int CheckAnnotate(WinEDA_DrawFrame * frame, bool OneSheetOnly)
/************************************************************/

/* Retourne le nombre de composants non annots ou de meme rfrence (doubls)
	Si OneSheetOnly : recherche sur le schema courant
	sinon: recherche sur toute la hierarchie
*/
{
int NbSheet, ii, NumSheet = 1, error, NbOfCmp;
SCH_SCREEN *Window;
CmpListStruct * ListeCmp = NULL;
wxString Buff;
wxString msg, cmpref;
	
	/* Comptage du nombre de feuilles de hierarchy */
	Window = ScreenSch;
	for ( NbSheet = 0 ; Window != NULL; Window = (SCH_SCREEN*)Window->Pnext )
		NbSheet++;

	Window = ScreenSch;
	for ( ii = 1; Window != NULL; Window = (SCH_SCREEN*)Window->Pnext, ii++ )
	{
		Window->m_SheetNumber = ii; Window->m_NumberOfSheet = NbSheet;
	}
	
	/* 1ere passe : Comptage du nombre de composants */

	Window = (SCH_SCREEN*) frame->m_CurrentScreen;
	if( OneSheetOnly == 0 )
		{
		NbOfCmp = 0; Window = ScreenSch;
		for ( ; Window != NULL; Window = (SCH_SCREEN*)Window->Pnext )
			{
			NbOfCmp += ListeComposants(NULL, Window, NumSheet);
			}
		}
	else NbOfCmp = ListeComposants(NULL, Window, NumSheet);

	if( NbOfCmp == 0 )
		{
		wxBell();
		return(0);
		}

	ii = sizeof(CmpListStruct) * NbOfCmp;
	ListeCmp = (CmpListStruct *) MyZMalloc(ii);

	/* 2eme passe : Remplissage du tableau des caracteristiques */
	if( OneSheetOnly == 0 )
	{
		ii = 0; Window = ScreenSch;
		for ( ; Window != NULL; Window = (SCH_SCREEN*)Window->Pnext )
		{
			ii += ListeComposants(ListeCmp + ii, Window, NumSheet);
		}
	}
	else ListeComposants(ListeCmp, Window, NumSheet);

	qsort( ListeCmp, NbOfCmp, sizeof(CmpListStruct),
				(int(*)(const void*, const void*))AnnotTriComposant);


	/* Separation des Numeros de la reference: IC1 -> IC, et 1 dans .m_NumRef */
	BreakReference(ListeCmp, NbOfCmp);

	/* comptage des elements non annotes */
	error = 0;
	for( ii = 0; ii < NbOfCmp-1 ; ii++ )
	{
		msg.Empty(); Buff.Empty();
		if ( ListeCmp[ii].m_IsNew )
		{
			if( ListeCmp[ii].m_NumRef >= 0 ) Buff << ListeCmp[ii].m_NumRef;
			else Buff = wxT("?");
			cmpref = CONV_FROM_UTF8(ListeCmp[ii].m_TextRef);
			msg.Printf( _("item not annotated: %s%s"), cmpref.GetData(), Buff.GetData());

			if( (ListeCmp[ii].m_Unit > 0) && (ListeCmp[ii].m_Unit < 0x7FFFFFFF) )
			{
				Buff.Printf( _("( unit %d)"), ListeCmp[ii].m_Unit);
				msg << Buff;
			}
			DisplayError(NULL, msg);
			error++; break;
		}

		if( MAX(ListeCmp[ii].m_NbParts, 1) < ListeCmp[ii].m_Unit  )	// Annotate error
		{
			if( ListeCmp[ii].m_NumRef >= 0 ) Buff << ListeCmp[ii].m_NumRef;
			else Buff = wxT("?");

			cmpref = CONV_FROM_UTF8(ListeCmp[ii].m_TextRef);
			msg.Printf( _("Error item %s%s"), cmpref.GetData(), Buff.GetData());

			Buff.Printf( _(" unit %d and no more than %d parts"),
										ListeCmp[ii].m_Unit, ListeCmp[ii].m_NbParts);
			msg << Buff;
			DisplayError(frame, msg);
			error++; break;
		}
	}

	if ( error ) return error;

	/* comptage des elements doubls (si tous sont annots) */
	for( ii = 0; (ii < NbOfCmp-1) && (error < 4); ii++ )
	{
		msg.Empty(); Buff.Empty();
		if( (stricmp(ListeCmp[ii].m_TextRef,ListeCmp[ii+1].m_TextRef) != 0) ||
			( ListeCmp[ii].m_NumRef != ListeCmp[ii+1].m_NumRef ) )
			continue;
		/* Meme reference trouve */

		/* Il y a erreur si meme unite */
		if( ListeCmp[ii].m_Unit == ListeCmp[ii+1].m_Unit )
		{

			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"),
						cmpref.GetData(),Buff.GetData());

			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++; continue;
		}

		/* Il y a erreur si unites differentes mais nombre de parts differentes
		par boitier (ex U3 ( 1 part) et U3B sont incompatibles) */
		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);
			msg.Printf( _("Multiple item %s%s"), cmpref.GetData(), Buff.GetData());

			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++;
		}

		/* Il y a erreur si unites differentes ET valeurs diffrentes */
		if( stricmp(ListeCmp[ii].m_TextValue,ListeCmp[ii+1].m_TextValue) != 0)
		{
			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)"),
						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());

			DisplayError(frame, msg);
			error++;
		}
	}

	MyFree(ListeCmp);
	return(error);
}