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.

1022 lines
30 KiB

19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
  1. /********************************************************************/
  2. /* Routines de lecture et sauvegarde des structures en format ASCii */
  3. /* Fichier common a PCBNEW et CVPCB */
  4. /********************************************************************/
  5. /* ioascii.cpp */
  6. #include "fctsys.h"
  7. #include "gr_basic.h"
  8. #include "common.h"
  9. #include "pcbnew.h"
  10. #ifdef PCBNEW
  11. #include "pcbnew.h"
  12. #include "autorout.h"
  13. #endif
  14. #ifdef CVPCB
  15. #include "cvpcb.h"
  16. #endif
  17. #include "protos.h"
  18. /* Format des structures de sauvegarde type ASCII :
  19. Structure PAD:
  20. $PAD
  21. Sh "name" forme dimv dimH dV dH orient :forme generale dV, dH = delta dimensions
  22. Dr diam, dV dH :drill : diametre offsets de percage
  23. At type S/N layers : type standard,cms,conn,hole,meca.,
  24. Stack/Normal,
  25. Hexadecimal 32 bits: occupation des couches
  26. Nm net_code netname
  27. Po posrefX posrefy : position refX,Y (= position orient 0 / ancre)
  28. $EndPAD
  29. ****** Structure module ***********
  30. $MODULE namelib
  31. Po ax ay orient layer masquelayer m_TimeCode
  32. ax ay = coord ancre (position module)
  33. orient = orient en 0.1 degre
  34. layer = numero de couche
  35. masquelayer = couche pour serigraphie
  36. m_TimeCode a usage interne (groupements)
  37. Li <namelib>
  38. Cd <text> Description du composant (Composant Doc)
  39. Kw <text> Liste des mots cle
  40. Sc schematimestamp de reference schematique
  41. Op rot90 rot180 Options de placement auto (cout rot 90, 180 )
  42. rot90 est sur 2x4 bits:
  43. lsb = cout rot 90, msb = cout rot -90;
  44. Tn px py dimv dimh orient epaisseur miroir visible "texte"
  45. n = type (0 = ref, 1 = val, > 1 =qcq
  46. Textes POS x,y / ancre et orient module 0
  47. dimv dimh orient
  48. epaisseur miroir (Normal/miroir)
  49. visible V/I
  50. DS ox oy fx fy w
  51. edge: segment coord ox,oy a fx,fy, relatives
  52. a l'ancre et orient 0
  53. epaisseur w
  54. DC ox oy fx fy w descr cercle (centre, 1 point, epaisseur)
  55. $PAD
  56. $EndPAD section pads s'il y en a
  57. $EndMODULE
  58. */
  59. extern Ki_PageDescr* SheetList[];
  60. /* Local Variables */
  61. int NbDraw, NbTrack, NbZone, NbMod, NbNets;
  62. /**********************************************************************/
  63. int WinEDA_BasePcbFrame::ReadListeSegmentDescr( FILE* File,
  64. TRACK* PtSegm, int StructType, int* LineNum, int NumSegm )
  65. /**********************************************************************/
  66. /** Read a list of segments (Tracks, zones)
  67. * @return items count or - count if no end block ($End...) found.
  68. */
  69. {
  70. int shape, width, layer, type, flags, net_code;
  71. int ii = 0;
  72. char line1[256];
  73. char line2[256];
  74. TRACK* NewTrack;
  75. while( GetLine( File, line1, LineNum ) )
  76. {
  77. int makeType;
  78. unsigned long timeStamp;
  79. if( line1[0] == '$' )
  80. {
  81. return ii; /* end of segmentlist: OK */
  82. }
  83. // Read the 2nd line to determine the exact type, one of:
  84. // TYPETRACK, TYPEVIA, or TYPEZONE. The type field in 2nd line
  85. // differentiates between TYPETRACK and TYPEVIA. With virtual
  86. // functions in use, it is critical to instantiate the TYPEVIA exactly.
  87. if( GetLine( File, line2, LineNum ) == NULL )
  88. break;
  89. if( line2[0] == '$' )
  90. break;
  91. // parse the 2nd line first to determine the type of object
  92. sscanf( line2 + 2, " %d %d %d %lX %X", &layer, &type, &net_code,
  93. &timeStamp, &flags );
  94. if( StructType==TYPETRACK && type==1 )
  95. makeType = TYPEVIA;
  96. else
  97. makeType = StructType;
  98. switch( makeType )
  99. {
  100. default:
  101. case TYPETRACK:
  102. NewTrack = new TRACK( m_Pcb );
  103. break;
  104. case TYPEVIA:
  105. NewTrack = new SEGVIA( m_Pcb );
  106. break;
  107. case TYPEZONE:
  108. NewTrack = new SEGZONE( m_Pcb );
  109. break;
  110. }
  111. NewTrack->Insert( m_Pcb, PtSegm );
  112. PtSegm = NewTrack;
  113. PtSegm->m_TimeStamp = timeStamp;
  114. int arg_count = sscanf( line1 + 2, " %d %d %d %d %d %d %d", &shape,
  115. &PtSegm->m_Start.x, &PtSegm->m_Start.y,
  116. &PtSegm->m_End.x, &PtSegm->m_End.y, &width,
  117. &PtSegm->m_Drill );
  118. PtSegm->m_Width = width;
  119. PtSegm->m_Shape = shape;
  120. if( arg_count < 7 )
  121. PtSegm->m_Drill = -1;
  122. PtSegm->SetLayer( layer );
  123. PtSegm->SetNet( net_code );
  124. PtSegm->SetState( flags, ON );
  125. }
  126. DisplayError( this, _( "Error: Unexpected end of file !" ) );
  127. return -ii;
  128. }
  129. /**********************************************************************************/
  130. int WinEDA_BasePcbFrame::ReadGeneralDescrPcb( FILE* File, int* LineNum )
  131. /**********************************************************************************/
  132. {
  133. char Line[1024], * data;
  134. while( GetLine( File, Line, LineNum ) != NULL )
  135. {
  136. data = strtok( Line, " =\n\r" );
  137. if( strnicmp( data, "$EndGENERAL", 10 ) == 0 )
  138. break;
  139. if( strncmp( data, "Ly", 2 ) == 0 ) // Old format for Layer count
  140. {
  141. int Masque_Layer = 1, ii;
  142. data = strtok( NULL, " =\n\r" );
  143. sscanf( data, "%X", &Masque_Layer );
  144. // Setup layer count
  145. m_Pcb->m_BoardSettings->m_CopperLayerCount = 0;
  146. for( ii = 0; ii < NB_COPPER_LAYERS; ii++ )
  147. {
  148. if( Masque_Layer & 1 )
  149. m_Pcb->m_BoardSettings->m_CopperLayerCount++;
  150. Masque_Layer >>= 1;
  151. }
  152. continue;
  153. }
  154. if( strnicmp( data, "Links", 5 ) == 0 )
  155. {
  156. data = strtok( NULL, " =\n\r" );
  157. m_Pcb->m_NbLinks = atoi( data );
  158. continue;
  159. }
  160. if( strnicmp( data, "NoConn", 6 ) == 0 )
  161. {
  162. data = strtok( NULL, " =\n\r" );
  163. m_Pcb->m_NbNoconnect = atoi( data );
  164. continue;
  165. }
  166. if( strnicmp( data, "Di", 2 ) == 0 )
  167. {
  168. wxSize pcbsize, screensize;
  169. data = strtok( NULL, " =\n\r" );
  170. m_Pcb->m_BoundaryBox.SetX( atoi( data ) );
  171. data = strtok( NULL, " =\n\r" );
  172. m_Pcb->m_BoundaryBox.SetY( atoi( data ) );
  173. data = strtok( NULL, " =\n\r" );
  174. m_Pcb->m_BoundaryBox.SetWidth( atoi( data ) - m_Pcb->m_BoundaryBox.GetX() );
  175. data = strtok( NULL, " =\n\r" );
  176. m_Pcb->m_BoundaryBox.SetHeight( atoi( data ) - m_Pcb->m_BoundaryBox.GetY() );
  177. continue;
  178. }
  179. /* Lecture du nombre de segments type DRAW , TRACT, ZONE */
  180. if( stricmp( data, "Ndraw" ) == 0 )
  181. {
  182. data = strtok( NULL, " =\n\r" );
  183. NbDraw = atoi( data );;
  184. continue;
  185. }
  186. if( stricmp( data, "Ntrack" ) == 0 )
  187. {
  188. data = strtok( NULL, " =\n\r" );
  189. NbTrack = atoi( data );
  190. continue;
  191. }
  192. if( stricmp( data, "Nzone" ) == 0 )
  193. {
  194. data = strtok( NULL, " =\n\r" );
  195. NbZone = atoi( data );
  196. continue;
  197. }
  198. if( stricmp( data, "Nmodule" ) == 0 )
  199. {
  200. data = strtok( NULL, " =\n\r" );
  201. NbMod = atoi( data );
  202. continue;
  203. }
  204. if( stricmp( data, "Nnets" ) == 0 )
  205. {
  206. data = strtok( NULL, " =\n\r" );
  207. NbNets = atoi( data );
  208. continue;
  209. }
  210. }
  211. return 1;
  212. }
  213. /*************************************************************/
  214. int WinEDA_BasePcbFrame::ReadSetup( FILE* File, int* LineNum )
  215. /*************************************************************/
  216. {
  217. char Line[1024], * data;
  218. while( GetLine( File, Line, LineNum ) != NULL )
  219. {
  220. strtok( Line, " =\n\r" );
  221. data = strtok( NULL, " =\n\r" );
  222. if( stricmp( Line, "$EndSETUP" ) == 0 )
  223. {
  224. return 0;
  225. }
  226. if( stricmp( Line, "AuxiliaryAxisOrg" ) == 0 )
  227. {
  228. int gx = 0, gy = 0;
  229. gx = atoi( data );
  230. data = strtok( NULL, " =\n\r" );
  231. if( data )
  232. gy = atoi( data );
  233. m_Auxiliary_Axis_Position.x = gx;
  234. m_Auxiliary_Axis_Position.y = gy;
  235. continue;
  236. }
  237. #ifdef PCBNEW
  238. if( stricmp( Line, "Layers" ) == 0 )
  239. {
  240. int tmp;
  241. sscanf( data, "%d", &tmp );
  242. m_Pcb->m_BoardSettings->m_CopperLayerCount = tmp;
  243. continue;
  244. }
  245. if( stricmp( Line, "TrackWidth" ) == 0 )
  246. {
  247. g_DesignSettings.m_CurrentTrackWidth = atoi( data );
  248. AddHistory( g_DesignSettings.m_CurrentTrackWidth, TYPETRACK );
  249. continue;
  250. }
  251. if( stricmp( Line, "TrackWidthHistory" ) == 0 )
  252. {
  253. int tmp = atoi( data );
  254. AddHistory( tmp, TYPETRACK );
  255. continue;
  256. }
  257. if( stricmp( Line, "TrackClearence" ) == 0 )
  258. {
  259. g_DesignSettings.m_TrackClearence = atoi( data );
  260. continue;
  261. }
  262. if( stricmp( Line, "ZoneClearence" ) == 0 )
  263. {
  264. g_DesignSettings.m_ZoneClearence = atoi( data );
  265. continue;
  266. }
  267. if( stricmp( Line, "GridSize" ) == 0 )
  268. {
  269. wxSize Grid;
  270. Grid.x = atoi( data );
  271. data = strtok( NULL, " =\n\r" );
  272. if( data )
  273. Grid.y = atoi( data );
  274. else
  275. Grid.y = Grid.x;
  276. GetScreen()->SetGrid( Grid );
  277. continue;
  278. }
  279. if( stricmp( Line, "ZoneGridSize" ) == 0 )
  280. {
  281. g_GridRoutingSize = atoi( data );
  282. continue;
  283. }
  284. if( stricmp( Line, "UserGridSize" ) == 0 )
  285. {
  286. wxString msg;
  287. if( data )
  288. {
  289. msg = CONV_FROM_UTF8( data );
  290. msg.ToDouble( &g_UserGrid.x );
  291. }
  292. else
  293. continue;
  294. data = strtok( NULL, " =\n\r" );
  295. if( data )
  296. {
  297. msg = CONV_FROM_UTF8( data );
  298. msg.ToDouble( &g_UserGrid.y );
  299. }
  300. else
  301. g_UserGrid.y = g_UserGrid.x;
  302. GetScreen()->m_UserGrid = g_UserGrid;
  303. data = strtok( NULL, " =\n\r" );
  304. if( data )
  305. {
  306. if( stricmp( data, "mm" ) == 0 )
  307. g_UserGrid_Unit = MILLIMETRE;
  308. else
  309. g_UserGrid_Unit = INCHES;
  310. GetScreen()->m_UserGridUnit = g_UserGrid_Unit;
  311. }
  312. continue;
  313. }
  314. if( stricmp( Line, "DrawSegmWidth" ) == 0 )
  315. {
  316. g_DesignSettings.m_DrawSegmentWidth = atoi( data );
  317. continue;
  318. }
  319. if( stricmp( Line, "EdgeSegmWidth" ) == 0 )
  320. {
  321. g_DesignSettings.m_EdgeSegmentWidth = atoi( data );
  322. continue;
  323. }
  324. if( stricmp( Line, "ViaSize" ) == 0 )
  325. {
  326. g_DesignSettings.m_CurrentViaSize = atoi( data );
  327. AddHistory( g_DesignSettings.m_CurrentViaSize, TYPEVIA );
  328. continue;
  329. }
  330. if( stricmp( Line, "ViaSizeHistory" ) == 0 )
  331. {
  332. int tmp = atoi( data );
  333. AddHistory( tmp, TYPEVIA );
  334. continue;
  335. }
  336. if( stricmp( Line, "ViaDrill" ) == 0 )
  337. {
  338. g_DesignSettings.m_ViaDrill = atoi( data );
  339. continue;
  340. }
  341. if( stricmp( Line, "TextPcbWidth" ) == 0 )
  342. {
  343. g_DesignSettings.m_PcbTextWidth = atoi( data );
  344. continue;
  345. }
  346. if( stricmp( Line, "TextPcbSize" ) == 0 )
  347. {
  348. g_DesignSettings.m_PcbTextSize.x = atoi( data );
  349. data = strtok( NULL, " =\n\r" );
  350. g_DesignSettings.m_PcbTextSize.y = atoi( data );
  351. continue;
  352. }
  353. if( stricmp( Line, "EdgeModWidth" ) == 0 )
  354. {
  355. ModuleSegmentWidth = atoi( data );
  356. continue;
  357. }
  358. if( stricmp( Line, "TextModWidth" ) == 0 )
  359. {
  360. ModuleTextWidth = atoi( data );
  361. continue;
  362. }
  363. if( stricmp( Line, "TextModSize" ) == 0 )
  364. {
  365. ModuleTextSize.x = atoi( data );
  366. data = strtok( NULL, " =\n\r" );
  367. ModuleTextSize.y = atoi( data );
  368. continue;
  369. }
  370. if( stricmp( Line, "PadSize" ) == 0 )
  371. {
  372. g_Pad_Master.m_Size.x = atoi( data );
  373. data = strtok( NULL, " =\n\r" );
  374. g_Pad_Master.m_Size.y = atoi( data );
  375. continue;
  376. }
  377. if( stricmp( Line, "PadDrill" ) == 0 )
  378. {
  379. g_Pad_Master.m_Drill.x = atoi( data );
  380. g_Pad_Master.m_Drill.y = g_Pad_Master.m_Drill.x;
  381. continue;
  382. }
  383. #endif
  384. }
  385. return 1;
  386. }
  387. #ifdef PCBNEW
  388. /***************************************************************/
  389. static int WriteSetup( FILE* File, WinEDA_BasePcbFrame* frame )
  390. /***************************************************************/
  391. {
  392. char text[1024];
  393. int ii, jj;
  394. fprintf( File, "$SETUP\n" );
  395. sprintf( text, "InternalUnit %f INCH\n", 1.0 / PCB_INTERNAL_UNIT );
  396. fprintf( File, text );
  397. if( frame->GetScreen()->m_UserGridIsON )
  398. ii = jj = -1;
  399. else
  400. {
  401. ii = frame->GetScreen()->GetGrid().x;
  402. jj = frame->GetScreen()->GetGrid().y;
  403. }
  404. sprintf( text, "GridSize %d %d\n", ii, jj );
  405. fprintf( File, text );
  406. sprintf( text, "UserGridSize %lf %lf %s\n",
  407. frame->GetScreen()->m_UserGrid.x, frame->GetScreen()->m_UserGrid.y,
  408. ( g_UserGrid_Unit == 0 ) ? "INCH" : "mm" );
  409. fprintf( File, text );
  410. fprintf( File, "ZoneGridSize %d\n", g_GridRoutingSize );
  411. fprintf( File, "Layers %d\n", g_DesignSettings.m_CopperLayerCount );
  412. fprintf( File, "TrackWidth %d\n", g_DesignSettings.m_CurrentTrackWidth );
  413. for( ii = 0; ii < HIST0RY_NUMBER; ii++ )
  414. {
  415. if( g_DesignSettings.m_TrackWidhtHistory[ii] == 0 )
  416. break;
  417. fprintf( File, "TrackWidthHistory %d\n",
  418. g_DesignSettings.m_TrackWidhtHistory[ii] );
  419. }
  420. fprintf( File, "TrackClearence %d\n", g_DesignSettings.m_TrackClearence );
  421. fprintf( File, "ZoneClearence %d\n", g_DesignSettings.m_ZoneClearence );
  422. fprintf( File, "DrawSegmWidth %d\n", g_DesignSettings.m_DrawSegmentWidth );
  423. fprintf( File, "EdgeSegmWidth %d\n", g_DesignSettings.m_EdgeSegmentWidth );
  424. fprintf( File, "ViaSize %d\n", g_DesignSettings.m_CurrentViaSize );
  425. fprintf( File, "ViaDrill %d\n", g_DesignSettings.m_ViaDrill );
  426. for( ii = 0; ii < HIST0RY_NUMBER; ii++ )
  427. {
  428. if( g_DesignSettings.m_ViaSizeHistory[ii] == 0 )
  429. break;
  430. fprintf( File, "ViaSizeHistory %d\n", g_DesignSettings.m_ViaSizeHistory[ii] );
  431. }
  432. fprintf( File, "TextPcbWidth %d\n", g_DesignSettings.m_PcbTextWidth );
  433. fprintf( File, "TextPcbSize %d %d\n",
  434. g_DesignSettings.m_PcbTextSize.x, g_DesignSettings.m_PcbTextSize.y );
  435. fprintf( File, "EdgeModWidth %d\n", ModuleSegmentWidth );
  436. fprintf( File, "TextModSize %d %d\n", ModuleTextSize.x, ModuleTextSize.y );
  437. fprintf( File, "TextModWidth %d\n", ModuleTextWidth );
  438. fprintf( File, "PadSize %d %d\n", g_Pad_Master.m_Size.x, g_Pad_Master.m_Size.y );
  439. fprintf( File, "PadDrill %d\n", g_Pad_Master.m_Drill.x );
  440. fprintf( File, "AuxiliaryAxisOrg %d %d\n",
  441. frame->m_Auxiliary_Axis_Position.x, frame->m_Auxiliary_Axis_Position.y );
  442. fprintf( File, "$EndSETUP\n\n" );
  443. return 1;
  444. }
  445. #endif
  446. /******************************************************/
  447. bool WinEDA_PcbFrame::WriteGeneralDescrPcb( FILE* File )
  448. /******************************************************/
  449. {
  450. EDA_BaseStruct* PtStruct = m_Pcb->m_Modules;
  451. int NbModules, NbDrawItem, NbLayers;
  452. /* Write copper layer count */
  453. NbLayers = m_Pcb->m_BoardSettings->m_CopperLayerCount;
  454. fprintf( File, "$GENERAL\n" );
  455. fprintf( File, "LayerCount %d\n", NbLayers );
  456. // Write old format for Layer count (for compatibility with old versions of pcbnew
  457. fprintf( File, "Ly %8X\n", g_TabAllCopperLayerMask[NbLayers - 1] | ALL_NO_CU_LAYERS ); // For compatibility with old version of pcbnew
  458. fprintf( File, "Links %d\n", m_Pcb->m_NbLinks );
  459. fprintf( File, "NoConn %d\n", m_Pcb->m_NbNoconnect );
  460. /* Write Bounding box info */
  461. m_Pcb->ComputeBoundaryBox();
  462. fprintf( File, "Di %d %d %d %d\n",
  463. m_Pcb->m_BoundaryBox.GetX(), m_Pcb->m_BoundaryBox.GetY(),
  464. m_Pcb->m_BoundaryBox.GetRight(),
  465. m_Pcb->m_BoundaryBox.GetBottom() );
  466. /* Write segment count for footprints, drawings, track and zones */
  467. /* Calculate the footprint count */
  468. for( NbModules = 0; PtStruct != NULL; PtStruct = PtStruct->Pnext )
  469. NbModules++;
  470. PtStruct = m_Pcb->m_Drawings; NbDrawItem = 0;
  471. for( ; PtStruct != NULL; PtStruct = PtStruct->Pnext )
  472. NbDrawItem++;
  473. fprintf( File, "Ndraw %d\n", NbDrawItem );
  474. fprintf( File, "Ntrack %d\n", m_Pcb->GetNumSegmTrack() );
  475. fprintf( File, "Nzone %d\n", m_Pcb->GetNumSegmZone() );
  476. fprintf( File, "Nmodule %d\n", NbModules );
  477. fprintf( File, "Nnets %d\n", m_Pcb->m_NbNets );
  478. fprintf( File, "$EndGENERAL\n\n" );
  479. return TRUE;
  480. }
  481. /******************************************************/
  482. bool WriteSheetDescr( BASE_SCREEN* screen, FILE* File )
  483. /******************************************************/
  484. /** Function WriteSheetDescr
  485. * Save the page information (size, texts, date ..)
  486. * @param screen BASE_SCREEN to save
  487. * @param File = an openen FILE to write info
  488. */
  489. {
  490. Ki_PageDescr* sheet = screen->m_CurrentSheet;
  491. fprintf( File, "$SHEETDESCR\n" );
  492. fprintf( File, "Sheet %s %d %d\n",
  493. CONV_TO_UTF8( sheet->m_Name ), sheet->m_Size.x, sheet->m_Size.y );
  494. fprintf( File, "Title \"%s\"\n", CONV_TO_UTF8( screen->m_Title ) );
  495. fprintf( File, "Date \"%s\"\n", CONV_TO_UTF8( screen->m_Date ) );
  496. fprintf( File, "Rev \"%s\"\n", CONV_TO_UTF8( screen->m_Revision ) );
  497. fprintf( File, "Comp \"%s\"\n", CONV_TO_UTF8( screen->m_Company ) );
  498. fprintf( File, "Comment1 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire1 ) );
  499. fprintf( File, "Comment2 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire2 ) );
  500. fprintf( File, "Comment3 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire3 ) );
  501. fprintf( File, "Comment4 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire4 ) );
  502. fprintf( File, "$EndSHEETDESCR\n\n" );
  503. return TRUE;
  504. }
  505. /***************************************************************************/
  506. static bool ReadSheetDescr( BASE_SCREEN* screen, FILE* File, int* LineNum )
  507. /***************************************************************************/
  508. {
  509. char Line[1024], buf[1024], * text;
  510. while( GetLine( File, Line, LineNum ) != NULL )
  511. {
  512. if( strnicmp( Line, "$End", 4 ) == 0 )
  513. return TRUE;
  514. if( strnicmp( Line, "Sheet", 4 ) == 0 )
  515. {
  516. text = strtok( Line, " \t\n\r" );
  517. text = strtok( NULL, " \t\n\r" );
  518. Ki_PageDescr* sheet = SheetList[0];
  519. int ii;
  520. for( ii = 0; sheet != NULL; ii++, sheet = SheetList[ii] )
  521. {
  522. if( stricmp( CONV_TO_UTF8( sheet->m_Name ), text ) == 0 )
  523. {
  524. screen->m_CurrentSheet = sheet;
  525. if( sheet == &g_Sheet_user )
  526. {
  527. text = strtok( NULL, " \t\n\r" );
  528. if( text )
  529. sheet->m_Size.x = atoi( text );
  530. text = strtok( NULL, " \t\n\r" );
  531. if( text )
  532. sheet->m_Size.y = atoi( text );
  533. }
  534. break;
  535. }
  536. }
  537. continue;
  538. }
  539. if( strnicmp( Line, "Title", 2 ) == 0 )
  540. {
  541. ReadDelimitedText( buf, Line, 256 );
  542. screen->m_Title = CONV_FROM_UTF8( buf );
  543. continue;
  544. }
  545. if( strnicmp( Line, "Date", 2 ) == 0 )
  546. {
  547. ReadDelimitedText( buf, Line, 256 );
  548. screen->m_Date = CONV_FROM_UTF8( buf );
  549. continue;
  550. }
  551. if( strnicmp( Line, "Rev", 2 ) == 0 )
  552. {
  553. ReadDelimitedText( buf, Line, 256 );
  554. screen->m_Revision = CONV_FROM_UTF8( buf );
  555. continue;
  556. }
  557. if( strnicmp( Line, "Comp", 4 ) == 0 )
  558. {
  559. ReadDelimitedText( buf, Line, 256 );
  560. screen->m_Company = CONV_FROM_UTF8( buf );
  561. continue;
  562. }
  563. if( strnicmp( Line, "Comment1", 8 ) == 0 )
  564. {
  565. ReadDelimitedText( buf, Line, 256 );
  566. screen->m_Commentaire1 = CONV_FROM_UTF8( buf );
  567. continue;
  568. }
  569. if( strnicmp( Line, "Comment2", 8 ) == 0 )
  570. {
  571. ReadDelimitedText( buf, Line, 256 );
  572. screen->m_Commentaire2 = CONV_FROM_UTF8( buf );
  573. continue;
  574. }
  575. if( strnicmp( Line, "Comment3", 8 ) == 0 )
  576. {
  577. ReadDelimitedText( buf, Line, 256 );
  578. screen->m_Commentaire3 = CONV_FROM_UTF8( buf );
  579. continue;
  580. }
  581. if( strnicmp( Line, "Comment4", 8 ) == 0 )
  582. {
  583. ReadDelimitedText( buf, Line, 256 );
  584. screen->m_Commentaire4 = CONV_FROM_UTF8( buf );
  585. continue;
  586. }
  587. }
  588. return FALSE;
  589. }
  590. /********************************************************************/
  591. int WinEDA_PcbFrame::ReadPcbFile( wxDC* DC, FILE* File, bool Append )
  592. /********************************************************************/
  593. /** ReadPcbFile
  594. * Read a board file <file>.brd
  595. * @param Append if 0: a previoulsy loaded boar is delete before loadin the file.
  596. * else all items of the board file are added to the existing board
  597. */
  598. {
  599. char Line[1024];
  600. int LineNum = 0;
  601. int nbsegm, nbmod;
  602. BOARD_ITEM* LastStructPcb = NULL, * StructPcb;
  603. MODULE* LastModule = NULL, * Module;
  604. EQUIPOT* LastEquipot = NULL, * Equipot;
  605. wxBusyCursor dummy;
  606. // Switch the locale to standard C (needed to print floating point numbers like 1.3)
  607. setlocale( LC_NUMERIC, "C" );
  608. NbDraw = NbTrack = NbZone = NbMod = NbNets = -1;
  609. m_Pcb->m_NbNets = 0;
  610. m_Pcb->m_Status_Pcb = 0;
  611. nbmod = 0;
  612. if( Append )
  613. {
  614. LastModule = m_Pcb->m_Modules;
  615. for( ; LastModule != NULL; LastModule = (MODULE*) LastModule->Pnext )
  616. {
  617. if( LastModule->Pnext == NULL )
  618. break;
  619. }
  620. LastStructPcb = m_Pcb->m_Drawings;
  621. for( ; LastStructPcb != NULL; LastStructPcb = LastStructPcb->Next() )
  622. {
  623. if( LastStructPcb->Pnext == NULL )
  624. break;
  625. }
  626. LastEquipot = m_Pcb->m_Equipots;
  627. for( ; LastEquipot != NULL; LastEquipot = (EQUIPOT*) LastEquipot->Pnext )
  628. {
  629. if( LastEquipot->Pnext == NULL )
  630. break;
  631. }
  632. }
  633. while( GetLine( File, Line, &LineNum ) != NULL )
  634. {
  635. if( strnicmp( Line, "$EndPCB", 6 ) == 0 )
  636. break;
  637. if( strnicmp( Line, "$GENERAL", 8 ) == 0 )
  638. {
  639. ReadGeneralDescrPcb( File, &LineNum );
  640. continue;
  641. }
  642. if( strnicmp( Line, "$SHEETDESCR", 11 ) == 0 )
  643. {
  644. ReadSheetDescr( m_CurrentScreen, File, &LineNum );
  645. continue;
  646. }
  647. if( strnicmp( Line, "$SETUP", 6 ) == 0 )
  648. {
  649. if( !Append )
  650. {
  651. ReadSetup( File, &LineNum );
  652. }
  653. else
  654. {
  655. while( GetLine( File, Line, &LineNum ) != NULL )
  656. if( strnicmp( Line, "$EndSETUP", 6 ) == 0 )
  657. break;
  658. }
  659. continue;
  660. }
  661. if( strnicmp( Line, "$EQUIPOT", 7 ) == 0 )
  662. {
  663. Equipot = new EQUIPOT( m_Pcb );
  664. Equipot->ReadEquipotDescr( File, &LineNum );
  665. if( LastEquipot == NULL )
  666. {
  667. m_Pcb->m_Equipots = Equipot;
  668. Equipot->Pback = m_Pcb;
  669. }
  670. else
  671. {
  672. Equipot->Pback = LastEquipot;
  673. LastEquipot->Pnext = Equipot;
  674. }
  675. LastEquipot = Equipot;
  676. m_Pcb->m_NbNets++;
  677. continue;
  678. }
  679. if( strnicmp( Line, "$CZONE_OUTLINE", 7 ) == 0 )
  680. {
  681. ZONE_CONTAINER * zone_descr = new ZONE_CONTAINER(m_Pcb);
  682. zone_descr->ReadDescr( File, &LineNum );
  683. m_Pcb->m_ZoneDescriptorList.push_back(zone_descr);
  684. }
  685. if( strnicmp( Line, "$MODULE", 7 ) == 0 )
  686. {
  687. Module = new MODULE( m_Pcb );
  688. if( Module == NULL )
  689. continue;
  690. Module->ReadDescr( File, &LineNum );
  691. if( LastModule == NULL )
  692. {
  693. m_Pcb->m_Modules = Module;
  694. Module->Pback = m_Pcb;
  695. }
  696. else
  697. {
  698. Module->Pback = LastModule;
  699. LastModule->Pnext = Module;
  700. }
  701. LastModule = Module;
  702. nbmod++;
  703. continue;
  704. }
  705. if( strnicmp( Line, "$TEXTPCB", 8 ) == 0 )
  706. {
  707. TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_Pcb );
  708. StructPcb = pcbtxt;
  709. pcbtxt->ReadTextePcbDescr( File, &LineNum );
  710. if( LastStructPcb == NULL )
  711. {
  712. m_Pcb->m_Drawings = StructPcb;
  713. StructPcb->Pback = m_Pcb;
  714. }
  715. else
  716. {
  717. StructPcb->Pback = LastStructPcb;
  718. LastStructPcb->Pnext = StructPcb;
  719. }
  720. LastStructPcb = StructPcb;
  721. continue;
  722. }
  723. if( strnicmp( Line, "$DRAWSEGMENT", 10 ) == 0 )
  724. {
  725. DRAWSEGMENT* DrawSegm = new DRAWSEGMENT( m_Pcb );
  726. DrawSegm->ReadDrawSegmentDescr( File, &LineNum );
  727. if( LastStructPcb == NULL )
  728. {
  729. m_Pcb->m_Drawings = DrawSegm;
  730. DrawSegm->Pback = m_Pcb;
  731. }
  732. else
  733. {
  734. DrawSegm->Pback = LastStructPcb;
  735. LastStructPcb->Pnext = DrawSegm;
  736. }
  737. LastStructPcb = DrawSegm;
  738. continue;
  739. }
  740. if( strnicmp( Line, "$COTATION", 9 ) == 0 )
  741. {
  742. COTATION* Cotation = new COTATION( m_Pcb );
  743. Cotation->ReadCotationDescr( File, &LineNum );
  744. if( LastStructPcb == NULL )
  745. {
  746. m_Pcb->m_Drawings = Cotation;
  747. Cotation->Pback = m_Pcb;
  748. }
  749. else
  750. {
  751. Cotation->Pback = LastStructPcb;
  752. LastStructPcb->Pnext = Cotation;
  753. }
  754. LastStructPcb = Cotation;
  755. continue;
  756. }
  757. if( strnicmp( Line, "$MIREPCB", 8 ) == 0 )
  758. {
  759. MIREPCB* Mire = new MIREPCB( m_Pcb );
  760. Mire->ReadMirePcbDescr( File, &LineNum );
  761. if( LastStructPcb == NULL )
  762. {
  763. m_Pcb->m_Drawings = Mire;
  764. Mire->Pback = m_Pcb;
  765. }
  766. else
  767. {
  768. Mire->Pback = LastStructPcb;
  769. LastStructPcb->Pnext = Mire;
  770. }
  771. LastStructPcb = Mire;
  772. continue;
  773. }
  774. if( strnicmp( Line, "$TRACK", 6 ) == 0 )
  775. {
  776. TRACK* StartTrack = m_Pcb->m_Track;
  777. nbsegm = 0;
  778. if( Append )
  779. {
  780. for( ; StartTrack != NULL; StartTrack = StartTrack->Next() )
  781. {
  782. if( StartTrack->Pnext == NULL )
  783. break;
  784. }
  785. }
  786. #ifdef PCBNEW
  787. int ii = ReadListeSegmentDescr( File, StartTrack, TYPETRACK,
  788. &LineNum, NbTrack );
  789. m_Pcb->m_NbSegmTrack += ii;
  790. #endif
  791. continue;
  792. }
  793. if( strnicmp( Line, "$ZONE", 5 ) == 0 )
  794. {
  795. SEGZONE* StartZone = m_Pcb->m_Zone;
  796. if( Append )
  797. {
  798. for( ; StartZone != NULL; StartZone = StartZone->Next() )
  799. {
  800. if( StartZone->Pnext == NULL )
  801. break;
  802. }
  803. }
  804. #ifdef PCBNEW
  805. int ii = ReadListeSegmentDescr( File, StartZone, TYPEZONE,
  806. &LineNum, NbZone );
  807. m_Pcb->m_NbSegmZone += ii;
  808. #endif
  809. continue;
  810. }
  811. }
  812. setlocale( LC_NUMERIC, "" ); // revert to the current locale
  813. Affiche_Message( wxEmptyString );
  814. BestZoom();
  815. DrawPanel->ReDraw(DC, true);
  816. #ifdef PCBNEW
  817. Compile_Ratsnest( DC, TRUE );
  818. #endif
  819. return 1;
  820. }
  821. #ifdef PCBNEW
  822. /***************************************************/
  823. int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* aFile )
  824. /****************************************************/
  825. /* Routine de sauvegarde du PCB courant sous format ASCII
  826. * retourne
  827. * 1 si OK
  828. * 0 si sauvegarde non faite
  829. */
  830. {
  831. bool rc;
  832. char line[256];
  833. m_Pcb->m_Status_Pcb &= ~CONNEXION_OK;
  834. wxBeginBusyCursor();
  835. // Switch the locale to standard C (needed to print floating point numbers like 1.3)
  836. setlocale( LC_NUMERIC, "C" );
  837. /* Ecriture de l'entete PCB : */
  838. fprintf( aFile, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB,
  839. DateAndTime( line ) );
  840. WriteGeneralDescrPcb( aFile );
  841. WriteSheetDescr( m_CurrentScreen, aFile );
  842. WriteSetup( aFile, this );
  843. rc = m_Pcb->Save( aFile );
  844. setlocale( LC_NUMERIC, "" ); // revert to the current locale
  845. wxEndBusyCursor();
  846. if( !rc )
  847. DisplayError( this, wxT( "Unable to save PCB file" ) );
  848. else
  849. Affiche_Message( wxEmptyString );
  850. return rc;
  851. }
  852. #endif