File: viewlogi.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 (422 lines) | stat: -rw-r--r-- 10,628 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
	/********************************************************/
	/* Traitement des netlistes VIEWLOGIC , Format WIRELIST */
	/********************************************************/

/* Traite la netliste VIEWLOGIC au format WIRELIST
*/

#include "fctsys.h"

#include "common.h"
#include "cvpcb.h"

#include "protos.h"

/* routines locales : */
static int ReadVLDescrCmp( char * Line, STORECMP * Cmp, int Type);
static int ReadReelNumPin( char * Line, STORECMP * Cmp, int Type);
static int RegroupeUnitsComposant( STORECMP * BaseCmp );
static STORECMP *TraitePseudoCmp(char * Text, STORECMP *PseudoCmp, int Header);
static void MergePseudoCmp(STORECMP * BaseCmp, STORECMP * BasePseudoCmp);

/* Variables Locales */
STORECMP * BasePseudoCmp;	/* Stockage des descriptions generales */

/* Identificateurs de debut de ligne */
#define API ( (('A'&255) << 16) | (('P'&255) << 8 ) | ('I'&255) )
#define AP_ ( (('A'&255) << 8) | ('P'&255) )
#define AS_ ( (('A'&255) << 8) | ('S'&255) )
#define A__ ('A' & 255)
#define W__ ('W' & 255)
#define M__ ('M' & 255)
#define I__ ('I' & 255)


/************************************************/
int WinEDA_CvpcbFrame::ReadViewlogicWirList(void)
/************************************************/
{
int ii, Type = 0, error, Header;
char RefDes[40], val[40], LocalRef[40], Generic[40] ;
char Line[1024], *Text;
STORECMP * Cmp, *NextCmp;
STORECMP * PseudoCmp = NULL;
wxString msg;
	
	modified = 0;
	Rjustify = 1;

	/* Raz buffer et variable de gestion */
	if( BaseListeCmp ) FreeMemoryComponants();

	Cmp = NULL;

	/* Ouverture du fichier source */
	msg = _("Netlist file ") + FFileName;
	SetStatusText(msg,0);

	source = wxFopen(FFileName, wxT("rt"));
	if (source == 0)
	{
		msg = _("File not found ") + FFileName;
		DisplayError(this, msg); return(-1);
	}

	/* Lecture entete qui doit etre "| Wirelist ..*/
	fgets(Line,1024,source) ;
	ii = strncmp(Line,"| Wirelist",3) ;	 /* net type Viewlogic */

	if ( ii != 0 )
	{
		wxString Lineconv = CONV_FROM_UTF8(Line);
		msg.Printf( _("Unknown file format <%s>"), Lineconv.GetData());
		fclose(source); return(-3) ;
	}

	SetStatusText( wxT("Format Netliste ViewLogic wirelist"), 0);

	/* Lecture de la liste */
	for ( ;; )
		{
		if ( fgets(Line,1024,source) == 0 )  break ;
		Text = StrPurge(Line);

		Header = *Text & 255;	/* Header est la copie du 1er mot de la ligne */
		for( ii = 1; ii < 3 ; ii++ )
			{
			if( Text[ii] <= ' ' ) break;
			Header <<= 8; Header |= Text[ii] & 255;
			}

		switch( Header )
			{
			case AP_ :
			case AS_ :
				PseudoCmp = TraitePseudoCmp(Text, PseudoCmp, Header);
				Type = 0;
				break;

			case API :
				if( (nbcomp <= 0 ) || (Cmp == NULL) )
					{
					DisplayError(NULL, wxT("Description API inattendue"), 20);
					break;
					}
				error = ReadReelNumPin( Text, Cmp, Type );
				if( error < 0 )
					{
					msg.Printf( wxT("Erreur %d ligne API"), -error );
					DisplayError(NULL, msg,10 );
					}
				break;

			case I__ :	/* Lecture descr 1 composant */
				if( nbcomp <= 0 )
				{
					DisplayError(NULL, wxT("Description Composant inattendue"), 20);
					break;
				}
				*RefDes = 0; *val = 0;
				ReadVLDescrCmp( Text, Cmp, Type);
				Type = 1;	/* pour lecture num pins */
				break;

			case W__ :
			case M__ :
				Cmp = new STORECMP();
				Cmp->Pnext = BaseListeCmp;
				BaseListeCmp = Cmp;
				nbcomp++ ;
				Type = Header;
				Text = strtok(NULL, " \t\n\r");
				if( Text == NULL ) break;
				strncpy(Generic, Text, 40);
				Text = strtok(NULL, " \n\r");
				if( Text == NULL ) break;
				strncpy(LocalRef, Text, 40);
				break;

			default:
				Type = 0;
				break;
			}
		}

	fclose(source);

	/* reclassement alpabtique : */
	BaseListeCmp = TriListeComposantss( BaseListeCmp, nbcomp);
	nbcomp -= RegroupeUnitsComposant( BaseListeCmp );

	/* Addition des renseignements issus des pseudo composants */
	MergePseudoCmp( BaseListeCmp, BasePseudoCmp);

	/* Renumerotation des composants */
	Cmp = BaseListeCmp;
	for( ii = 1; Cmp != NULL; ii++, Cmp = Cmp->Pnext)
	{
		Cmp->m_Num = ii;
	}

	/* Liberation memoire */
	Cmp = BasePseudoCmp;
	for( ; Cmp != NULL; Cmp = NextCmp )
	{
		NextCmp = Cmp->Pnext; delete Cmp;
	}
	BasePseudoCmp = NULL;

	return(0);
}


/****************************************************************/
static int ReadVLDescrCmp( char * Line, STORECMP * Cmp, int Type)
/****************************************************************/
/* Lecture de la description d'un composant
	(ligne commencant par I ...)
*/
{
char * Text, *Ident;
int nbpins = 0;
char numpin[9];
STOREPIN * Pin = NULL;
STOREPIN ** LastPin = & Cmp->m_Pins;

	Text = strtok(Line, " \n\t\r`");

	Text = strtok(NULL, " \n\t\r`");	/* Text pointe 1er mot utile */

	Ident = strtok(NULL, " \n\t\r`");	/* Ident pointe identificateur */
	Cmp->m_Repere = CONV_FROM_UTF8(Ident);

	while ( Text )
		{
		Text = strtok(NULL, " \t\n\r`");
		if( Text == NULL ) break;

		if( strncmp(Text, "VALUE=" ,6) == 0 )
		{
			Cmp->m_Valeur = CONV_FROM_UTF8(Text+6);
			continue;
		}

		if( strncmp(Text, "REFDES=",7 ) == 0 )
		{
			Cmp->m_Reference = CONV_FROM_UTF8(Text+7);
			if( !isdigit(Cmp->m_Reference.Last() ) )
				Cmp->m_Reference.RemoveLast();
			continue;
		}

		/* Lecture d'un net pin */
		nbpins++;
		Pin = (STOREPIN *)MyZMalloc( sizeof(STOREPIN) );
		*LastPin = Pin; LastPin = &Pin->Pnext;
		sprintf(numpin,"%d", nbpins);
		Pin->m_Index = nbpins;
		Pin->m_PinNum = CONV_FROM_UTF8(numpin);
		Pin->m_PinNet = CONV_FROM_UTF8(Text);
		}

	if( Cmp->m_Valeur.IsEmpty())
	{
		Cmp->m_Valeur = CONV_FROM_UTF8(Ident);
	}


	/* Mise en place du TimeStamp init a 0 */
	Cmp->m_TimeStamp = wxT("00000000");

	/* Analyse du type */
	switch( Type )
	{
		case M__: return(0);
		case W__: return(0);
		default: break;
	}
	return(-1);
}

	/*********************************************************************/
	/* int ReadReelNumPin( char * Line, STORECMP * Cmp, int Type) */
	/*********************************************************************/

/* Lit les lignes commencant par "API" pour recuperer le vrai numero de pin
*/
static int ReadReelNumPin( char * Line, STORECMP * Cmp, int Type)
{
char * Text, *Ident;
int numpin;
STOREPIN * Pin;


	if( Type != 1 ) return (-1);

	Text = strtok(Line, " \n\t\r");

	Ident = strtok(NULL, " \n\t\r");	/* Ident pointe identificateur */

	Text = strtok(NULL, " \n\t\r");		/* Text pointe type composant */

	Text = strtok(NULL, " \n\t\r");		/* pointe numero d'ordre */
	if( Text == NULL ) return(-2);;

	numpin = atoi(Text);

	Text = strtok(NULL, " \n\t\r");		/* pointe Reel NumPin */
	if( Text == NULL ) return(-3);

	if( strncmp(Text, "#=" ,2) ) return (-4);

	for(Pin = Cmp->m_Pins ; Pin != NULL; Pin = Pin->Pnext )
		{
		if( Pin->m_Type != STRUCT_PIN ) return(-5);
		if( Pin->m_Index != numpin ) continue;
		Pin->m_PinNum = CONV_FROM_UTF8(Text+2);
		return(0);
		}
	return(-6 );
}


	/***********************************************/
	/* int RegroupeComposant( STORECMP * BaseCmp ) */
	/***********************************************/

/* Regroupe les pins des differentes Unites d'un meme composant
	et modifie le chainage
*/
static int RegroupeUnitsComposant( STORECMP * BaseCmp )
{
STORECMP * Cmp = BaseCmp;
STORECMP * NextCmp = Cmp->Pnext;
STOREPIN * Pin;
int Deleted = 0;


	if( NextCmp == NULL ) return(0);

	for( ; NextCmp != NULL; Cmp = NextCmp, NextCmp = NextCmp->Pnext )
		{
		if( Cmp->m_Reference != NextCmp->m_Reference ) continue;
		/* 2 composants identiques : Pins a regrouper */
		Deleted++;
		Pin = Cmp->m_Pins;
		if( Pin == NULL ) Cmp->m_Pins = NextCmp->m_Pins;
		else
		{
			while(Pin->Pnext) Pin = Pin->Pnext;
			Pin->Pnext = NextCmp->m_Pins;
		}
		NextCmp->m_Pins = NULL;
		Cmp->Pnext = NextCmp->Pnext;
		(Cmp->Pnext)->Pback = Cmp;
		delete NextCmp;
		NextCmp = Cmp;
		}
	return(Deleted);
}



/****************************************************************************/
static STORECMP *TraitePseudoCmp(char * Line, STORECMP *PseudoCmp, int Header)
/****************************************************************************/
{
STORECMP * Cmp = PseudoCmp;
STOREPIN * Pin;
char  *Text;
wxString Name;

	Text = strtok(Line," \t\n\r");
	Text = strtok(NULL," \t\n\r");  /* Pointe Name */
	Name = CONV_FROM_UTF8(Text);
	Text = strtok(NULL," \t\n\r");  /* Pointe partie utile */

	if( Cmp == NULL )
	{
		Cmp = BasePseudoCmp = new STORECMP();
		Cmp->m_Repere = Name;
		Cmp->m_Valeur = Name;
	}

	else if( Name != Cmp->m_Valeur )	/* Nouveau pseudo composant */
	{
		Cmp = new STORECMP();
		PseudoCmp->Pnext = Cmp;
		Cmp->m_Valeur = Name;
		Cmp->m_Repere = Name;
	}

	switch ( Header )
		{
		case AS_ :
			if( strnicmp(Text,"PKG_TYPE=",9) == 0 )
				{
				Cmp->m_Module = CONV_FROM_UTF8(Text+9);
				break;
				}
			if( strnicmp(Text,"PARTS =",7) == 0 )
				{
				Cmp->m_Multi = atoi(Text+7);
				break;
				}
			if( strnicmp(Text,"REFDES=",7) == 0 )
				{
				Cmp->m_Reference = CONV_FROM_UTF8(Text+7);
				break;
				}
			if( strnicmp(Text,"SIGNAL=",7) == 0 )
				{
				Text = strtok(Text," ;=\t\n\r");
				Text = strtok(NULL," ;=\t\n\r");  /* Pointe partie utile */
				Pin = new STOREPIN();
				Pin->Pnext = Cmp->m_Pins;
				Cmp->m_Pins = Pin;
				Pin->m_PinNet = CONV_FROM_UTF8(Text);
				Text = strtok(NULL," ;=\t\n\r");  /* Pointe partie utile */
				Pin->m_PinNum = CONV_FROM_UTF8(Text);
				break;
				}
			break;

		case AP_ :
			break;

		}	

	return(Cmp);
}


/*********************************************************************/
static void MergePseudoCmp(STORECMP * BaseCmp, STORECMP * BasePseudoCmp)
/*********************************************************************/
/* Additionne aux composants standards les renseignements contenus
dans les descriptions generales
*/
{
STORECMP * Cmp, * PseudoCmp;
STOREPIN * Pin, * PseudoPin;

	Cmp = BaseCmp;
	for( ; Cmp != NULL; Cmp = Cmp->Pnext)
	{
		PseudoCmp = BasePseudoCmp;
		for( ; PseudoCmp != NULL; PseudoCmp = PseudoCmp->Pnext)
		{
			if( Cmp->m_Repere != PseudoCmp->m_Repere ) continue;
			/* Description trouvee, transfert des infos */
			Cmp->m_Multi = PseudoCmp->m_Multi;
			PseudoPin = PseudoCmp->m_Pins;
			for ( ; PseudoPin != NULL; PseudoPin = PseudoPin->Pnext)
			{
				Pin = new STOREPIN(*PseudoPin);
				Pin->Pnext = Cmp->m_Pins; Cmp->m_Pins = Pin;
			}
			break;
		}
	}
}