You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
7.0 KiB

  1. /*************************************************************/
  2. /* Traitement des netlistes VIEWLOGIC , Format NETLISt + PKG */
  3. /*************************************************************/
  4. /* Traite la netliste VIEWLOGIC au format .net, avec fichiers .pkg
  5. format .pkg
  6. ex:
  7. valeur;package;liste des composants
  8. 74LS00;14PDIP;U8,U9
  9. 74LS04;14PDIP;U2
  10. CAP_NPOL;;CP1,CP2,CP3,CP4,CP5,CP6,CP7
  11. RVERT;R_250MW;R11,R12,R13,R14,R15,R16,R17,R21,R22,R23,R24,R25,R26,R27,R31,R32,
  12. R33,R34,R35,R36,R37
  13. ..
  14. format .net
  15. netname;cmp^pin,...
  16. ex:
  17. $1I1\$1N2;U2^8,U3^10
  18. $1I1\$1N6;U3^9,U6^9
  19. $1N30;J2_8^2,Q1^2,Q2^2,Q3^2,Q4^2,Q5^2,Q6^2,Q7^2,R21^2,R22^2,R23^2,R24^2,R25^2,
  20. R26^2,R27^2,RP1^1,RP2^1,RP3^1,RP4^1,RP5^1,RP6^1,RP7^1
  21. */
  22. #include "fctsys.h"
  23. #include "wxstruct.h"
  24. #include "common.h"
  25. #include "cvpcb.h"
  26. #include "protos.h"
  27. /* routines locales : */
  28. static void GenPin( STORECMP *BaseCmp,char *CmpName, char *PinNum, char *PinNet);
  29. static int GenListeComposants(FILE * PkgFile);
  30. /* Variables Locales */
  31. /******************************/
  32. /* int ReadViewlogicNet(void) */
  33. /******************************/
  34. int WinEDA_CvpcbFrame::ReadViewlogicNetList(void)
  35. {
  36. int ii, LineNum;
  37. char Line[1024], *Text;
  38. wxString PkgFileName;
  39. char PinName[256], NetName[256], RefName[256], *Data;
  40. STORECMP * Cmp;
  41. wxString msg;
  42. modified = 0;
  43. Rjustify = 1;
  44. /* Raz buffer et variable de gestion */
  45. if( g_BaseListeCmp ) FreeMemoryComponants();
  46. Cmp = NULL; LineNum = 0;
  47. memset(Line, 0, sizeof(Line) );
  48. /* Tst de la presence du fichier principal Netliste, et son format:
  49. Si format = PCBNEW, appel de ReadSchematicNetlist
  50. */
  51. source = wxFopen(FFileName, wxT("rt") );
  52. if (source == 0)
  53. {
  54. msg = _("File not found ") + FFileName;
  55. DisplayError(this, msg); return(-1);
  56. }
  57. if ( fgets(Line, sizeof(Line)-1, source) == 0 )
  58. { /* fichier vide */
  59. fclose(source); return(-1);
  60. }
  61. fclose(source);
  62. Text = StrPurge(Line);
  63. ii = strnicmp(Line,"( { ",4) ; /* net type PCB2 */
  64. if( ii != 0 ) ii = strnicmp(Line,"# EESchema",4) ; /* net type EESchema */
  65. if( ii == 0 )
  66. {
  67. ii = ReadSchematicNetlist(); return(ii);
  68. }
  69. /* Traitement reel de la netliste Viewlogic ( .net et .pkg ) */
  70. SetStatusText( _("Format Netlist: ViewLogic net&pkg"), 0);
  71. /* Calcul du nom (full file name) du fichier .pkg */
  72. PkgFileName = FFileName;
  73. ChangeFileNameExt(PkgFileName, PkgInExtBuffer);
  74. /* Ouverture du fichier .pkg */
  75. source = wxFopen(PkgFileName, wxT("rt"));
  76. if (source == 0)
  77. {
  78. msg = _("File not found ") + PkgFileName;
  79. DisplayError(this, msg);
  80. return(-1);
  81. }
  82. nbcomp = GenListeComposants(source);
  83. fclose(source);
  84. /* reclassement alpab�tique : */
  85. g_BaseListeCmp = TriListeComposantss( g_BaseListeCmp, nbcomp);
  86. /* Ouverture du fichier netliste */
  87. source = wxFopen(FFileName, wxT("rt"));
  88. if (source == 0)
  89. {
  90. msg = _("File not found ") + FFileName;
  91. DisplayError(this, msg);
  92. return(-1);
  93. }
  94. /* Lecture de la liste ( fichier netliste ) */
  95. LineNum = 0;
  96. for ( ;; )
  97. {
  98. LineNum++;
  99. if ( fgets(Line, sizeof(Line)-1, source) == 0 ) break ;
  100. Text = StrPurge(Line);
  101. if (*Text < ' ' ) continue; /* Ligne vide */
  102. /* Lecture du NetName */
  103. for( ii = 0; ii < 80; ii++, Text++)
  104. {
  105. if( *Text == 0 ) break;
  106. if( *Text == ';' ) break;
  107. NetName[ii] = *Text;
  108. }
  109. NetName[ii] = 0; if ( *Text == ';' ) Text++;
  110. if( NetName[0] == 0 )
  111. {
  112. msg.Printf( wxT("Err. Pin Name ligne %s"),Line);
  113. DisplayError(this, msg, 20);
  114. }
  115. /* Lecture des attributions de pins */
  116. while( *Text != 0 )
  117. {
  118. Data = RefName; RefName[0] = PinName[0] = 0;
  119. for( ii = 0; ii < 1000; ii++, Text++ )
  120. {
  121. if( *Text == 0 ) break;
  122. if( *Text == ',' ) break;
  123. if( *Text == '^' )
  124. {
  125. *Data = 0; Data = PinName; continue;
  126. }
  127. *Data = *Text; Data++;
  128. }
  129. *Data = 0;
  130. if( (PinName[0] == 0 ) || (PinName[0] == 0 ) )
  131. {
  132. msg.Printf( wxT("Err. Pin Name ligne %s"),Line);
  133. DisplayError(this, msg, 20); break;
  134. }
  135. GenPin( g_BaseListeCmp, RefName, PinName, NetName);
  136. if ( *Text == ',' ) /* Autre element a traiter, ou nouvelle */
  137. /* ligne a lire ( continuation de ligne ) */
  138. {
  139. Text++; Text = StrPurge(Text);
  140. if( *Text == 0 ) /* Nouvelle ligne a lire */
  141. {
  142. LineNum++;
  143. if ( fgets(Line, sizeof(Line)-1, source) == 0 ) break ;
  144. Text = StrPurge(Line);
  145. }
  146. }
  147. }
  148. }
  149. fclose(source);
  150. return(0);
  151. }
  152. /******************************************************************************/
  153. static void GenPin( STORECMP *BaseCmp, char * CmpName,
  154. char *PinNum, char *PinNet)
  155. /******************************************************************************/
  156. /* Routine de creation d'une pin pour le composant de ref CmpName.
  157. la pin a pour "numero" PinNum, et pour Net PinNet
  158. */
  159. {
  160. STORECMP *Cmp;
  161. STOREPIN * Pin;
  162. wxString StrCmpName = CONV_FROM_UTF8(CmpName);
  163. /* Recherche du composant */
  164. Cmp = BaseCmp;
  165. for( ; Cmp != NULL; Cmp = Cmp->Pnext )
  166. {
  167. if( Cmp->m_Reference.CmpNoCase(StrCmpName) == 0 ) break;
  168. }
  169. if( Cmp == NULL )
  170. {
  171. wxString msg;
  172. msg.Printf( _("Component [%s] not found in .pkg file"), CmpName);
  173. DisplayError(NULL, msg, 1);
  174. return;
  175. }
  176. /* Creation de la Pin */
  177. Pin = new STOREPIN();
  178. Pin->Pnext = Cmp->m_Pins; Cmp->m_Pins = Pin;
  179. Pin->m_PinNum = CONV_FROM_UTF8(PinNum);
  180. Pin->m_PinNet = CONV_FROM_UTF8(PinNet);
  181. }
  182. /******************************************/
  183. static int GenListeComposants(FILE * PkgFile)
  184. /******************************************/
  185. /* Cree la liste des composants cites dans le fichier .pkg
  186. Retourne le nombre de composants
  187. */
  188. {
  189. int ii, LineNum, NbComp;
  190. char Line[1024], *Text;
  191. char Valeur[256], Package[256], Name[256];
  192. STORECMP * Cmp;
  193. LineNum = 0; NbComp = 0;
  194. /* Lecture de la liste ( fichier .pkg ) */
  195. for ( ;; )
  196. {
  197. LineNum++;
  198. if ( fgets(Line, sizeof(Line)-1, PkgFile) == 0 ) break ;
  199. Text = StrPurge(Line);
  200. if (*Text < ' ' ) continue; /* Ligne vide */
  201. /* Lecture de la Valeur */
  202. for( ii = 0; ii < 80; ii++, Text++)
  203. {
  204. if( *Text == 0 ) break;
  205. if( *Text == ';' ) break;
  206. Valeur[ii] = *Text;
  207. }
  208. Valeur[ii] = 0; if ( *Text == ';' ) Text++;
  209. /* Lecture du type du boitier */
  210. for( ii = 0; ii < 80; ii++, Text++)
  211. {
  212. if( *Text == 0 ) break;
  213. if( *Text == ';' ) break;
  214. Package[ii] = *Text;
  215. }
  216. Package[ii] = 0; if ( *Text == ';' ) Text++;
  217. /* Lecture des composants */
  218. while( *Text )
  219. {
  220. /* Lecture du nom du composant */
  221. for( ii = 0; ii < 80; ii++, Text++)
  222. {
  223. if( *Text <= ' ' ) break;
  224. if( *Text == ',' ) break;
  225. Name[ii] = *Text;
  226. }
  227. Name[ii] = 0;
  228. Cmp = new STORECMP();
  229. Cmp->Pnext = g_BaseListeCmp;
  230. g_BaseListeCmp = Cmp;
  231. NbComp++ ;
  232. Cmp->m_Reference = CONV_FROM_UTF8( StrPurge(Name) );
  233. Cmp->m_Valeur = CONV_FROM_UTF8( StrPurge(Valeur) );
  234. Cmp->m_Module = CONV_FROM_UTF8( StrPurge(Package) );
  235. Cmp->m_TimeStamp = wxT("00000000");
  236. if ( *Text == ',' ) /* Autre element a traiter, ou nouvelle */
  237. /* ligne a lire ( continuation de ligne ) */
  238. {
  239. Text++; Text = StrPurge(Text);
  240. if( *Text == 0 ) /* Nouvelle ligne a lire */
  241. {
  242. LineNum++;
  243. if ( fgets(Line, sizeof(Line)-1, PkgFile) == 0 ) break ;
  244. Text = StrPurge(Line);
  245. }
  246. }
  247. }
  248. }
  249. return(NbComp);
  250. }