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.

949 lines
29 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 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 "common.h"
  8. #include "pcbnew.h"
  9. #ifdef PCBNEW
  10. #include "pcbnew.h"
  11. #include "autorout.h"
  12. #include "zones.h"
  13. #endif
  14. #ifdef CVPCB
  15. #include "cvpcb.h"
  16. #endif
  17. #include "id.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* insertBeforeMe, 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, drill, 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. // TYPE_TRACK, TYPE_VIA, or TYPE_ZONE. The type field in 2nd line
  85. // differentiates between TYPE_TRACK and TYPE_VIA. With virtual
  86. // functions in use, it is critical to instantiate the TYPE_VIA 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==TYPE_TRACK && type==1 )
  95. makeType = TYPE_VIA;
  96. else
  97. makeType = StructType;
  98. switch( makeType )
  99. {
  100. default:
  101. case TYPE_TRACK:
  102. newTrack = new TRACK( m_Pcb );
  103. m_Pcb->m_Track.Insert( newTrack, insertBeforeMe );
  104. break;
  105. case TYPE_VIA:
  106. newTrack = new SEGVIA( m_Pcb );
  107. m_Pcb->m_Track.Insert( newTrack, insertBeforeMe );
  108. break;
  109. case TYPE_ZONE:
  110. newTrack = new SEGZONE( m_Pcb );
  111. m_Pcb->m_Zone.Insert( (SEGZONE*)newTrack, (SEGZONE*)insertBeforeMe );
  112. break;
  113. }
  114. newTrack->m_TimeStamp = timeStamp;
  115. int arg_count = sscanf( line1 + 2, " %d %d %d %d %d %d %d", &shape,
  116. &newTrack->m_Start.x, &newTrack->m_Start.y,
  117. &newTrack->m_End.x, &newTrack->m_End.y, &width,
  118. &drill );
  119. newTrack->m_Width = width;
  120. newTrack->m_Shape = shape;
  121. if( arg_count < 7 || drill <= 0 )
  122. newTrack->SetDrillDefault();
  123. else
  124. newTrack->SetDrillValue(drill);
  125. newTrack->SetLayer( layer );
  126. newTrack->SetNet( net_code );
  127. newTrack->SetState( flags, ON );
  128. }
  129. DisplayError( this, _( "Error: Unexpected end of file !" ) );
  130. return -ii;
  131. }
  132. /**********************************************************************************/
  133. int WinEDA_BasePcbFrame::ReadGeneralDescrPcb( FILE* File, int* LineNum )
  134. /**********************************************************************************/
  135. {
  136. char Line[1024], * data;
  137. while( GetLine( File, Line, LineNum ) != NULL )
  138. {
  139. data = strtok( Line, " =\n\r" );
  140. if( strnicmp( data, "$EndGENERAL", 10 ) == 0 )
  141. break;
  142. if( strncmp( data, "Ly", 2 ) == 0 ) // Old format for Layer count
  143. {
  144. int Masque_Layer = 1, ii;
  145. data = strtok( NULL, " =\n\r" );
  146. sscanf( data, "%X", &Masque_Layer );
  147. // Setup layer count
  148. m_Pcb->m_BoardSettings->m_CopperLayerCount = 0;
  149. for( ii = 0; ii < NB_COPPER_LAYERS; ii++ )
  150. {
  151. if( Masque_Layer & 1 )
  152. m_Pcb->m_BoardSettings->m_CopperLayerCount++;
  153. Masque_Layer >>= 1;
  154. }
  155. continue;
  156. }
  157. if( strnicmp( data, "Links", 5 ) == 0 )
  158. {
  159. data = strtok( NULL, " =\n\r" );
  160. m_Pcb->m_NbLinks = atoi( data );
  161. continue;
  162. }
  163. if( strnicmp( data, "NoConn", 6 ) == 0 )
  164. {
  165. data = strtok( NULL, " =\n\r" );
  166. m_Pcb->m_NbNoconnect = atoi( data );
  167. continue;
  168. }
  169. if( strnicmp( data, "Di", 2 ) == 0 )
  170. {
  171. wxSize pcbsize, screensize;
  172. data = strtok( NULL, " =\n\r" );
  173. m_Pcb->m_BoundaryBox.SetX( atoi( data ) );
  174. data = strtok( NULL, " =\n\r" );
  175. m_Pcb->m_BoundaryBox.SetY( atoi( data ) );
  176. data = strtok( NULL, " =\n\r" );
  177. m_Pcb->m_BoundaryBox.SetWidth( atoi( data ) - m_Pcb->m_BoundaryBox.GetX() );
  178. data = strtok( NULL, " =\n\r" );
  179. m_Pcb->m_BoundaryBox.SetHeight( atoi( data ) - m_Pcb->m_BoundaryBox.GetY() );
  180. continue;
  181. }
  182. /* Lecture du nombre de segments type DRAW , TRACT, ZONE */
  183. if( stricmp( data, "Ndraw" ) == 0 )
  184. {
  185. data = strtok( NULL, " =\n\r" );
  186. NbDraw = atoi( data );;
  187. continue;
  188. }
  189. if( stricmp( data, "Ntrack" ) == 0 )
  190. {
  191. data = strtok( NULL, " =\n\r" );
  192. NbTrack = atoi( data );
  193. continue;
  194. }
  195. if( stricmp( data, "Nzone" ) == 0 )
  196. {
  197. data = strtok( NULL, " =\n\r" );
  198. NbZone = atoi( data );
  199. continue;
  200. }
  201. if( stricmp( data, "Nmodule" ) == 0 )
  202. {
  203. data = strtok( NULL, " =\n\r" );
  204. NbMod = atoi( data );
  205. continue;
  206. }
  207. if( stricmp( data, "Nnets" ) == 0 )
  208. {
  209. data = strtok( NULL, " =\n\r" );
  210. NbNets = atoi( data );
  211. continue;
  212. }
  213. }
  214. return 1;
  215. }
  216. /*************************************************************/
  217. int WinEDA_BasePcbFrame::ReadSetup( FILE* File, int* LineNum )
  218. /*************************************************************/
  219. {
  220. char Line[1024], * data;
  221. while( GetLine( File, Line, LineNum ) != NULL )
  222. {
  223. strtok( Line, " =\n\r" );
  224. data = strtok( NULL, " =\n\r" );
  225. if( stricmp( Line, "$EndSETUP" ) == 0 )
  226. {
  227. return 0;
  228. }
  229. if( stricmp( Line, "AuxiliaryAxisOrg" ) == 0 )
  230. {
  231. int gx = 0, gy = 0;
  232. gx = atoi( data );
  233. data = strtok( NULL, " =\n\r" );
  234. if( data )
  235. gy = atoi( data );
  236. m_Auxiliary_Axis_Position.x = gx;
  237. m_Auxiliary_Axis_Position.y = gy;
  238. continue;
  239. }
  240. #ifdef PCBNEW
  241. if( stricmp( Line, "Layers" ) == 0 )
  242. {
  243. int tmp;
  244. sscanf( data, "%d", &tmp );
  245. m_Pcb->m_BoardSettings->m_CopperLayerCount = tmp;
  246. continue;
  247. }
  248. const int LAYERKEYZ = sizeof("Layer[")-1;
  249. if( strncmp( Line, "Layer[", LAYERKEYZ ) == 0 )
  250. {
  251. // parse:
  252. // Layer[n] <a_Layer_name_with_no_spaces> <LAYER_T>
  253. char* cp = Line + LAYERKEYZ;
  254. int layer = atoi(cp);
  255. if( data )
  256. {
  257. wxString layerName = CONV_FROM_UTF8( data );
  258. m_Pcb->SetLayerName( layer, layerName );
  259. data = strtok( NULL, " " );
  260. if( data )
  261. {
  262. LAYER_T type = LAYER::ParseType( data );
  263. m_Pcb->SetLayerType( layer, type );
  264. }
  265. }
  266. continue;
  267. }
  268. if( stricmp( Line, "TrackWidth" ) == 0 )
  269. {
  270. g_DesignSettings.m_CurrentTrackWidth = atoi( data );
  271. AddHistory( g_DesignSettings.m_CurrentTrackWidth, TYPE_TRACK );
  272. continue;
  273. }
  274. if( stricmp( Line, "TrackWidthHistory" ) == 0 )
  275. {
  276. int tmp = atoi( data );
  277. AddHistory( tmp, TYPE_TRACK );
  278. continue;
  279. }
  280. if( stricmp( Line, "TrackClearence" ) == 0 )
  281. {
  282. g_DesignSettings.m_TrackClearence = atoi( data );
  283. continue;
  284. }
  285. if( stricmp( Line, "ZoneClearence" ) == 0 )
  286. {
  287. g_Zone_Default_Setting.m_ZoneClearance = atoi( data );
  288. continue;
  289. }
  290. if( stricmp( Line, "ZoneGridSize" ) == 0 )
  291. {
  292. g_GridRoutingSize = atoi( data );
  293. continue;
  294. }
  295. if( stricmp( Line, "UserGridSize" ) == 0 )
  296. {
  297. wxString msg;
  298. if( data )
  299. {
  300. msg = CONV_FROM_UTF8( data );
  301. msg.ToDouble( &g_UserGrid.x );
  302. }
  303. else
  304. continue;
  305. data = strtok( NULL, " =\n\r" );
  306. if( data )
  307. {
  308. msg = CONV_FROM_UTF8( data );
  309. msg.ToDouble( &g_UserGrid.y );
  310. }
  311. else
  312. g_UserGrid.y = g_UserGrid.x;
  313. data = strtok( NULL, " =\n\r" );
  314. if( data )
  315. {
  316. if( stricmp( data, "mm" ) == 0 )
  317. g_UserGrid_Unit = MILLIMETRE;
  318. else
  319. g_UserGrid_Unit = INCHES;
  320. GetScreen()->AddGrid( g_UserGrid, g_UserGrid_Unit,
  321. ID_POPUP_GRID_USER );
  322. }
  323. continue;
  324. }
  325. if( stricmp( Line, "DrawSegmWidth" ) == 0 )
  326. {
  327. g_DesignSettings.m_DrawSegmentWidth = atoi( data );
  328. continue;
  329. }
  330. if( stricmp( Line, "EdgeSegmWidth" ) == 0 )
  331. {
  332. g_DesignSettings.m_EdgeSegmentWidth = atoi( data );
  333. continue;
  334. }
  335. if( stricmp( Line, "ViaSize" ) == 0 )
  336. {
  337. g_DesignSettings.m_CurrentViaSize = atoi( data );
  338. AddHistory( g_DesignSettings.m_CurrentViaSize, TYPE_VIA );
  339. continue;
  340. }
  341. if( stricmp( Line, "MicroViaSize" ) == 0 )
  342. {
  343. g_DesignSettings.m_CurrentMicroViaSize = atoi( data );
  344. continue;
  345. }
  346. if( stricmp( Line, "ViaSizeHistory" ) == 0 )
  347. {
  348. int tmp = atoi( data );
  349. AddHistory( tmp, TYPE_VIA );
  350. continue;
  351. }
  352. if( stricmp( Line, "ViaDrill" ) == 0 )
  353. {
  354. g_DesignSettings.m_ViaDrill = atoi( data );
  355. continue;
  356. }
  357. if( stricmp( Line, "MicroViaDrill" ) == 0 )
  358. {
  359. g_DesignSettings.m_MicroViaDrill = atoi( data );
  360. continue;
  361. }
  362. if( stricmp( Line, "MicroViasAllowed" ) == 0 )
  363. {
  364. g_DesignSettings.m_MicroViasAllowed = atoi( data );
  365. continue;
  366. }
  367. if( stricmp( Line, "TextPcbWidth" ) == 0 )
  368. {
  369. g_DesignSettings.m_PcbTextWidth = atoi( data );
  370. continue;
  371. }
  372. if( stricmp( Line, "TextPcbSize" ) == 0 )
  373. {
  374. g_DesignSettings.m_PcbTextSize.x = atoi( data );
  375. data = strtok( NULL, " =\n\r" );
  376. g_DesignSettings.m_PcbTextSize.y = atoi( data );
  377. continue;
  378. }
  379. if( stricmp( Line, "EdgeModWidth" ) == 0 )
  380. {
  381. ModuleSegmentWidth = atoi( data );
  382. continue;
  383. }
  384. if( stricmp( Line, "TextModWidth" ) == 0 )
  385. {
  386. ModuleTextWidth = atoi( data );
  387. continue;
  388. }
  389. if( stricmp( Line, "TextModSize" ) == 0 )
  390. {
  391. ModuleTextSize.x = atoi( data );
  392. data = strtok( NULL, " =\n\r" );
  393. ModuleTextSize.y = atoi( data );
  394. continue;
  395. }
  396. if( stricmp( Line, "PadSize" ) == 0 )
  397. {
  398. g_Pad_Master.m_Size.x = atoi( data );
  399. data = strtok( NULL, " =\n\r" );
  400. g_Pad_Master.m_Size.y = atoi( data );
  401. continue;
  402. }
  403. if( stricmp( Line, "PadDrill" ) == 0 )
  404. {
  405. g_Pad_Master.m_Drill.x = atoi( data );
  406. g_Pad_Master.m_Drill.y = g_Pad_Master.m_Drill.x;
  407. continue;
  408. }
  409. #endif
  410. }
  411. return 1;
  412. }
  413. #ifdef PCBNEW
  414. /******************************************************************************/
  415. static int WriteSetup( FILE* aFile, WinEDA_BasePcbFrame* aFrame, BOARD* aBoard )
  416. /******************************************************************************/
  417. {
  418. char text[1024];
  419. int ii;
  420. fprintf( aFile, "$SETUP\n" );
  421. sprintf( text, "InternalUnit %f INCH\n", 1.0 / PCB_INTERNAL_UNIT );
  422. fprintf( aFile, text );
  423. sprintf( text, "UserGridSize %lf %lf %s\n", g_UserGrid.x, g_UserGrid.y,
  424. ( g_UserGrid_Unit == 0 ) ? "INCH" : "mm" );
  425. fprintf( aFile, text );
  426. fprintf( aFile, "ZoneGridSize %d\n", g_GridRoutingSize );
  427. fprintf( aFile, "Layers %d\n", aBoard->GetCopperLayerCount() );
  428. unsigned layerMask = g_TabAllCopperLayerMask[aBoard->GetCopperLayerCount()-1];
  429. for( int layer=0; layerMask; ++layer, layerMask>>=1 )
  430. {
  431. if( layerMask & 1 )
  432. {
  433. fprintf( aFile, "Layer[%d] %s %s\n", layer,
  434. CONV_TO_UTF8( aBoard->GetLayerName(layer) ),
  435. LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
  436. }
  437. }
  438. fprintf( aFile, "TrackWidth %d\n", g_DesignSettings.m_CurrentTrackWidth );
  439. for( int ii = 0; ii < HISTORY_NUMBER; ii++ )
  440. {
  441. if( g_DesignSettings.m_TrackWidthHistory[ii] == 0 )
  442. break;
  443. fprintf( aFile, "TrackWidthHistory %d\n",
  444. g_DesignSettings.m_TrackWidthHistory[ii] );
  445. }
  446. fprintf( aFile, "TrackClearence %d\n", g_DesignSettings.m_TrackClearence );
  447. fprintf( aFile, "ZoneClearence %d\n", g_Zone_Default_Setting.m_ZoneClearance );
  448. fprintf( aFile, "DrawSegmWidth %d\n", g_DesignSettings.m_DrawSegmentWidth );
  449. fprintf( aFile, "EdgeSegmWidth %d\n", g_DesignSettings.m_EdgeSegmentWidth );
  450. fprintf( aFile, "ViaSize %d\n", g_DesignSettings.m_CurrentViaSize );
  451. fprintf( aFile, "ViaDrill %d\n", g_DesignSettings.m_ViaDrill );
  452. for( ii = 0; ii < HISTORY_NUMBER; ii++ )
  453. {
  454. if( g_DesignSettings.m_ViaSizeHistory[ii] == 0 )
  455. break;
  456. fprintf( aFile, "ViaSizeHistory %d\n", g_DesignSettings.m_ViaSizeHistory[ii] );
  457. }
  458. fprintf( aFile, "MicroViaSize %d\n", g_DesignSettings.m_CurrentMicroViaSize);
  459. fprintf( aFile, "MicroViaDrill %d\n", g_DesignSettings.m_MicroViaDrill);
  460. fprintf( aFile, "MicroViasAllowed %d\n", g_DesignSettings.m_MicroViasAllowed);
  461. fprintf( aFile, "TextPcbWidth %d\n", g_DesignSettings.m_PcbTextWidth );
  462. fprintf( aFile, "TextPcbSize %d %d\n",
  463. g_DesignSettings.m_PcbTextSize.x, g_DesignSettings.m_PcbTextSize.y );
  464. fprintf( aFile, "EdgeModWidth %d\n", ModuleSegmentWidth );
  465. fprintf( aFile, "TextModSize %d %d\n", ModuleTextSize.x, ModuleTextSize.y );
  466. fprintf( aFile, "TextModWidth %d\n", ModuleTextWidth );
  467. fprintf( aFile, "PadSize %d %d\n", g_Pad_Master.m_Size.x, g_Pad_Master.m_Size.y );
  468. fprintf( aFile, "PadDrill %d\n", g_Pad_Master.m_Drill.x );
  469. fprintf( aFile, "AuxiliaryAxisOrg %d %d\n",
  470. aFrame->m_Auxiliary_Axis_Position.x, aFrame->m_Auxiliary_Axis_Position.y );
  471. fprintf( aFile, "$EndSETUP\n\n" );
  472. return 1;
  473. }
  474. #endif
  475. /******************************************************/
  476. bool WinEDA_PcbFrame::WriteGeneralDescrPcb( FILE* File )
  477. /******************************************************/
  478. {
  479. EDA_BaseStruct* PtStruct = m_Pcb->m_Modules;
  480. int NbModules, NbDrawItem, NbLayers;
  481. /* Write copper layer count */
  482. NbLayers = m_Pcb->m_BoardSettings->m_CopperLayerCount;
  483. fprintf( File, "$GENERAL\n" );
  484. fprintf( File, "LayerCount %d\n", NbLayers );
  485. // Write old format for Layer count (for compatibility with old versions of pcbnew
  486. fprintf( File, "Ly %8X\n", g_TabAllCopperLayerMask[NbLayers - 1] | ALL_NO_CU_LAYERS ); // For compatibility with old version of pcbnew
  487. fprintf( File, "Links %d\n", m_Pcb->m_NbLinks );
  488. fprintf( File, "NoConn %d\n", m_Pcb->m_NbNoconnect );
  489. /* Write Bounding box info */
  490. m_Pcb->ComputeBoundaryBox();
  491. fprintf( File, "Di %d %d %d %d\n",
  492. m_Pcb->m_BoundaryBox.GetX(), m_Pcb->m_BoundaryBox.GetY(),
  493. m_Pcb->m_BoundaryBox.GetRight(),
  494. m_Pcb->m_BoundaryBox.GetBottom() );
  495. /* Write segment count for footprints, drawings, track and zones */
  496. /* Calculate the footprint count */
  497. for( NbModules = 0; PtStruct != NULL; PtStruct = PtStruct->Next() )
  498. NbModules++;
  499. PtStruct = m_Pcb->m_Drawings; NbDrawItem = 0;
  500. for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
  501. NbDrawItem++;
  502. fprintf( File, "Ndraw %d\n", NbDrawItem );
  503. fprintf( File, "Ntrack %d\n", m_Pcb->GetNumSegmTrack() );
  504. fprintf( File, "Nzone %d\n", m_Pcb->GetNumSegmZone() );
  505. fprintf( File, "Nmodule %d\n", NbModules );
  506. fprintf( File, "Nnets %d\n", m_Pcb->m_Equipots.GetCount() );
  507. fprintf( File, "$EndGENERAL\n\n" );
  508. return TRUE;
  509. }
  510. /******************************************************/
  511. bool WriteSheetDescr( BASE_SCREEN* screen, FILE* File )
  512. /******************************************************/
  513. /** Function WriteSheetDescr
  514. * Save the page information (size, texts, date ..)
  515. * @param screen BASE_SCREEN to save
  516. * @param File = an openen FILE to write info
  517. */
  518. {
  519. Ki_PageDescr* sheet = screen->m_CurrentSheetDesc;
  520. fprintf( File, "$SHEETDESCR\n" );
  521. fprintf( File, "Sheet %s %d %d\n",
  522. CONV_TO_UTF8( sheet->m_Name ), sheet->m_Size.x, sheet->m_Size.y );
  523. fprintf( File, "Title \"%s\"\n", CONV_TO_UTF8( screen->m_Title ) );
  524. fprintf( File, "Date \"%s\"\n", CONV_TO_UTF8( screen->m_Date ) );
  525. fprintf( File, "Rev \"%s\"\n", CONV_TO_UTF8( screen->m_Revision ) );
  526. fprintf( File, "Comp \"%s\"\n", CONV_TO_UTF8( screen->m_Company ) );
  527. fprintf( File, "Comment1 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire1 ) );
  528. fprintf( File, "Comment2 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire2 ) );
  529. fprintf( File, "Comment3 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire3 ) );
  530. fprintf( File, "Comment4 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire4 ) );
  531. fprintf( File, "$EndSHEETDESCR\n\n" );
  532. return TRUE;
  533. }
  534. /***************************************************************************/
  535. static bool ReadSheetDescr( BASE_SCREEN* screen, FILE* File, int* LineNum )
  536. /***************************************************************************/
  537. {
  538. char Line[1024], buf[1024], * text;
  539. while( GetLine( File, Line, LineNum ) != NULL )
  540. {
  541. if( strnicmp( Line, "$End", 4 ) == 0 )
  542. return TRUE;
  543. if( strnicmp( Line, "Sheet", 4 ) == 0 )
  544. {
  545. text = strtok( Line, " \t\n\r" );
  546. text = strtok( NULL, " \t\n\r" );
  547. Ki_PageDescr* sheet = SheetList[0];
  548. int ii;
  549. for( ii = 0; sheet != NULL; ii++, sheet = SheetList[ii] )
  550. {
  551. if( stricmp( CONV_TO_UTF8( sheet->m_Name ), text ) == 0 )
  552. {
  553. screen->m_CurrentSheetDesc = sheet;
  554. if( sheet == &g_Sheet_user )
  555. {
  556. text = strtok( NULL, " \t\n\r" );
  557. if( text )
  558. sheet->m_Size.x = atoi( text );
  559. text = strtok( NULL, " \t\n\r" );
  560. if( text )
  561. sheet->m_Size.y = atoi( text );
  562. }
  563. break;
  564. }
  565. }
  566. continue;
  567. }
  568. if( strnicmp( Line, "Title", 2 ) == 0 )
  569. {
  570. ReadDelimitedText( buf, Line, 256 );
  571. screen->m_Title = CONV_FROM_UTF8( buf );
  572. continue;
  573. }
  574. if( strnicmp( Line, "Date", 2 ) == 0 )
  575. {
  576. ReadDelimitedText( buf, Line, 256 );
  577. screen->m_Date = CONV_FROM_UTF8( buf );
  578. continue;
  579. }
  580. if( strnicmp( Line, "Rev", 2 ) == 0 )
  581. {
  582. ReadDelimitedText( buf, Line, 256 );
  583. screen->m_Revision = CONV_FROM_UTF8( buf );
  584. continue;
  585. }
  586. if( strnicmp( Line, "Comp", 4 ) == 0 )
  587. {
  588. ReadDelimitedText( buf, Line, 256 );
  589. screen->m_Company = CONV_FROM_UTF8( buf );
  590. continue;
  591. }
  592. if( strnicmp( Line, "Comment1", 8 ) == 0 )
  593. {
  594. ReadDelimitedText( buf, Line, 256 );
  595. screen->m_Commentaire1 = CONV_FROM_UTF8( buf );
  596. continue;
  597. }
  598. if( strnicmp( Line, "Comment2", 8 ) == 0 )
  599. {
  600. ReadDelimitedText( buf, Line, 256 );
  601. screen->m_Commentaire2 = CONV_FROM_UTF8( buf );
  602. continue;
  603. }
  604. if( strnicmp( Line, "Comment3", 8 ) == 0 )
  605. {
  606. ReadDelimitedText( buf, Line, 256 );
  607. screen->m_Commentaire3 = CONV_FROM_UTF8( buf );
  608. continue;
  609. }
  610. if( strnicmp( Line, "Comment4", 8 ) == 0 )
  611. {
  612. ReadDelimitedText( buf, Line, 256 );
  613. screen->m_Commentaire4 = CONV_FROM_UTF8( buf );
  614. continue;
  615. }
  616. }
  617. return FALSE;
  618. }
  619. /********************************************************************/
  620. int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
  621. /********************************************************************/
  622. /** ReadPcbFile
  623. * Read a board file <file>.brd
  624. * @param Append if 0: a previoulsy loaded boar is delete before loadin the file.
  625. * else all items of the board file are added to the existing board
  626. */
  627. {
  628. char Line[1024];
  629. int LineNum = 0;
  630. wxBusyCursor dummy;
  631. // Switch the locale to standard C (needed to read floating point numbers like 1.3)
  632. SetLocaleTo_C_standard( );
  633. NbDraw = NbTrack = NbZone = NbMod = NbNets = -1;
  634. m_Pcb->m_Status_Pcb = 0;
  635. while( GetLine( File, Line, &LineNum ) != NULL )
  636. {
  637. if( strnicmp( Line, "$EndPCB", 6 ) == 0 )
  638. break;
  639. if( strnicmp( Line, "$GENERAL", 8 ) == 0 )
  640. {
  641. ReadGeneralDescrPcb( File, &LineNum );
  642. continue;
  643. }
  644. if( strnicmp( Line, "$SHEETDESCR", 11 ) == 0 )
  645. {
  646. ReadSheetDescr( GetScreen(), File, &LineNum );
  647. continue;
  648. }
  649. if( strnicmp( Line, "$SETUP", 6 ) == 0 )
  650. {
  651. if( !Append )
  652. {
  653. ReadSetup( File, &LineNum );
  654. }
  655. else
  656. {
  657. while( GetLine( File, Line, &LineNum ) != NULL )
  658. if( strnicmp( Line, "$EndSETUP", 6 ) == 0 )
  659. break;
  660. }
  661. continue;
  662. }
  663. if( strnicmp( Line, "$EQUIPOT", 7 ) == 0 )
  664. {
  665. EQUIPOT* Equipot = new EQUIPOT( m_Pcb );
  666. m_Pcb->m_Equipots.PushBack( Equipot );
  667. Equipot->ReadEquipotDescr( File, &LineNum );
  668. continue;
  669. }
  670. if( strnicmp( Line, "$CZONE_OUTLINE", 7 ) == 0 )
  671. {
  672. ZONE_CONTAINER * zone_descr = new ZONE_CONTAINER(m_Pcb);
  673. zone_descr->ReadDescr( File, &LineNum );
  674. if ( zone_descr->GetNumCorners( ) > 2 ) // should not occur
  675. m_Pcb->Add(zone_descr);
  676. else delete zone_descr;
  677. continue;
  678. }
  679. if( strnicmp( Line, "$MODULE", 7 ) == 0 )
  680. {
  681. MODULE* Module = new MODULE( m_Pcb );
  682. if( Module == NULL )
  683. continue;
  684. m_Pcb->Add( Module, ADD_APPEND );
  685. Module->ReadDescr( File, &LineNum );
  686. continue;
  687. }
  688. if( strnicmp( Line, "$TEXTPCB", 8 ) == 0 )
  689. {
  690. TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_Pcb );
  691. m_Pcb->Add( pcbtxt, ADD_APPEND );
  692. pcbtxt->ReadTextePcbDescr( File, &LineNum );
  693. continue;
  694. }
  695. if( strnicmp( Line, "$DRAWSEGMENT", 10 ) == 0 )
  696. {
  697. DRAWSEGMENT* DrawSegm = new DRAWSEGMENT( m_Pcb );
  698. m_Pcb->Add( DrawSegm, ADD_APPEND );
  699. DrawSegm->ReadDrawSegmentDescr( File, &LineNum );
  700. continue;
  701. }
  702. if( strnicmp( Line, "$COTATION", 9 ) == 0 )
  703. {
  704. COTATION* Cotation = new COTATION( m_Pcb );
  705. m_Pcb->Add( Cotation, ADD_APPEND );
  706. Cotation->ReadCotationDescr( File, &LineNum );
  707. continue;
  708. }
  709. if( strnicmp( Line, "$MIREPCB", 8 ) == 0 )
  710. {
  711. MIREPCB* Mire = new MIREPCB( m_Pcb );
  712. m_Pcb->Add( Mire, ADD_APPEND );
  713. Mire->ReadMirePcbDescr( File, &LineNum );
  714. continue;
  715. }
  716. if( strnicmp( Line, "$TRACK", 6 ) == 0 )
  717. {
  718. #ifdef PCBNEW
  719. TRACK* insertBeforeMe = Append ? NULL : m_Pcb->m_Track.GetFirst();
  720. ReadListeSegmentDescr( File, insertBeforeMe, TYPE_TRACK,
  721. &LineNum, NbTrack );
  722. D( m_Pcb->m_Track.VerifyListIntegrity(); )
  723. #endif
  724. continue;
  725. }
  726. if( strnicmp( Line, "$ZONE", 5 ) == 0 )
  727. {
  728. #ifdef PCBNEW
  729. SEGZONE* insertBeforeMe = Append ? NULL : m_Pcb->m_Zone.GetFirst();
  730. ReadListeSegmentDescr( File, insertBeforeMe, TYPE_ZONE,
  731. &LineNum, NbZone );
  732. D( m_Pcb->m_Zone.VerifyListIntegrity(); )
  733. #endif
  734. continue;
  735. }
  736. }
  737. SetLocaleTo_Default( ); // revert to the current locale
  738. Affiche_Message( wxEmptyString );
  739. BestZoom();
  740. #ifdef PCBNEW
  741. // Build connectivity info
  742. Compile_Ratsnest( NULL, TRUE );
  743. #endif
  744. return 1;
  745. }
  746. #ifdef PCBNEW
  747. /***************************************************/
  748. int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* aFile )
  749. /****************************************************/
  750. /* Routine de sauvegarde du PCB courant sous format ASCII
  751. * retourne
  752. * 1 si OK
  753. * 0 si sauvegarde non faite
  754. */
  755. {
  756. bool rc;
  757. char line[256];
  758. m_Pcb->m_Status_Pcb &= ~CONNEXION_OK;
  759. wxBeginBusyCursor();
  760. // Switch the locale to standard C (needed to print floating point numbers like 1.3)
  761. SetLocaleTo_C_standard( );
  762. /* Ecriture de l'entete PCB : */
  763. fprintf( aFile, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB,
  764. DateAndTime( line ) );
  765. WriteGeneralDescrPcb( aFile );
  766. WriteSheetDescr( GetScreen(), aFile );
  767. WriteSetup( aFile, this, m_Pcb );
  768. rc = m_Pcb->Save( aFile );
  769. SetLocaleTo_Default( ); // revert to the current locale
  770. wxEndBusyCursor();
  771. if( !rc )
  772. DisplayError( this, wxT( "Unable to save PCB file" ) );
  773. else
  774. Affiche_Message( wxEmptyString );
  775. return rc;
  776. }
  777. #endif