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.

1217 lines
36 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
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 "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. /* Variables locales, utilisees pour la lecture des fichiers PCB */
  61. int NbDraw, NbTrack, NbZone, NbMod, NbNets;
  62. /**********************************************************************/
  63. int WinEDA_BasePcbFrame::ReadListeSegmentDescr( wxDC* DC, FILE* File,
  64. TRACK* PtSegm, int StructType, int* LineNum, int NumSegm )
  65. /**********************************************************************/
  66. /* Lecture de la description d'une liste de segments (Tracks, zones)
  67. * Retourne:
  68. * si ok nombre d'items lus.
  69. * si pas de fin de block ($..) - nombre.
  70. */
  71. {
  72. int shape, width, layer, type, flags, net_code;
  73. int ii = 0, PerCent, Pas;
  74. char line1[256];
  75. char line2[256];
  76. TRACK* NewTrack;
  77. PerCent = 0;
  78. Pas = NumSegm / 99;
  79. #ifdef PCBNEW
  80. switch( StructType )
  81. {
  82. case TYPETRACK:
  83. case TYPEVIA:
  84. DisplayActivity( PerCent, wxT( "Tracks:" ) );
  85. break;
  86. case TYPEZONE:
  87. DisplayActivity( PerCent, wxT( "Zones:" ) );
  88. break;
  89. }
  90. #endif
  91. while( GetLine( File, line1, LineNum ) )
  92. {
  93. int makeType;
  94. unsigned long timeStamp;
  95. if( line1[0] == '$' )
  96. {
  97. return ii; /* fin de liste OK */
  98. }
  99. // Read the 2nd line to determine the exact type, one of:
  100. // TYPETRACK, TYPEVIA, or TYPEZONE. The type field in 2nd line
  101. // differentiates between TYPETRACK and TYPEVIA. With virtual
  102. // functions in use, it is critical to instantiate the TYPEVIA exactly.
  103. if( GetLine( File, line2, LineNum ) == NULL )
  104. break;
  105. if( line2[0] == '$' )
  106. break;
  107. // parse the 2nd line first to determine the type of object
  108. sscanf( line2 + 2, " %d %d %d %lX %X", &layer, &type, &net_code,
  109. &timeStamp, &flags );
  110. if( StructType==TYPETRACK && type==1 )
  111. makeType = TYPEVIA;
  112. else
  113. makeType = StructType;
  114. switch( makeType )
  115. {
  116. default:
  117. case TYPETRACK:
  118. NewTrack = new TRACK( m_Pcb );
  119. break;
  120. case TYPEVIA:
  121. NewTrack = new SEGVIA( m_Pcb );
  122. break;
  123. case TYPEZONE:
  124. NewTrack = new SEGZONE( m_Pcb );
  125. break;
  126. }
  127. NewTrack->Insert( m_Pcb, PtSegm );
  128. PtSegm = NewTrack;
  129. PtSegm->m_TimeStamp = timeStamp;
  130. int arg_count = sscanf( line1 + 2, " %d %d %d %d %d %d %d", &shape,
  131. &PtSegm->m_Start.x, &PtSegm->m_Start.y,
  132. &PtSegm->m_End.x, &PtSegm->m_End.y, &width,
  133. &PtSegm->m_Drill );
  134. PtSegm->m_Width = width;
  135. PtSegm->m_Shape = shape;
  136. if( arg_count < 7 )
  137. PtSegm->m_Drill = -1;
  138. PtSegm->SetLayer( layer );
  139. PtSegm->SetNet( net_code );
  140. PtSegm->SetState( flags, ON );
  141. #ifdef PCBNEW
  142. PtSegm->Draw( DrawPanel, DC, GR_OR );
  143. #endif
  144. ii++;
  145. if( ( Pas && (ii % Pas ) == 0) )
  146. {
  147. PerCent++;
  148. #ifdef PCBNEW
  149. switch( makeType )
  150. {
  151. case TYPETRACK:
  152. case TYPEVIA:
  153. DisplayActivity( PerCent, _( "Tracks:" ) );
  154. break;
  155. case TYPEZONE:
  156. DisplayActivity( PerCent, _( "Zones:" ) );
  157. break;
  158. }
  159. #endif
  160. }
  161. }
  162. DisplayError( this, _( "Error: Unexpected end of file !" ) );
  163. return -ii;
  164. }
  165. /**********************************************************************************/
  166. int WinEDA_BasePcbFrame::ReadGeneralDescrPcb( wxDC* DC, FILE* File, int* LineNum )
  167. /**********************************************************************************/
  168. {
  169. char Line[1024], * data;
  170. BASE_SCREEN* screen = m_CurrentScreen;
  171. while( GetLine( File, Line, LineNum ) != NULL )
  172. {
  173. data = strtok( Line, " =\n\r" );
  174. if( strnicmp( data, "$EndGENERAL", 10 ) == 0 )
  175. break;
  176. if( strncmp( data, "Ly", 2 ) == 0 ) // Old format for Layer count
  177. {
  178. int Masque_Layer = 1, ii;
  179. data = strtok( NULL, " =\n\r" );
  180. sscanf( data, "%X", &Masque_Layer );
  181. // Setup layer count
  182. m_Pcb->m_BoardSettings->m_CopperLayerCount = 0;
  183. for( ii = 0; ii < NB_COPPER_LAYERS; ii++ )
  184. {
  185. if( Masque_Layer & 1 )
  186. m_Pcb->m_BoardSettings->m_CopperLayerCount++;
  187. Masque_Layer >>= 1;
  188. }
  189. continue;
  190. }
  191. if( strnicmp( data, "Links", 5 ) == 0 )
  192. {
  193. data = strtok( NULL, " =\n\r" );
  194. m_Pcb->m_NbLinks = atoi( data );
  195. continue;
  196. }
  197. if( strnicmp( data, "NoConn", 6 ) == 0 )
  198. {
  199. data = strtok( NULL, " =\n\r" );
  200. m_Pcb->m_NbNoconnect = atoi( data );
  201. continue;
  202. }
  203. if( strnicmp( data, "Di", 2 ) == 0 )
  204. {
  205. int ii, jj, bestzoom;
  206. wxSize pcbsize, screensize;
  207. data = strtok( NULL, " =\n\r" );
  208. m_Pcb->m_BoundaryBox.SetX( atoi( data ) );
  209. data = strtok( NULL, " =\n\r" );
  210. m_Pcb->m_BoundaryBox.SetY( atoi( data ) );
  211. data = strtok( NULL, " =\n\r" );
  212. m_Pcb->m_BoundaryBox.SetWidth( atoi( data ) - m_Pcb->m_BoundaryBox.GetX() );
  213. data = strtok( NULL, " =\n\r" );
  214. m_Pcb->m_BoundaryBox.SetHeight( atoi( data ) - m_Pcb->m_BoundaryBox.GetY() );
  215. /* calcul du zoom optimal */
  216. pcbsize = m_Pcb->m_BoundaryBox.GetSize();
  217. screensize = DrawPanel->GetClientSize();
  218. ii = pcbsize.x / screensize.x;
  219. jj = pcbsize.y / screensize.y;
  220. bestzoom = MAX( ii, jj );
  221. screen->m_Curseur = m_Pcb->m_BoundaryBox.Centre();
  222. screen->SetZoom( bestzoom );
  223. // la position des trac� a chang� mise a jour dans le DC courant
  224. wxPoint org;
  225. DrawPanel->GetViewStart( &org.x, &org.y );
  226. DrawPanel->GetScrollPixelsPerUnit( &ii, &jj );
  227. org.x *= ii; org.y *= jj;
  228. #ifdef WX_ZOOM
  229. DC->SetUserScale( 1.0 / (double) screen->GetZoom(), 1.0 / screen->GetZoom() );
  230. org.x *= screen->GetZoom(); org.y *= screen->GetZoom();
  231. DC->SetDeviceOrigin( -org.x, -org.y );
  232. #endif
  233. DrawPanel->SetBoundaryBox();
  234. Recadre_Trace( TRUE );
  235. continue;
  236. }
  237. /* Lecture du nombre de segments type DRAW , TRACT, ZONE */
  238. if( stricmp( data, "Ndraw" ) == 0 )
  239. {
  240. data = strtok( NULL, " =\n\r" );
  241. NbDraw = atoi( data );;
  242. continue;
  243. }
  244. if( stricmp( data, "Ntrack" ) == 0 )
  245. {
  246. data = strtok( NULL, " =\n\r" );
  247. NbTrack = atoi( data );
  248. continue;
  249. }
  250. if( stricmp( data, "Nzone" ) == 0 )
  251. {
  252. data = strtok( NULL, " =\n\r" );
  253. NbZone = atoi( data );
  254. continue;
  255. }
  256. if( stricmp( data, "Nmodule" ) == 0 )
  257. {
  258. data = strtok( NULL, " =\n\r" );
  259. NbMod = atoi( data );
  260. continue;
  261. }
  262. if( stricmp( data, "Nnets" ) == 0 )
  263. {
  264. data = strtok( NULL, " =\n\r" );
  265. NbNets = atoi( data );
  266. continue;
  267. }
  268. }
  269. return 1;
  270. }
  271. /*************************************************************/
  272. int WinEDA_BasePcbFrame::ReadSetup( FILE* File, int* LineNum )
  273. /*************************************************************/
  274. {
  275. char Line[1024], * data;
  276. while( GetLine( File, Line, LineNum ) != NULL )
  277. {
  278. strtok( Line, " =\n\r" );
  279. data = strtok( NULL, " =\n\r" );
  280. if( stricmp( Line, "$EndSETUP" ) == 0 )
  281. {
  282. return 0;
  283. }
  284. if( stricmp( Line, "AuxiliaryAxisOrg" ) == 0 )
  285. {
  286. int gx = 0, gy = 0;
  287. gx = atoi( data );
  288. data = strtok( NULL, " =\n\r" );
  289. if( data )
  290. gy = atoi( data );
  291. m_Auxiliary_Axis_Position.x = gx;
  292. m_Auxiliary_Axis_Position.y = gy;
  293. continue;
  294. }
  295. #ifdef PCBNEW
  296. if( stricmp( Line, "Layers" ) == 0 )
  297. {
  298. int tmp;
  299. sscanf( data, "%d", &tmp );
  300. m_Pcb->m_BoardSettings->m_CopperLayerCount = tmp;
  301. continue;
  302. }
  303. if( stricmp( Line, "TrackWidth" ) == 0 )
  304. {
  305. g_DesignSettings.m_CurrentTrackWidth = atoi( data );
  306. AddHistory( g_DesignSettings.m_CurrentTrackWidth, TYPETRACK );
  307. continue;
  308. }
  309. if( stricmp( Line, "TrackWidthHistory" ) == 0 )
  310. {
  311. int tmp = atoi( data );
  312. AddHistory( tmp, TYPETRACK );
  313. continue;
  314. }
  315. if( stricmp( Line, "TrackClearence" ) == 0 )
  316. {
  317. g_DesignSettings.m_TrackClearence = atoi( data );
  318. continue;
  319. }
  320. if( stricmp( Line, "ZoneClearence" ) == 0 )
  321. {
  322. g_DesignSettings.m_ZoneClearence = atoi( data );
  323. continue;
  324. }
  325. if( stricmp( Line, "GridSize" ) == 0 )
  326. {
  327. wxSize Grid;
  328. Grid.x = atoi( data );
  329. data = strtok( NULL, " =\n\r" );
  330. if( data )
  331. Grid.y = atoi( data );
  332. else
  333. Grid.y = Grid.x;
  334. GetScreen()->SetGrid( Grid );
  335. continue;
  336. }
  337. if( stricmp( Line, "ZoneGridSize" ) == 0 )
  338. {
  339. g_GridRoutingSize = atoi( data );
  340. continue;
  341. }
  342. if( stricmp( Line, "UserGridSize" ) == 0 )
  343. {
  344. wxString msg;
  345. if( data )
  346. {
  347. msg = CONV_FROM_UTF8( data );
  348. msg.ToDouble( &g_UserGrid.x );
  349. }
  350. else
  351. continue;
  352. data = strtok( NULL, " =\n\r" );
  353. if( data )
  354. {
  355. msg = CONV_FROM_UTF8( data );
  356. msg.ToDouble( &g_UserGrid.y );
  357. }
  358. else
  359. g_UserGrid.y = g_UserGrid.x;
  360. GetScreen()->m_UserGrid = g_UserGrid;
  361. data = strtok( NULL, " =\n\r" );
  362. if( data )
  363. {
  364. if( stricmp( data, "mm" ) == 0 )
  365. g_UserGrid_Unit = MILLIMETRE;
  366. else
  367. g_UserGrid_Unit = INCHES;
  368. GetScreen()->m_UserGridUnit = g_UserGrid_Unit;
  369. }
  370. continue;
  371. }
  372. if( stricmp( Line, "DrawSegmWidth" ) == 0 )
  373. {
  374. g_DesignSettings.m_DrawSegmentWidth = atoi( data );
  375. continue;
  376. }
  377. if( stricmp( Line, "EdgeSegmWidth" ) == 0 )
  378. {
  379. g_DesignSettings.m_EdgeSegmentWidth = atoi( data );
  380. continue;
  381. }
  382. if( stricmp( Line, "ViaSize" ) == 0 )
  383. {
  384. g_DesignSettings.m_CurrentViaSize = atoi( data );
  385. AddHistory( g_DesignSettings.m_CurrentViaSize, TYPEVIA );
  386. continue;
  387. }
  388. if( stricmp( Line, "ViaSizeHistory" ) == 0 )
  389. {
  390. int tmp = atoi( data );
  391. AddHistory( tmp, TYPEVIA );
  392. continue;
  393. }
  394. if( stricmp( Line, "ViaDrill" ) == 0 )
  395. {
  396. g_DesignSettings.m_ViaDrill = atoi( data );
  397. continue;
  398. }
  399. if( stricmp( Line, "TextPcbWidth" ) == 0 )
  400. {
  401. g_DesignSettings.m_PcbTextWidth = atoi( data );
  402. continue;
  403. }
  404. if( stricmp( Line, "TextPcbSize" ) == 0 )
  405. {
  406. g_DesignSettings.m_PcbTextSize.x = atoi( data );
  407. data = strtok( NULL, " =\n\r" );
  408. g_DesignSettings.m_PcbTextSize.y = atoi( data );
  409. continue;
  410. }
  411. if( stricmp( Line, "EdgeModWidth" ) == 0 )
  412. {
  413. ModuleSegmentWidth = atoi( data );
  414. continue;
  415. }
  416. if( stricmp( Line, "TextModWidth" ) == 0 )
  417. {
  418. ModuleTextWidth = atoi( data );
  419. continue;
  420. }
  421. if( stricmp( Line, "TextModSize" ) == 0 )
  422. {
  423. ModuleTextSize.x = atoi( data );
  424. data = strtok( NULL, " =\n\r" );
  425. ModuleTextSize.y = atoi( data );
  426. continue;
  427. }
  428. if( stricmp( Line, "PadSize" ) == 0 )
  429. {
  430. g_Pad_Master.m_Size.x = atoi( data );
  431. data = strtok( NULL, " =\n\r" );
  432. g_Pad_Master.m_Size.y = atoi( data );
  433. continue;
  434. }
  435. if( stricmp( Line, "PadDrill" ) == 0 )
  436. {
  437. g_Pad_Master.m_Drill.x = atoi( data );
  438. g_Pad_Master.m_Drill.y = g_Pad_Master.m_Drill.x;
  439. continue;
  440. }
  441. if( stricmp( Line, "PadDeltaSize" ) == 0 )
  442. {
  443. g_Pad_Master.m_DeltaSize.x = atoi( data );
  444. data = strtok( NULL, " =\n\r" );
  445. g_Pad_Master.m_DeltaSize.y = atoi( data );
  446. continue;
  447. }
  448. if( stricmp( Line, "PadShapeOffset" ) == 0 )
  449. {
  450. g_Pad_Master.m_Offset.x = atoi( data );
  451. data = strtok( NULL, " =\n\r" );
  452. g_Pad_Master.m_Offset.y = atoi( data );
  453. continue;
  454. }
  455. #endif
  456. }
  457. return 1;
  458. }
  459. #ifdef PCBNEW
  460. /***************************************************************/
  461. static int WriteSetup( FILE* File, WinEDA_BasePcbFrame* frame )
  462. /***************************************************************/
  463. {
  464. char text[1024];
  465. int ii, jj;
  466. fprintf( File, "$SETUP\n" );
  467. sprintf( text, "InternalUnit %f INCH\n", 1.0 / PCB_INTERNAL_UNIT );
  468. fprintf( File, text );
  469. if( frame->GetScreen()->m_UserGridIsON )
  470. ii = jj = -1;
  471. else
  472. {
  473. ii = frame->GetScreen()->GetGrid().x;
  474. jj = frame->GetScreen()->GetGrid().y;
  475. }
  476. sprintf( text, "GridSize %d %d\n", ii, jj );
  477. fprintf( File, text );
  478. sprintf( text, "UserGridSize %lf %lf %s\n",
  479. frame->GetScreen()->m_UserGrid.x, frame->GetScreen()->m_UserGrid.y,
  480. ( g_UserGrid_Unit == 0 ) ? "INCH" : "mm" );
  481. fprintf( File, text );
  482. fprintf( File, "ZoneGridSize %d\n", g_GridRoutingSize );
  483. fprintf( File, "Layers %d\n", g_DesignSettings.m_CopperLayerCount );
  484. fprintf( File, "TrackWidth %d\n", g_DesignSettings.m_CurrentTrackWidth );
  485. for( ii = 0; ii < HIST0RY_NUMBER; ii++ )
  486. {
  487. if( g_DesignSettings.m_TrackWidhtHistory[ii] == 0 )
  488. break;
  489. fprintf( File, "TrackWidthHistory %d\n",
  490. g_DesignSettings.m_TrackWidhtHistory[ii] );
  491. }
  492. fprintf( File, "TrackClearence %d\n", g_DesignSettings.m_TrackClearence );
  493. fprintf( File, "ZoneClearence %d\n", g_DesignSettings.m_ZoneClearence );
  494. fprintf( File, "DrawSegmWidth %d\n", g_DesignSettings.m_DrawSegmentWidth );
  495. fprintf( File, "EdgeSegmWidth %d\n", g_DesignSettings.m_EdgeSegmentWidth );
  496. fprintf( File, "ViaSize %d\n", g_DesignSettings.m_CurrentViaSize );
  497. fprintf( File, "ViaDrill %d\n", g_DesignSettings.m_ViaDrill );
  498. for( ii = 0; ii < HIST0RY_NUMBER; ii++ )
  499. {
  500. if( g_DesignSettings.m_ViaSizeHistory[ii] == 0 )
  501. break;
  502. fprintf( File, "ViaSizeHistory %d\n", g_DesignSettings.m_ViaSizeHistory[ii] );
  503. }
  504. fprintf( File, "TextPcbWidth %d\n", g_DesignSettings.m_PcbTextWidth );
  505. fprintf( File, "TextPcbSize %d %d\n",
  506. g_DesignSettings.m_PcbTextSize.x, g_DesignSettings.m_PcbTextSize.y );
  507. fprintf( File, "EdgeModWidth %d\n", ModuleSegmentWidth );
  508. fprintf( File, "TextModSize %d %d\n", ModuleTextSize.x, ModuleTextSize.y );
  509. fprintf( File, "TextModWidth %d\n", ModuleTextWidth );
  510. fprintf( File, "PadSize %d %d\n", g_Pad_Master.m_Size.x, g_Pad_Master.m_Size.y );
  511. fprintf( File, "PadDrill %d\n", g_Pad_Master.m_Drill.x );
  512. // fprintf(File, "PadDeltaSize %d %d\n", Pad_DeltaSize.x, Pad_DeltaSize.y);
  513. // fprintf(File, "PadDrillOffset %d %d\n", Pad_OffsetSize.x, Pad_OffsetSize.y);
  514. fprintf( File, "AuxiliaryAxisOrg %d %d\n",
  515. frame->m_Auxiliary_Axis_Position.x, frame->m_Auxiliary_Axis_Position.y );
  516. fprintf( File, "$EndSETUP\n\n" );
  517. return 1;
  518. }
  519. #endif
  520. /******************************************************/
  521. bool WinEDA_PcbFrame::WriteGeneralDescrPcb( FILE* File )
  522. /******************************************************/
  523. {
  524. EDA_BaseStruct* PtStruct = m_Pcb->m_Modules;
  525. int NbModules, NbDrawItem, NbLayers;
  526. /* Calcul du nombre des modules */
  527. for( NbModules = 0; PtStruct != NULL; PtStruct = PtStruct->Pnext )
  528. NbModules++;
  529. /* generation du masque des couches autorisees */
  530. NbLayers = m_Pcb->m_BoardSettings->m_CopperLayerCount;
  531. fprintf( File, "$GENERAL\n" );
  532. fprintf( File, "LayerCount %d\n", NbLayers );
  533. // Write old format for Layer count (for compatibility with old versions of pcbnew
  534. fprintf( File, "Ly %8X\n", g_TabAllCopperLayerMask[NbLayers - 1] | ALL_NO_CU_LAYERS ); // For compatibility with old version of pcbnew
  535. fprintf( File, "Links %d\n", m_Pcb->m_NbLinks );
  536. fprintf( File, "NoConn %d\n", m_Pcb->m_NbNoconnect );
  537. /* Generation des coord du rectangle d'encadrement */
  538. m_Pcb->ComputeBoundaryBox();
  539. fprintf( File, "Di %d %d %d %d\n",
  540. m_Pcb->m_BoundaryBox.GetX(), m_Pcb->m_BoundaryBox.GetY(),
  541. m_Pcb->m_BoundaryBox.GetRight(),
  542. m_Pcb->m_BoundaryBox.GetBottom() );
  543. /* Generation du nombre de segments type DRAW , TRACT ZONE */
  544. PtStruct = m_Pcb->m_Drawings; NbDrawItem = 0;
  545. for( ; PtStruct != NULL; PtStruct = PtStruct->Pnext )
  546. NbDrawItem++;
  547. fprintf( File, "Ndraw %d\n", NbDrawItem );
  548. fprintf( File, "Ntrack %d\n", m_Pcb->GetNumSegmTrack() );
  549. fprintf( File, "Nzone %d\n", m_Pcb->GetNumSegmZone() );
  550. fprintf( File, "Nmodule %d\n", NbModules );
  551. fprintf( File, "Nnets %d\n", m_Pcb->m_NbNets );
  552. fprintf( File, "$EndGENERAL\n\n" );
  553. return TRUE;
  554. }
  555. /******************************************************/
  556. bool WriteSheetDescr( BASE_SCREEN* screen, FILE* File )
  557. /******************************************************/
  558. {
  559. /* Sauvegarde des dimensions de la feuille de dessin, des textes du cartouche.. */
  560. Ki_PageDescr* sheet = screen->m_CurrentSheet;
  561. fprintf( File, "$SHEETDESCR\n" );
  562. fprintf( File, "Sheet %s %d %d\n",
  563. CONV_TO_UTF8( sheet->m_Name ), sheet->m_Size.x, sheet->m_Size.y );
  564. fprintf( File, "Title \"%s\"\n", CONV_TO_UTF8( screen->m_Title ) );
  565. fprintf( File, "Date \"%s\"\n", CONV_TO_UTF8( screen->m_Date ) );
  566. fprintf( File, "Rev \"%s\"\n", CONV_TO_UTF8( screen->m_Revision ) );
  567. fprintf( File, "Comp \"%s\"\n", CONV_TO_UTF8( screen->m_Company ) );
  568. fprintf( File, "Comment1 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire1 ) );
  569. fprintf( File, "Comment2 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire2 ) );
  570. fprintf( File, "Comment3 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire3 ) );
  571. fprintf( File, "Comment4 \"%s\"\n", CONV_TO_UTF8( screen->m_Commentaire4 ) );
  572. fprintf( File, "$EndSHEETDESCR\n\n" );
  573. return TRUE;
  574. }
  575. /***************************************************************************/
  576. static bool ReadSheetDescr( BASE_SCREEN* screen, FILE* File, int* LineNum )
  577. /***************************************************************************/
  578. {
  579. char Line[1024], buf[1024], * text;
  580. /* Recheche suite et fin de descr */
  581. while( GetLine( File, Line, LineNum ) != NULL )
  582. {
  583. if( strnicmp( Line, "$End", 4 ) == 0 )
  584. return TRUE;
  585. if( strnicmp( Line, "Sheet", 4 ) == 0 )
  586. {
  587. text = strtok( Line, " \t\n\r" );
  588. text = strtok( NULL, " \t\n\r" );
  589. Ki_PageDescr* sheet = SheetList[0];
  590. int ii;
  591. for( ii = 0; sheet != NULL; ii++, sheet = SheetList[ii] )
  592. {
  593. if( stricmp( CONV_TO_UTF8( sheet->m_Name ), text ) == 0 )
  594. {
  595. screen->m_CurrentSheet = sheet;
  596. if( sheet == &g_Sheet_user )
  597. {
  598. text = strtok( NULL, " \t\n\r" );
  599. if( text )
  600. sheet->m_Size.x = atoi( text );
  601. text = strtok( NULL, " \t\n\r" );
  602. if( text )
  603. sheet->m_Size.y = atoi( text );
  604. }
  605. break;
  606. }
  607. }
  608. continue;
  609. }
  610. if( strnicmp( Line, "Title", 2 ) == 0 )
  611. {
  612. ReadDelimitedText( buf, Line, 256 );
  613. screen->m_Title = CONV_FROM_UTF8( buf );
  614. continue;
  615. }
  616. if( strnicmp( Line, "Date", 2 ) == 0 )
  617. {
  618. ReadDelimitedText( buf, Line, 256 );
  619. screen->m_Date = CONV_FROM_UTF8( buf );
  620. continue;
  621. }
  622. if( strnicmp( Line, "Rev", 2 ) == 0 )
  623. {
  624. ReadDelimitedText( buf, Line, 256 );
  625. screen->m_Revision = CONV_FROM_UTF8( buf );
  626. continue;
  627. }
  628. if( strnicmp( Line, "Comp", 4 ) == 0 )
  629. {
  630. ReadDelimitedText( buf, Line, 256 );
  631. screen->m_Company = CONV_FROM_UTF8( buf );
  632. continue;
  633. }
  634. if( strnicmp( Line, "Comment1", 8 ) == 0 )
  635. {
  636. ReadDelimitedText( buf, Line, 256 );
  637. screen->m_Commentaire1 = CONV_FROM_UTF8( buf );
  638. continue;
  639. }
  640. if( strnicmp( Line, "Comment2", 8 ) == 0 )
  641. {
  642. ReadDelimitedText( buf, Line, 256 );
  643. screen->m_Commentaire2 = CONV_FROM_UTF8( buf );
  644. continue;
  645. }
  646. if( strnicmp( Line, "Comment3", 8 ) == 0 )
  647. {
  648. ReadDelimitedText( buf, Line, 256 );
  649. screen->m_Commentaire3 = CONV_FROM_UTF8( buf );
  650. continue;
  651. }
  652. if( strnicmp( Line, "Comment4", 8 ) == 0 )
  653. {
  654. ReadDelimitedText( buf, Line, 256 );
  655. screen->m_Commentaire4 = CONV_FROM_UTF8( buf );
  656. continue;
  657. }
  658. }
  659. return FALSE;
  660. }
  661. /********************************************************************/
  662. int WinEDA_PcbFrame::ReadPcbFile( wxDC* DC, FILE* File, bool Append )
  663. /********************************************************************/
  664. /* Lit un fichier PCB .brd
  665. * Si Append == 0: l'ancien pcb en memoire est supprime
  666. * Sinon il y a ajout des elements
  667. */
  668. {
  669. char Line[1024];
  670. int LineNum = 0;
  671. int nbsegm, nbmod;
  672. BOARD_ITEM* LastStructPcb = NULL, * StructPcb;
  673. MODULE* LastModule = NULL, * Module;
  674. EQUIPOT* LastEquipot = NULL, * Equipot;
  675. wxBusyCursor dummy;
  676. // Switch the locale to standard C (needed to print floating point numbers like 1.3)
  677. setlocale( LC_NUMERIC, "C" );
  678. NbDraw = NbTrack = NbZone = NbMod = NbNets = -1;
  679. m_Pcb->m_NbNets = 0;
  680. m_Pcb->m_Status_Pcb = 0;
  681. nbmod = 0;
  682. if( Append )
  683. {
  684. LastModule = m_Pcb->m_Modules;
  685. for( ; LastModule != NULL; LastModule = (MODULE*) LastModule->Pnext )
  686. {
  687. if( LastModule->Pnext == NULL )
  688. break;
  689. }
  690. LastStructPcb = m_Pcb->m_Drawings;
  691. for( ; LastStructPcb != NULL; LastStructPcb = LastStructPcb->Next() )
  692. {
  693. if( LastStructPcb->Pnext == NULL )
  694. break;
  695. }
  696. LastEquipot = m_Pcb->m_Equipots;
  697. for( ; LastEquipot != NULL; LastEquipot = (EQUIPOT*) LastEquipot->Pnext )
  698. {
  699. if( LastEquipot->Pnext == NULL )
  700. break;
  701. }
  702. }
  703. while( GetLine( File, Line, &LineNum ) != NULL )
  704. {
  705. if( strnicmp( Line, "$EndPCB", 6 ) == 0 )
  706. break;
  707. if( strnicmp( Line, "$GENERAL", 8 ) == 0 )
  708. {
  709. ReadGeneralDescrPcb( DC, File, &LineNum );
  710. continue;
  711. }
  712. if( strnicmp( Line, "$SHEETDESCR", 11 ) == 0 )
  713. {
  714. ReadSheetDescr( m_CurrentScreen, File, &LineNum );
  715. continue;
  716. }
  717. if( strnicmp( Line, "$SETUP", 6 ) == 0 )
  718. {
  719. if( !Append )
  720. {
  721. ReadSetup( File, &LineNum );
  722. }
  723. else
  724. {
  725. while( GetLine( File, Line, &LineNum ) != NULL )
  726. if( strnicmp( Line, "$EndSETUP", 6 ) == 0 )
  727. break;
  728. }
  729. continue;
  730. }
  731. if( strnicmp( Line, "$EQUIPOT", 7 ) == 0 )
  732. {
  733. Equipot = new EQUIPOT( m_Pcb );
  734. Equipot->ReadEquipotDescr( File, &LineNum );
  735. if( LastEquipot == NULL )
  736. {
  737. m_Pcb->m_Equipots = Equipot;
  738. Equipot->Pback = m_Pcb;
  739. }
  740. else
  741. {
  742. Equipot->Pback = LastEquipot;
  743. LastEquipot->Pnext = Equipot;
  744. }
  745. LastEquipot = Equipot;
  746. m_Pcb->m_NbNets++;
  747. continue;
  748. }
  749. if( strnicmp( Line, "$MODULE", 7 ) == 0 )
  750. {
  751. float Pas;
  752. Pas = 100.0; if( NbMod > 1 )
  753. Pas /= NbMod;
  754. Module = new MODULE( m_Pcb );
  755. if( Module == NULL )
  756. continue;
  757. Module->ReadDescr( File, &LineNum );
  758. if( LastModule == NULL )
  759. {
  760. m_Pcb->m_Modules = Module;
  761. Module->Pback = m_Pcb;
  762. }
  763. else
  764. {
  765. Module->Pback = LastModule;
  766. LastModule->Pnext = Module;
  767. }
  768. LastModule = Module;
  769. nbmod++;
  770. #ifdef PCBNEW
  771. DisplayActivity( (int) ( Pas * nbmod), wxT( "Modules:" ) );
  772. #endif
  773. Module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
  774. continue;
  775. }
  776. if( strnicmp( Line, "$TEXTPCB", 8 ) == 0 )
  777. {
  778. TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_Pcb );
  779. StructPcb = pcbtxt;
  780. pcbtxt->ReadTextePcbDescr( File, &LineNum );
  781. if( LastStructPcb == NULL )
  782. {
  783. m_Pcb->m_Drawings = StructPcb;
  784. StructPcb->Pback = m_Pcb;
  785. }
  786. else
  787. {
  788. StructPcb->Pback = LastStructPcb;
  789. LastStructPcb->Pnext = StructPcb;
  790. }
  791. LastStructPcb = StructPcb;
  792. #ifdef PCBNEW
  793. ( (TEXTE_PCB*) StructPcb )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
  794. #endif
  795. continue;
  796. }
  797. if( strnicmp( Line, "$DRAWSEGMENT", 10 ) == 0 )
  798. {
  799. DRAWSEGMENT* DrawSegm = new DRAWSEGMENT( m_Pcb );
  800. DrawSegm->ReadDrawSegmentDescr( File, &LineNum );
  801. if( LastStructPcb == NULL )
  802. {
  803. m_Pcb->m_Drawings = DrawSegm;
  804. DrawSegm->Pback = m_Pcb;
  805. }
  806. else
  807. {
  808. DrawSegm->Pback = LastStructPcb;
  809. LastStructPcb->Pnext = DrawSegm;
  810. }
  811. LastStructPcb = DrawSegm;
  812. #ifdef PCBNEW
  813. Trace_DrawSegmentPcb( DrawPanel, DC, DrawSegm, GR_OR );
  814. #endif
  815. continue;
  816. }
  817. if( strnicmp( Line, "$COTATION", 9 ) == 0 )
  818. {
  819. COTATION* Cotation = new COTATION( m_Pcb );
  820. Cotation->ReadCotationDescr( File, &LineNum );
  821. if( LastStructPcb == NULL )
  822. {
  823. m_Pcb->m_Drawings = Cotation;
  824. Cotation->Pback = m_Pcb;
  825. }
  826. else
  827. {
  828. Cotation->Pback = LastStructPcb;
  829. LastStructPcb->Pnext = Cotation;
  830. }
  831. LastStructPcb = Cotation;
  832. #ifdef PCBNEW
  833. Cotation->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
  834. #endif
  835. continue;
  836. }
  837. if( strnicmp( Line, "$MIREPCB", 8 ) == 0 )
  838. {
  839. MIREPCB* Mire = new MIREPCB( m_Pcb );
  840. Mire->ReadMirePcbDescr( File, &LineNum );
  841. if( LastStructPcb == NULL )
  842. {
  843. m_Pcb->m_Drawings = Mire;
  844. Mire->Pback = m_Pcb;
  845. }
  846. else
  847. {
  848. Mire->Pback = LastStructPcb;
  849. LastStructPcb->Pnext = Mire;
  850. }
  851. LastStructPcb = Mire;
  852. #ifdef PCBNEW
  853. Mire->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
  854. #endif
  855. continue;
  856. }
  857. if( strnicmp( Line, "$TRACK", 6 ) == 0 )
  858. {
  859. TRACK* StartTrack = m_Pcb->m_Track;
  860. nbsegm = 0;
  861. if( Append )
  862. {
  863. for( ; StartTrack != NULL; StartTrack = (TRACK*) StartTrack->Pnext )
  864. {
  865. if( StartTrack->Pnext == NULL )
  866. break;
  867. }
  868. }
  869. #ifdef PCBNEW
  870. int ii = ReadListeSegmentDescr( DC, File, StartTrack, TYPETRACK,
  871. &LineNum, NbTrack );
  872. m_Pcb->m_NbSegmTrack += ii;
  873. #endif
  874. continue;
  875. }
  876. if( strnicmp( Line, "$ZONE", 5 ) == 0 )
  877. {
  878. TRACK* StartZone = m_Pcb->m_Zone;
  879. if( Append )
  880. {
  881. for( ; StartZone != NULL; StartZone = (TRACK*) StartZone->Pnext )
  882. {
  883. if( StartZone->Pnext == NULL )
  884. break;
  885. }
  886. }
  887. #ifdef PCBNEW
  888. int ii = ReadListeSegmentDescr( DC, File, StartZone, TYPEZONE,
  889. &LineNum, NbZone );
  890. m_Pcb->m_NbSegmZone += ii;
  891. #endif
  892. continue;
  893. }
  894. }
  895. setlocale( LC_NUMERIC, "" ); // revert to the current locale
  896. Affiche_Message( wxEmptyString );
  897. #ifdef PCBNEW
  898. Compile_Ratsnest( DC, TRUE );
  899. #endif
  900. return 1;
  901. }
  902. #ifdef PCBNEW
  903. /***************************************************/
  904. int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* File )
  905. /****************************************************/
  906. /* Routine de sauvegarde du PCB courant sous format ASCII
  907. * retourne
  908. * 1 si OK
  909. * 0 si sauvegarde non faite
  910. */
  911. {
  912. int ii, NbModules, nseg;
  913. float Pas;
  914. char Line[256];
  915. EQUIPOT* Equipot;
  916. TRACK* PtSegm;
  917. EDA_BaseStruct* PtStruct;
  918. MODULE* Module;
  919. wxBeginBusyCursor();
  920. m_Pcb->m_Status_Pcb &= ~CONNEXION_OK;
  921. /* Calcul du nombre des modules */
  922. PtStruct = (EDA_BaseStruct*) m_Pcb->m_Modules;
  923. NbModules = 0;
  924. for( ; PtStruct != NULL; PtStruct = PtStruct->Pnext )
  925. NbModules++;
  926. // Switch the locale to standard C (needed to print floating point numbers like 1.3)
  927. setlocale( LC_NUMERIC, "C" );
  928. /* Ecriture de l'entete PCB : */
  929. fprintf( File, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB,
  930. DateAndTime( Line ) );
  931. WriteGeneralDescrPcb( File );
  932. WriteSheetDescr( m_CurrentScreen, File );
  933. WriteSetup( File, this );
  934. /* Ecriture des donnes utiles du pcb */
  935. Equipot = m_Pcb->m_Equipots;
  936. Pas = 100.0;
  937. if( m_Pcb->m_NbNets )
  938. Pas /= m_Pcb->m_NbNets;
  939. for( ii = 0; Equipot != NULL; ii++, Equipot = (EQUIPOT*) Equipot->Pnext )
  940. {
  941. Equipot->WriteEquipotDescr( File );
  942. DisplayActivity( (int) ( Pas * ii ), wxT( "Equipot:" ) );
  943. }
  944. Pas = 100.0;
  945. if( NbModules )
  946. Pas /= NbModules;
  947. Module = m_Pcb->m_Modules;
  948. for( ii = 1; Module != NULL; Module = Module->Next(), ii++ )
  949. {
  950. Module->WriteDescr( File );
  951. DisplayActivity( (int) (ii * Pas), wxT( "Modules:" ) );
  952. }
  953. /* sortie des inscriptions du PCB: */
  954. PtStruct = m_Pcb->m_Drawings;
  955. for( ; PtStruct != NULL; PtStruct = PtStruct->Pnext )
  956. {
  957. switch( PtStruct->Type() )
  958. {
  959. case TYPETEXTE:
  960. ( (TEXTE_PCB*) PtStruct )->WriteTextePcbDescr( File );
  961. break;
  962. case TYPEDRAWSEGMENT:
  963. ( (DRAWSEGMENT*) PtStruct )->WriteDrawSegmentDescr( File );
  964. break;
  965. case TYPEMIRE:
  966. ( (MIREPCB*) PtStruct )->WriteMirePcbDescr( File );
  967. break;
  968. case TYPECOTATION:
  969. ( (COTATION*) PtStruct )->WriteCotationDescr( File );
  970. break;
  971. case TYPEMARQUEUR: /* sauvegarde inutile */
  972. break;
  973. default:
  974. DisplayError( this, wxT( "Unknown Draw Type" ) );
  975. break;
  976. }
  977. }
  978. Pas = 100.0;
  979. if( m_Pcb->m_NbSegmTrack )
  980. Pas /= (m_Pcb->m_NbSegmTrack);
  981. fprintf( File, "$TRACK\n" );
  982. PtSegm = m_Pcb->m_Track;
  983. DisplayActivity( 0, wxT( "Tracks:" ) );
  984. for( nseg = 0, ii = 0; PtSegm != NULL; ii++, PtSegm = (TRACK*) PtSegm->Pnext )
  985. {
  986. ( (TRACK*) PtSegm )->WriteTrackDescr( File );
  987. if( nseg != (int) ( ii * Pas) )
  988. {
  989. nseg = (int) ( ii * Pas);
  990. DisplayActivity( nseg, wxT( "Tracks:" ) );
  991. }
  992. }
  993. fprintf( File, "$EndTRACK\n" );
  994. fprintf( File, "$ZONE\n" );
  995. PtSegm = (TRACK*) m_Pcb->m_Zone;
  996. ii = m_Pcb->m_NbSegmZone;
  997. Pas = 100.0;
  998. if( ii )
  999. Pas /= ii;
  1000. PtSegm = m_Pcb->m_Zone;
  1001. DisplayActivity( 0, wxT( "Zones:" ) );
  1002. for( nseg = 0, ii = 0; PtSegm != NULL; ii++, PtSegm = (TRACK*) PtSegm->Pnext )
  1003. {
  1004. ( (TRACK*) PtSegm )->WriteTrackDescr( File );
  1005. if( nseg != (int) ( ii * Pas) )
  1006. {
  1007. nseg = (int) ( ii * Pas);
  1008. DisplayActivity( nseg, wxT( "Zones:" ) );
  1009. }
  1010. }
  1011. fprintf( File, "$EndZONE\n" );
  1012. fprintf( File, "$EndBOARD\n" );
  1013. setlocale( LC_NUMERIC, "" ); // revert to the current locale
  1014. wxEndBusyCursor();
  1015. Affiche_Message( wxEmptyString );
  1016. return 1;
  1017. }
  1018. #endif