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.

3768 lines
93 KiB

18 years ago
15 years ago
18 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007-2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /* This source file implements export and import capabilities to the
  25. specctra dsn file format. The grammar for that file format is documented
  26. fairly well. There are classes for each major type of descriptor in the
  27. spec.
  28. Since there are so many classes in here, it may be helpful to generate
  29. the Doxygen directory:
  30. $ cd <kicadSourceRoot>
  31. $ doxygen
  32. Then you can view the html documentation in the <kicadSourceRoot>/doxygen
  33. directory. The main class in this file is SPECCTRA_DB and its main
  34. functions are LoadPCB(), LoadSESSION(), and ExportPCB().
  35. Wide use is made of boost::ptr_vector<> and std::vector<> template classes.
  36. If the contained object is small, then std::vector tends to be used.
  37. If the contained object is large, variable size, or would require writing
  38. an assignment operator() or copy constructor, then boost::ptr_vector
  39. cannot be beat.
  40. */
  41. #include <cstdarg>
  42. #include <cstdio>
  43. #include <build_version.h>
  44. #include <class_board.h>
  45. #include <class_track.h>
  46. #include <specctra.h>
  47. #include <macros.h>
  48. namespace DSN {
  49. #define NESTWIDTH 2 ///< how many spaces per nestLevel
  50. //-----<SPECCTRA_DB>-------------------------------------------------
  51. const char* GetTokenText( T aTok )
  52. {
  53. return SPECCTRA_LEXER::TokenName( aTok );
  54. }
  55. void SPECCTRA_DB::buildLayerMaps( BOARD* aBoard )
  56. {
  57. // specctra wants top physical layer first, then going down to the
  58. // bottom most physical layer in physical sequence.
  59. // @question : why does KiCad not display layers in that order?
  60. int layerCount = aBoard->GetCopperLayerCount();
  61. layerIds.clear();
  62. pcbLayer2kicad.resize( layerCount );
  63. kicadLayer2pcb.resize( LAYER_N_FRONT + 1 );
  64. for( LAYER_NUM kiNdx = layerCount - 1, pcbNdx=FIRST_LAYER;
  65. kiNdx >= 0; --kiNdx, ++pcbNdx )
  66. {
  67. LAYER_NUM kilayer = (kiNdx>0 && kiNdx==layerCount-1) ? LAYER_N_FRONT : kiNdx;
  68. // establish bi-directional mapping between KiCad's BOARD layer and PCB layer
  69. pcbLayer2kicad[pcbNdx] = kilayer;
  70. kicadLayer2pcb[kilayer] = pcbNdx;
  71. // save the specctra layer name in SPECCTRA_DB::layerIds for later.
  72. layerIds.push_back( TO_UTF8( aBoard->GetLayerName( kilayer ) ) );
  73. }
  74. }
  75. int SPECCTRA_DB::findLayerName( const std::string& aLayerName ) const
  76. {
  77. for( int i=0; i < int(layerIds.size()); ++i )
  78. {
  79. if( 0 == aLayerName.compare( layerIds[i] ) )
  80. return i;
  81. }
  82. return -1;
  83. }
  84. void SPECCTRA_DB::ThrowIOError( const wxString& fmt, ... ) throw( IO_ERROR )
  85. {
  86. wxString errText;
  87. va_list args;
  88. va_start( args, fmt );
  89. errText.PrintfV( fmt, args );
  90. va_end( args );
  91. THROW_IO_ERROR( errText );
  92. }
  93. void SPECCTRA_DB::readCOMPnPIN( std::string* component_id, std::string* pin_id ) throw( IO_ERROR )
  94. {
  95. T tok;
  96. static const char pin_def[] = "<pin_reference>::=<component_id>-<pin_id>";
  97. if( !IsSymbol( (T) CurTok() ) )
  98. Expecting( pin_def );
  99. // case for: A12-14, i.e. no wrapping quotes. This should be a single
  100. // token, so split it.
  101. if( CurTok() != T_STRING )
  102. {
  103. const char* toktext = CurText();
  104. const char* dash = strchr( toktext, '-' );
  105. if( !dash )
  106. Expecting( pin_def );
  107. while( toktext != dash )
  108. *component_id += *toktext++;
  109. ++toktext; // skip the dash
  110. while( *toktext )
  111. *pin_id += *toktext++;
  112. }
  113. // quoted string: "U12"-"14" or "U12"-14, 3 tokens in either case
  114. else
  115. {
  116. *component_id = CurText();
  117. tok = NextTok();
  118. if( tok!=T_DASH )
  119. Expecting( pin_def );
  120. NextTok(); // accept anything after the dash.
  121. *pin_id = CurText();
  122. }
  123. }
  124. void SPECCTRA_DB::readTIME( time_t* time_stamp ) throw( IO_ERROR )
  125. {
  126. T tok;
  127. struct tm mytime;
  128. static const char time_toks[] = "<month> <day> <hour> : <minute> : <second> <year>";
  129. static const char* months[] = { // index 0 = Jan
  130. "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  131. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL
  132. };
  133. NeedSYMBOL(); // month
  134. const char* ptok = CurText();
  135. mytime.tm_mon = 0; // remains if we don't find a month match.
  136. for( int m=0; months[m]; ++m )
  137. {
  138. if( !stricmp( months[m], ptok ) )
  139. {
  140. mytime.tm_mon = m;
  141. break;
  142. }
  143. }
  144. tok = NextTok(); // day
  145. if( tok != T_NUMBER )
  146. Expecting( time_toks );
  147. mytime.tm_mday = atoi( CurText() );
  148. tok = NextTok(); // hour
  149. if( tok != T_NUMBER )
  150. Expecting( time_toks );
  151. mytime.tm_hour = atoi( CurText() );
  152. // : colon
  153. NeedSYMBOL();
  154. if( *CurText() != ':' || strlen( CurText() )!=1 )
  155. Expecting( time_toks );
  156. tok = NextTok(); // minute
  157. if( tok != T_NUMBER )
  158. Expecting( time_toks );
  159. mytime.tm_min = atoi( CurText() );
  160. // : colon
  161. NeedSYMBOL();
  162. if( *CurText() != ':' || strlen( CurText() )!=1 )
  163. Expecting( time_toks );
  164. tok = NextTok(); // second
  165. if( tok != T_NUMBER )
  166. Expecting( time_toks );
  167. mytime.tm_sec = atoi( CurText() );
  168. tok = NextTok(); // year
  169. if( tok != T_NUMBER )
  170. Expecting( time_toks );
  171. mytime.tm_year = atoi( CurText() ) - 1900;
  172. *time_stamp = mktime( &mytime );
  173. }
  174. void SPECCTRA_DB::LoadPCB( const wxString& filename ) throw( IO_ERROR )
  175. {
  176. FILE_LINE_READER reader( filename );
  177. PushReader( &reader );
  178. if( NextTok() != T_LEFT )
  179. Expecting( T_LEFT );
  180. if( NextTok() != T_pcb )
  181. Expecting( T_pcb );
  182. SetPCB( new PCB() );
  183. doPCB( pcb );
  184. PopReader();
  185. }
  186. void SPECCTRA_DB::LoadSESSION( const wxString& filename ) throw( IO_ERROR )
  187. {
  188. FILE_LINE_READER reader( filename );
  189. PushReader( &reader );
  190. if( NextTok() != T_LEFT )
  191. Expecting( T_LEFT );
  192. if( NextTok() != T_session )
  193. Expecting( T_session );
  194. SetSESSION( new SESSION() );
  195. doSESSION( session );
  196. PopReader();
  197. }
  198. void SPECCTRA_DB::doPCB( PCB* growth ) throw( IO_ERROR )
  199. {
  200. T tok;
  201. /* <design_descriptor >::=
  202. (pcb <pcb_id >
  203. [<parser_descriptor> ]
  204. [<capacitance_resolution_descriptor> ]
  205. [<conductance_resolution_descriptor> ]
  206. [<current_resolution_descriptor> ]
  207. [<inductance_resolution_descriptor> ]
  208. [<resistance_resolution_descriptor> ]
  209. [<resolution_descriptor> ]
  210. [<time_resolution_descriptor> ]
  211. [<voltage_resolution_descriptor> ]
  212. [<unit_descriptor> ]
  213. [<structure_descriptor> | <file_descriptor> ]
  214. [<placement_descriptor> | <file_descriptor> ]
  215. [<library_descriptor> | <file_descriptor> ]
  216. [<floor_plan_descriptor> | <file_descriptor> ]
  217. [<part_library_descriptor> | <file_descriptor> ]
  218. [<network_descriptor> | <file_descriptor> ]
  219. [<wiring_descriptor> ]
  220. [<color_descriptor> ]
  221. )
  222. */
  223. NeedSYMBOL();
  224. growth->pcbname = CurText();
  225. while( (tok = NextTok()) != T_RIGHT )
  226. {
  227. if( tok != T_LEFT )
  228. Expecting( T_LEFT );
  229. tok = NextTok();
  230. switch( tok )
  231. {
  232. case T_parser:
  233. if( growth->parser )
  234. Unexpected( tok );
  235. growth->parser = new PARSER( growth );
  236. doPARSER( growth->parser );
  237. break;
  238. case T_unit:
  239. if( growth->unit )
  240. Unexpected( tok );
  241. growth->unit = new UNIT_RES( growth, tok );
  242. doUNIT( growth->unit );
  243. break;
  244. case T_resolution:
  245. if( growth->resolution )
  246. Unexpected( tok );
  247. growth->resolution = new UNIT_RES( growth, tok );
  248. doRESOLUTION( growth->resolution );
  249. break;
  250. case T_structure:
  251. if( growth->structure )
  252. Unexpected( tok );
  253. growth->structure = new STRUCTURE( growth );
  254. doSTRUCTURE( growth->structure );
  255. break;
  256. case T_placement:
  257. if( growth->placement )
  258. Unexpected( tok );
  259. growth->placement = new PLACEMENT( growth );
  260. doPLACEMENT( growth->placement );
  261. break;
  262. case T_library:
  263. if( growth->library )
  264. Unexpected( tok );
  265. growth->library = new LIBRARY( growth );
  266. doLIBRARY( growth->library );
  267. break;
  268. case T_network:
  269. if( growth->network )
  270. Unexpected( tok );
  271. growth->network = new NETWORK( growth );
  272. doNETWORK( growth->network );
  273. break;
  274. case T_wiring:
  275. if( growth->wiring )
  276. Unexpected( tok );
  277. growth->wiring = new WIRING( growth );
  278. doWIRING( growth->wiring );
  279. break;
  280. default:
  281. Unexpected( CurText() );
  282. }
  283. }
  284. tok = NextTok();
  285. if( tok != T_EOF )
  286. Expecting( T_EOF );
  287. }
  288. void SPECCTRA_DB::doPARSER( PARSER* growth ) throw( IO_ERROR )
  289. {
  290. T tok;
  291. std::string const1;
  292. std::string const2;
  293. /* <parser_descriptor >::=
  294. (parser
  295. [(string_quote <quote_char >)]
  296. (space_in_quoted_tokens [on | off])
  297. [(host_cad <id >)]
  298. [(host_version <id >)]
  299. [{(constant <id > <id >)}]
  300. [(write_resolution] {<character> <positive_integer >})]
  301. [(routes_include {[testpoint | guides |
  302. image_conductor]})]
  303. [(wires_include testpoint)]
  304. [(case_sensitive [on | off])]
  305. [(via_rotate_first [on | off])]
  306. )
  307. */
  308. while( (tok = NextTok()) != T_RIGHT )
  309. {
  310. if( tok != T_LEFT )
  311. Expecting( T_LEFT );
  312. tok = NextTok();
  313. switch( tok )
  314. {
  315. case T_STRING_QUOTE:
  316. tok = NextTok();
  317. if( tok != T_QUOTE_DEF )
  318. Expecting( T_QUOTE_DEF );
  319. SetStringDelimiter( (unsigned char) *CurText() );
  320. growth->string_quote = *CurText();
  321. quote_char = CurText();
  322. NeedRIGHT();
  323. break;
  324. case T_space_in_quoted_tokens:
  325. tok = NextTok();
  326. if( tok!=T_on && tok!=T_off )
  327. Expecting( "on|off" );
  328. SetSpaceInQuotedTokens( tok==T_on );
  329. growth->space_in_quoted_tokens = (tok==T_on);
  330. NeedRIGHT();
  331. break;
  332. case T_host_cad:
  333. NeedSYMBOL();
  334. growth->host_cad = CurText();
  335. NeedRIGHT();
  336. break;
  337. case T_host_version:
  338. NeedSYMBOLorNUMBER();
  339. growth->host_version = CurText();
  340. NeedRIGHT();
  341. break;
  342. case T_constant:
  343. NeedSYMBOLorNUMBER();
  344. const1 = CurText();
  345. NeedSYMBOLorNUMBER();
  346. const2 = CurText();
  347. NeedRIGHT();
  348. growth->constants.push_back( const1 );
  349. growth->constants.push_back( const2 );
  350. break;
  351. case T_write_resolution: // [(writee_resolution {<character> <positive_integer >})]
  352. while( (tok = NextTok()) != T_RIGHT )
  353. {
  354. if( tok!=T_SYMBOL )
  355. Expecting( T_SYMBOL );
  356. tok = NextTok();
  357. if( tok!=T_NUMBER )
  358. Expecting( T_NUMBER );
  359. // @todo
  360. }
  361. break;
  362. case T_routes_include: // [(routes_include {[testpoint | guides | image_conductor]})]
  363. while( (tok = NextTok()) != T_RIGHT )
  364. {
  365. switch( tok )
  366. {
  367. case T_testpoint:
  368. growth->routes_include_testpoint = true;
  369. break;
  370. case T_guide:
  371. growth->routes_include_guides = true;
  372. break;
  373. case T_image_conductor:
  374. growth->routes_include_image_conductor = true;
  375. break;
  376. default:
  377. Expecting( "testpoint|guides|image_conductor" );
  378. }
  379. }
  380. break;
  381. case T_wires_include: // [(wires_include testpoint)]
  382. tok = NextTok();
  383. if( tok != T_testpoint )
  384. Expecting( T_testpoint );
  385. growth->routes_include_testpoint = true;
  386. NeedRIGHT();
  387. break;
  388. case T_case_sensitive:
  389. tok = NextTok();
  390. if( tok!=T_on && tok!=T_off )
  391. Expecting( "on|off" );
  392. growth->case_sensitive = (tok==T_on);
  393. NeedRIGHT();
  394. break;
  395. case T_via_rotate_first: // [(via_rotate_first [on | off])]
  396. tok = NextTok();
  397. if( tok!=T_on && tok!=T_off )
  398. Expecting( "on|off" );
  399. growth->via_rotate_first = (tok==T_on);
  400. NeedRIGHT();
  401. break;
  402. case T_generated_by_freeroute:
  403. growth->generated_by_freeroute = true;
  404. NeedRIGHT();
  405. break;
  406. default:
  407. Unexpected( CurText() );
  408. }
  409. }
  410. }
  411. void SPECCTRA_DB::doRESOLUTION( UNIT_RES* growth ) throw( IO_ERROR )
  412. {
  413. T tok = NextTok();
  414. switch( tok )
  415. {
  416. case T_inch:
  417. case T_mil:
  418. case T_cm:
  419. case T_mm:
  420. case T_um:
  421. growth->units = tok;
  422. break;
  423. default:
  424. Expecting( "inch|mil|cm|mm|um" );
  425. }
  426. tok = NextTok();
  427. if( tok != T_NUMBER )
  428. Expecting( T_NUMBER );
  429. growth->value = atoi( CurText() );
  430. NeedRIGHT();
  431. }
  432. void SPECCTRA_DB::doUNIT( UNIT_RES* growth ) throw( IO_ERROR )
  433. {
  434. T tok = NextTok();
  435. switch( tok )
  436. {
  437. case T_inch:
  438. case T_mil:
  439. case T_cm:
  440. case T_mm:
  441. case T_um:
  442. growth->units = tok;
  443. break;
  444. default:
  445. Expecting( "inch|mil|cm|mm|um" );
  446. }
  447. NeedRIGHT();
  448. }
  449. void SPECCTRA_DB::doLAYER_PAIR( LAYER_PAIR* growth ) throw( IO_ERROR )
  450. {
  451. NeedSYMBOL();
  452. growth->layer_id0 = CurText();
  453. NeedSYMBOL();
  454. growth->layer_id1 = CurText();
  455. if( NextTok() != T_NUMBER )
  456. Expecting( T_NUMBER );
  457. growth->layer_weight = strtod( CurText(), 0 );
  458. NeedRIGHT();
  459. }
  460. void SPECCTRA_DB::doLAYER_NOISE_WEIGHT( LAYER_NOISE_WEIGHT* growth ) throw( IO_ERROR )
  461. {
  462. T tok;
  463. while( (tok = NextTok()) != T_RIGHT )
  464. {
  465. if( tok != T_LEFT )
  466. Expecting( T_LEFT );
  467. if( NextTok() != T_layer_pair )
  468. Expecting( T_layer_pair );
  469. LAYER_PAIR* layer_pair = new LAYER_PAIR( growth );
  470. growth->layer_pairs.push_back( layer_pair );
  471. doLAYER_PAIR( layer_pair );
  472. }
  473. }
  474. void SPECCTRA_DB::doSTRUCTURE( STRUCTURE* growth ) throw( IO_ERROR )
  475. {
  476. T tok;
  477. while( (tok = NextTok()) != T_RIGHT )
  478. {
  479. if( tok != T_LEFT )
  480. Expecting( T_LEFT );
  481. tok = NextTok();
  482. switch( tok )
  483. {
  484. case T_unit:
  485. if( growth->unit )
  486. Unexpected( tok );
  487. growth->unit = new UNIT_RES( growth, tok );
  488. doUNIT( growth->unit );
  489. break;
  490. case T_resolution:
  491. if( growth->unit )
  492. Unexpected( tok );
  493. growth->unit = new UNIT_RES( growth, tok );
  494. doRESOLUTION( growth->unit );
  495. break;
  496. case T_layer_noise_weight:
  497. if( growth->layer_noise_weight )
  498. Unexpected( tok );
  499. growth->layer_noise_weight = new LAYER_NOISE_WEIGHT( growth );
  500. doLAYER_NOISE_WEIGHT( growth->layer_noise_weight );
  501. break;
  502. case T_place_boundary:
  503. L_place:
  504. if( growth->place_boundary )
  505. Unexpected( tok );
  506. growth->place_boundary = new BOUNDARY( growth, T_place_boundary );
  507. doBOUNDARY( growth->place_boundary );
  508. break;
  509. case T_boundary:
  510. if( growth->boundary )
  511. {
  512. if( growth->place_boundary )
  513. Unexpected( tok );
  514. goto L_place;
  515. }
  516. growth->boundary = new BOUNDARY( growth );
  517. doBOUNDARY( growth->boundary );
  518. break;
  519. case T_plane:
  520. COPPER_PLANE* plane;
  521. plane = new COPPER_PLANE( growth );
  522. growth->planes.push_back( plane );
  523. doKEEPOUT( plane );
  524. break;
  525. case T_region:
  526. REGION* region;
  527. region = new REGION( growth );
  528. growth->regions.push_back( region );
  529. doREGION( region );
  530. break;
  531. case T_snap_angle:
  532. STRINGPROP* stringprop;
  533. stringprop = new STRINGPROP( growth, T_snap_angle );
  534. growth->Append( stringprop );
  535. doSTRINGPROP( stringprop );
  536. break;
  537. case T_via:
  538. if( growth->via )
  539. Unexpected( tok );
  540. growth->via = new VIA( growth );
  541. doVIA( growth->via );
  542. break;
  543. case T_control:
  544. if( growth->control )
  545. Unexpected( tok );
  546. growth->control = new CONTROL( growth );
  547. doCONTROL( growth->control );
  548. break;
  549. case T_layer:
  550. LAYER* layer;
  551. layer = new LAYER( growth );
  552. growth->layers.push_back( layer );
  553. doLAYER( layer );
  554. break;
  555. case T_rule:
  556. if( growth->rules )
  557. Unexpected( tok );
  558. growth->rules = new RULE( growth, T_rule );
  559. doRULE( growth->rules );
  560. break;
  561. case T_place_rule:
  562. if( growth->place_rules )
  563. Unexpected( tok );
  564. growth->place_rules = new RULE( growth, T_place_rule );
  565. doRULE( growth->place_rules );
  566. break;
  567. case T_keepout:
  568. case T_place_keepout:
  569. case T_via_keepout:
  570. case T_wire_keepout:
  571. case T_bend_keepout:
  572. case T_elongate_keepout:
  573. KEEPOUT* keepout;
  574. keepout = new KEEPOUT( growth, tok );
  575. growth->keepouts.push_back( keepout );
  576. doKEEPOUT( keepout );
  577. break;
  578. case T_grid:
  579. GRID* grid;
  580. grid = new GRID( growth );
  581. growth->grids.push_back( grid );
  582. doGRID( grid );
  583. break;
  584. default:
  585. Unexpected( CurText() );
  586. }
  587. }
  588. }
  589. void SPECCTRA_DB::doSTRUCTURE_OUT( STRUCTURE_OUT* growth ) throw( IO_ERROR )
  590. {
  591. /*
  592. <structure_out_descriptor >::=
  593. (structure_out
  594. {<layer_descriptor> }
  595. [<rule_descriptor> ]
  596. )
  597. */
  598. T tok = NextTok();
  599. while( tok != T_RIGHT )
  600. {
  601. if( tok != T_LEFT )
  602. Expecting( T_LEFT );
  603. tok = NextTok();
  604. switch( tok )
  605. {
  606. case T_layer:
  607. LAYER* layer;
  608. layer = new LAYER( growth );
  609. growth->layers.push_back( layer );
  610. doLAYER( layer );
  611. break;
  612. case T_rule:
  613. if( growth->rules )
  614. Unexpected( tok );
  615. growth->rules = new RULE( growth, T_rule );
  616. doRULE( growth->rules );
  617. break;
  618. default:
  619. Unexpected( CurText() );
  620. }
  621. tok = NextTok();
  622. }
  623. }
  624. void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth ) throw( IO_ERROR )
  625. {
  626. T tok = NextTok();
  627. if( IsSymbol(tok) )
  628. {
  629. growth->name = CurText();
  630. tok = NextTok();
  631. }
  632. if( tok!=T_LEFT )
  633. Expecting( T_LEFT );
  634. while( tok != T_RIGHT )
  635. {
  636. if( tok!=T_LEFT )
  637. Expecting( T_LEFT );
  638. tok = NextTok();
  639. switch( tok )
  640. {
  641. case T_sequence_number:
  642. if( NextTok() != T_NUMBER )
  643. Expecting( T_NUMBER );
  644. growth->sequence_number = atoi( CurText() );
  645. NeedRIGHT();
  646. break;
  647. case T_rule:
  648. if( growth->rules )
  649. Unexpected( tok );
  650. growth->rules = new RULE( growth, T_rule );
  651. doRULE( growth->rules );
  652. break;
  653. case T_place_rule:
  654. if( growth->place_rules )
  655. Unexpected( tok );
  656. growth->place_rules = new RULE( growth, T_place_rule );
  657. doRULE( growth->place_rules );
  658. break;
  659. case T_rect:
  660. if( growth->shape )
  661. Unexpected( tok );
  662. growth->shape = new RECTANGLE( growth );
  663. doRECTANGLE( (RECTANGLE*) growth->shape );
  664. break;
  665. case T_circle:
  666. if( growth->shape )
  667. Unexpected( tok );
  668. growth->shape = new CIRCLE( growth );
  669. doCIRCLE( (CIRCLE*) growth->shape );
  670. break;
  671. case T_polyline_path:
  672. tok = T_path;
  673. case T_path:
  674. case T_polygon:
  675. if( growth->shape )
  676. Unexpected( tok );
  677. growth->shape = new PATH( growth, tok );
  678. doPATH( (PATH*) growth->shape );
  679. break;
  680. case T_qarc:
  681. if( growth->shape )
  682. Unexpected( tok );
  683. growth->shape = new QARC( growth );
  684. doQARC( (QARC*) growth->shape );
  685. break;
  686. case T_window:
  687. WINDOW* window;
  688. window = new WINDOW( growth );
  689. growth->windows.push_back( window );
  690. doWINDOW( window );
  691. break;
  692. default:
  693. Unexpected( CurText() );
  694. }
  695. tok = NextTok();
  696. }
  697. }
  698. void SPECCTRA_DB::doCONNECT( CONNECT* growth ) throw( IO_ERROR )
  699. {
  700. /* from page 143 of specctra spec:
  701. (connect
  702. {(terminal <object_type> [<pin_reference> ])}
  703. )
  704. */
  705. T tok = NextTok();
  706. while( tok != T_RIGHT )
  707. {
  708. if( tok!=T_LEFT )
  709. Expecting( T_LEFT );
  710. tok = NextTok();
  711. switch( tok )
  712. {
  713. case T_terminal:
  714. // since we do not use the terminal information, simlpy toss it.
  715. while( ( tok = NextTok() ) != T_RIGHT && tok != T_EOF )
  716. ;
  717. break;
  718. default:
  719. Unexpected( CurText() );
  720. }
  721. tok = NextTok();
  722. }
  723. }
  724. void SPECCTRA_DB::doWINDOW( WINDOW* growth ) throw( IO_ERROR )
  725. {
  726. T tok = NextTok();
  727. while( tok != T_RIGHT )
  728. {
  729. if( tok!=T_LEFT )
  730. Expecting( T_LEFT );
  731. tok = NextTok();
  732. switch( tok )
  733. {
  734. case T_rect:
  735. if( growth->shape )
  736. Unexpected( tok );
  737. growth->shape = new RECTANGLE( growth );
  738. doRECTANGLE( (RECTANGLE*) growth->shape );
  739. break;
  740. case T_circle:
  741. if( growth->shape )
  742. Unexpected( tok );
  743. growth->shape = new CIRCLE( growth );
  744. doCIRCLE( (CIRCLE*) growth->shape );
  745. break;
  746. case T_polyline_path:
  747. tok = T_path;
  748. case T_path:
  749. case T_polygon:
  750. if( growth->shape )
  751. Unexpected( tok );
  752. growth->shape = new PATH( growth, tok );
  753. doPATH( (PATH*) growth->shape );
  754. break;
  755. case T_qarc:
  756. if( growth->shape )
  757. Unexpected( tok );
  758. growth->shape = new QARC( growth );
  759. doQARC( (QARC*) growth->shape );
  760. break;
  761. default:
  762. Unexpected( CurText() );
  763. }
  764. tok = NextTok();
  765. }
  766. }
  767. void SPECCTRA_DB::doBOUNDARY( BOUNDARY* growth ) throw( IO_ERROR )
  768. {
  769. T tok = NextTok();
  770. if( tok != T_LEFT )
  771. Expecting( T_LEFT );
  772. tok = NextTok();
  773. if( tok == T_rect )
  774. {
  775. if( growth->paths.size() )
  776. Unexpected( "rect when path already encountered" );
  777. growth->rectangle = new RECTANGLE( growth );
  778. doRECTANGLE( growth->rectangle );
  779. NeedRIGHT();
  780. }
  781. else if( tok == T_path )
  782. {
  783. if( growth->rectangle )
  784. Unexpected( "path when rect already encountered" );
  785. for(;;)
  786. {
  787. if( tok != T_path )
  788. Expecting( T_path );
  789. PATH* path = new PATH( growth, T_path ) ;
  790. growth->paths.push_back( path );
  791. doPATH( path );
  792. tok = NextTok();
  793. if( tok == T_RIGHT )
  794. break;
  795. if( tok != T_LEFT )
  796. Expecting(T_LEFT);
  797. tok = NextTok();
  798. }
  799. }
  800. else
  801. Expecting( "rect|path" );
  802. }
  803. void SPECCTRA_DB::doPATH( PATH* growth ) throw( IO_ERROR )
  804. {
  805. T tok = NextTok();
  806. if( !IsSymbol( tok ) )
  807. Expecting( "layer_id" );
  808. growth->layer_id = CurText();
  809. if( NextTok() != T_NUMBER )
  810. Expecting( "aperture_width" );
  811. growth->aperture_width = strtod( CurText(), NULL );
  812. POINT ptTemp;
  813. tok = NextTok();
  814. do
  815. {
  816. if( tok != T_NUMBER )
  817. Expecting( T_NUMBER );
  818. ptTemp.x = strtod( CurText(), NULL );
  819. if( NextTok() != T_NUMBER )
  820. Expecting( T_NUMBER );
  821. ptTemp.y = strtod( CurText(), NULL );
  822. growth->points.push_back( ptTemp );
  823. } while( (tok = NextTok())!=T_RIGHT && tok!=T_LEFT );
  824. if( tok == T_LEFT )
  825. {
  826. if( NextTok() != T_aperture_type )
  827. Expecting( T_aperture_type );
  828. tok = NextTok();
  829. if( tok!=T_round && tok!=T_square )
  830. Expecting( "round|square" );
  831. growth->aperture_type = tok;
  832. NeedRIGHT();
  833. }
  834. }
  835. void SPECCTRA_DB::doRECTANGLE( RECTANGLE* growth ) throw( IO_ERROR )
  836. {
  837. NeedSYMBOL();
  838. growth->layer_id = CurText();
  839. if( NextTok() != T_NUMBER )
  840. Expecting( T_NUMBER );
  841. growth->point0.x = strtod( CurText(), NULL );
  842. if( NextTok() != T_NUMBER )
  843. Expecting( T_NUMBER );
  844. growth->point0.y = strtod( CurText(), NULL );
  845. if( NextTok() != T_NUMBER )
  846. Expecting( T_NUMBER );
  847. growth->point1.x = strtod( CurText(), NULL );
  848. if( NextTok() != T_NUMBER )
  849. Expecting( T_NUMBER );
  850. growth->point1.y = strtod( CurText(), NULL );
  851. NeedRIGHT();
  852. }
  853. void SPECCTRA_DB::doCIRCLE( CIRCLE* growth ) throw( IO_ERROR )
  854. {
  855. T tok;
  856. NeedSYMBOL();
  857. growth->layer_id = CurText();
  858. if( NextTok() != T_NUMBER )
  859. Expecting( T_NUMBER );
  860. growth->diameter = strtod( CurText(), 0 );
  861. tok = NextTok();
  862. if( tok == T_NUMBER )
  863. {
  864. growth->vertex.x = strtod( CurText(), 0 );
  865. if( NextTok() != T_NUMBER )
  866. Expecting( T_NUMBER );
  867. growth->vertex.y = strtod( CurText(), 0 );
  868. tok = NextTok();
  869. }
  870. if( tok != T_RIGHT )
  871. Expecting( T_RIGHT );
  872. }
  873. void SPECCTRA_DB::doQARC( QARC* growth ) throw( IO_ERROR )
  874. {
  875. NeedSYMBOL();
  876. growth->layer_id = CurText();
  877. if( NextTok() != T_NUMBER )
  878. Expecting( T_NUMBER );
  879. growth->aperture_width = strtod( CurText(), 0 );
  880. for( int i=0; i<3; ++i )
  881. {
  882. if( NextTok() != T_NUMBER )
  883. Expecting( T_NUMBER );
  884. growth->vertex[i].x = strtod( CurText(), 0 );
  885. if( NextTok() != T_NUMBER )
  886. Expecting( T_NUMBER );
  887. growth->vertex[i].y = strtod( CurText(), 0 );
  888. }
  889. NeedRIGHT();
  890. }
  891. void SPECCTRA_DB::doSTRINGPROP( STRINGPROP* growth ) throw( IO_ERROR )
  892. {
  893. NeedSYMBOL();
  894. growth->value = CurText();
  895. NeedRIGHT();
  896. }
  897. void SPECCTRA_DB::doTOKPROP( TOKPROP* growth ) throw( IO_ERROR )
  898. {
  899. T tok = NextTok();
  900. if( tok<0 )
  901. Unexpected( CurText() );
  902. growth->value = tok;
  903. NeedRIGHT();
  904. }
  905. void SPECCTRA_DB::doVIA( VIA* growth ) throw( IO_ERROR )
  906. {
  907. T tok;
  908. while( (tok = NextTok()) != T_RIGHT )
  909. {
  910. if( tok == T_LEFT )
  911. {
  912. if( NextTok() != T_spare )
  913. Expecting( T_spare );
  914. while( (tok = NextTok()) != T_RIGHT )
  915. {
  916. if( !IsSymbol( tok ) )
  917. Expecting( T_SYMBOL );
  918. growth->spares.push_back( CurText() );
  919. }
  920. }
  921. else if( IsSymbol( tok ) )
  922. {
  923. growth->padstacks.push_back( CurText() );
  924. }
  925. else
  926. Unexpected( CurText() );
  927. }
  928. }
  929. void SPECCTRA_DB::doCONTROL( CONTROL* growth ) throw( IO_ERROR )
  930. {
  931. T tok;
  932. while( (tok = NextTok()) != T_RIGHT )
  933. {
  934. if( tok != T_LEFT )
  935. Expecting( T_LEFT );
  936. tok = NextTok();
  937. switch( tok )
  938. {
  939. case T_via_at_smd:
  940. tok = NextTok();
  941. if( tok!=T_on && tok!=T_off )
  942. Expecting( "on|off" );
  943. growth->via_at_smd = (tok==T_on);
  944. NeedRIGHT();
  945. break;
  946. case T_off_grid:
  947. case T_route_to_fanout_only:
  948. case T_force_to_terminal_point:
  949. case T_same_net_checking:
  950. case T_checking_trim_by_pin:
  951. case T_noise_calculation:
  952. case T_noise_accumulation:
  953. case T_include_pins_in_crosstalk:
  954. case T_bbv_ctr2ctr:
  955. case T_average_pair_length:
  956. case T_crosstalk_model:
  957. case T_roundoff_rotation:
  958. case T_microvia:
  959. case T_reroute_order_viols:
  960. TOKPROP* tokprop;
  961. tokprop = new TOKPROP( growth, tok ) ;
  962. growth->Append( tokprop );
  963. doTOKPROP( tokprop );
  964. break;
  965. default:
  966. Unexpected( CurText() );
  967. }
  968. }
  969. }
  970. void SPECCTRA_DB::doPROPERTIES( PROPERTIES* growth ) throw( IO_ERROR )
  971. {
  972. T tok;
  973. PROPERTY property; // construct it once here, append multiple times.
  974. while( (tok = NextTok()) != T_RIGHT )
  975. {
  976. if( tok != T_LEFT )
  977. Expecting( T_LEFT );
  978. NeedSYMBOLorNUMBER();
  979. property.name = CurText();
  980. NeedSYMBOLorNUMBER();
  981. property.value = CurText();
  982. growth->push_back( property );
  983. NeedRIGHT();
  984. }
  985. }
  986. void SPECCTRA_DB::doLAYER( LAYER* growth ) throw( IO_ERROR )
  987. {
  988. T tok = NextTok();
  989. if( !IsSymbol(tok) )
  990. Expecting(T_SYMBOL);
  991. growth->name = CurText();
  992. while( (tok = NextTok()) != T_RIGHT )
  993. {
  994. if( tok != T_LEFT )
  995. Expecting( T_LEFT );
  996. tok = NextTok();
  997. switch( tok )
  998. {
  999. case T_type:
  1000. tok = NextTok();
  1001. if( tok!=T_signal && tok!=T_power && tok!=T_mixed && tok!=T_jumper )
  1002. Expecting( "signal|power|mixed|jumper" );
  1003. growth->layer_type = tok;
  1004. if( NextTok()!=T_RIGHT )
  1005. Expecting(T_RIGHT);
  1006. break;
  1007. case T_rule:
  1008. growth->rules = new RULE( growth, T_rule );
  1009. doRULE( growth->rules );
  1010. break;
  1011. case T_property:
  1012. doPROPERTIES( &growth->properties );
  1013. break;
  1014. case T_direction:
  1015. tok = NextTok();
  1016. switch( tok )
  1017. {
  1018. case T_horizontal:
  1019. case T_vertical:
  1020. case T_orthogonal:
  1021. case T_positive_diagonal:
  1022. case T_negative_diagonal:
  1023. case T_diagonal:
  1024. case T_off:
  1025. growth->direction = tok;
  1026. break;
  1027. default:
  1028. // the spec has an example show an abbreviation of the "horizontal" keyword. Ouch.
  1029. if( !strcmp( "hori", CurText() ) )
  1030. {
  1031. growth->direction = T_horizontal;
  1032. break;
  1033. }
  1034. else if( !strcmp( "vert", CurText() ) )
  1035. {
  1036. growth->direction = T_vertical;
  1037. break;
  1038. }
  1039. Expecting( "horizontal|vertical|orthogonal|positive_diagonal|negative_diagonal|diagonal|off" );
  1040. }
  1041. if( NextTok()!=T_RIGHT )
  1042. Expecting(T_RIGHT);
  1043. break;
  1044. case T_cost:
  1045. tok = NextTok();
  1046. switch( tok )
  1047. {
  1048. case T_forbidden:
  1049. case T_high:
  1050. case T_medium:
  1051. case T_low:
  1052. case T_free:
  1053. growth->cost = tok;
  1054. break;
  1055. case T_NUMBER:
  1056. // store as negative so we can differentiate between
  1057. // T (positive) and T_NUMBER (negative)
  1058. growth->cost = -atoi( CurText() );
  1059. break;
  1060. default:
  1061. Expecting( "forbidden|high|medium|low|free|<positive_integer>|-1" );
  1062. }
  1063. tok = NextTok();
  1064. if( tok == T_LEFT )
  1065. {
  1066. if( NextTok() != T_type )
  1067. Unexpected( CurText() );
  1068. tok = NextTok();
  1069. if( tok!=T_length && tok!=T_way )
  1070. Expecting( "length|way" );
  1071. growth->cost_type = tok;
  1072. if( NextTok()!=T_RIGHT )
  1073. Expecting(T_RIGHT);
  1074. tok = NextTok();
  1075. }
  1076. if( tok!=T_RIGHT )
  1077. Expecting(T_RIGHT);
  1078. break;
  1079. case T_use_net:
  1080. while( (tok = NextTok()) != T_RIGHT )
  1081. {
  1082. if( !IsSymbol(tok) )
  1083. Expecting( T_SYMBOL );
  1084. growth->use_net.push_back( CurText() );
  1085. }
  1086. break;
  1087. default:
  1088. Unexpected( CurText() );
  1089. }
  1090. }
  1091. }
  1092. void SPECCTRA_DB::doRULE( RULE* growth ) throw( IO_ERROR )
  1093. {
  1094. std::string builder;
  1095. int bracketNesting = 1; // we already saw the opening T_LEFT
  1096. T tok = T_NONE;
  1097. while( bracketNesting!=0 && tok!=T_EOF )
  1098. {
  1099. tok = NextTok();
  1100. if( tok==T_LEFT)
  1101. ++bracketNesting;
  1102. else if( tok==T_RIGHT )
  1103. --bracketNesting;
  1104. if( bracketNesting >= 1 )
  1105. {
  1106. if( PrevTok()!=T_LEFT && tok!=T_RIGHT && (tok!=T_LEFT || bracketNesting>2) )
  1107. builder += ' ';
  1108. if( tok==T_STRING )
  1109. builder += quote_char;
  1110. builder += CurText();
  1111. if( tok==T_STRING )
  1112. builder += quote_char;
  1113. }
  1114. // When the nested rule is closed with a T_RIGHT and we are back down
  1115. // to bracketNesting == 1, (inside the <rule_descriptor> but outside
  1116. // the last rule). Then save the last rule and clear the string builder.
  1117. if( bracketNesting == 1 )
  1118. {
  1119. growth->rules.push_back( builder );
  1120. builder.clear();
  1121. }
  1122. }
  1123. if( tok==T_EOF )
  1124. Unexpected( T_EOF );
  1125. }
  1126. #if 0
  1127. void SPECCTRA_DB::doPLACE_RULE( PLACE_RULE* growth, bool expect_object_type ) throw( IO_ERROR )
  1128. {
  1129. /* (place_rule [<structure_place_rule_object> ]
  1130. {[<spacing_descriptor> |
  1131. <permit_orient_descriptor> |
  1132. <permit_side_descriptor> |
  1133. <opposite_side_descriptor> ]}
  1134. )
  1135. */
  1136. T tok = NextTok();
  1137. if( tok!=T_LEFT )
  1138. Expecting( T_LEFT );
  1139. tok = NextTok();
  1140. if( tok==T_object_type )
  1141. {
  1142. if( !expect_object_type )
  1143. Unexpected( tok );
  1144. /* [(object_type
  1145. [pcb |
  1146. image_set [large | small | discrete | capacitor | resistor]
  1147. [(image_type [smd | pin])]]
  1148. )]
  1149. */
  1150. tok = NextTok();
  1151. switch( tok )
  1152. {
  1153. case T_pcb:
  1154. growth->object_type = tok;
  1155. break;
  1156. case T_image_set:
  1157. tok = NextTok();
  1158. switch( tok )
  1159. {
  1160. case T_large:
  1161. case T_small:
  1162. case T_discrete:
  1163. case T_capacitor:
  1164. case T_resistor:
  1165. growth->object_type = tok;
  1166. break;
  1167. default:
  1168. Unexpected( CurText() );
  1169. }
  1170. break;
  1171. default:
  1172. Unexpected( CurText() );
  1173. }
  1174. tok = NextTok();
  1175. if( tok == T_LEFT )
  1176. {
  1177. tok = NextTok();
  1178. if( tok != T_image_type )
  1179. Expecting( T_image_type );
  1180. tok = NextTok();
  1181. if( tok!=T_smd && tok!=T_pin )
  1182. Expecting( "smd|pin" );
  1183. NeedRIGHT();
  1184. tok = NextTok();
  1185. }
  1186. if( tok != T_RIGHT )
  1187. Expecting( T_RIGHT );
  1188. tok = NextTok();
  1189. }
  1190. /* {[<spacing_descriptor> |
  1191. <permit_orient_descriptor> |
  1192. <permit_side_descriptor> | <opposite_side_descriptor> ]}
  1193. */
  1194. doRULE( growth );
  1195. }
  1196. #endif
  1197. void SPECCTRA_DB::doREGION( REGION* growth ) throw( IO_ERROR )
  1198. {
  1199. T tok = NextTok();
  1200. if( IsSymbol(tok) )
  1201. {
  1202. growth->region_id = CurText();
  1203. tok = NextTok();
  1204. }
  1205. for(;;)
  1206. {
  1207. if( tok != T_LEFT )
  1208. Expecting( T_LEFT );
  1209. tok = NextTok();
  1210. switch( tok )
  1211. {
  1212. case T_rect:
  1213. if( growth->rectangle )
  1214. Unexpected( tok );
  1215. growth->rectangle = new RECTANGLE( growth );
  1216. doRECTANGLE( growth->rectangle );
  1217. break;
  1218. case T_polygon:
  1219. if( growth->polygon )
  1220. Unexpected( tok );
  1221. growth->polygon = new PATH( growth, T_polygon );
  1222. doPATH( growth->polygon );
  1223. break;
  1224. case T_region_net:
  1225. case T_region_class:
  1226. STRINGPROP* stringprop;
  1227. stringprop = new STRINGPROP( growth, tok );
  1228. growth->Append( stringprop );
  1229. doSTRINGPROP( stringprop );
  1230. break;
  1231. case T_region_class_class:
  1232. CLASS_CLASS* class_class;
  1233. class_class = new CLASS_CLASS( growth, tok );
  1234. growth->Append( class_class );
  1235. doCLASS_CLASS( class_class );
  1236. break;
  1237. case T_rule:
  1238. if( growth->rules )
  1239. Unexpected( tok );
  1240. growth->rules = new RULE( growth, T_rule );
  1241. doRULE( growth->rules );
  1242. break;
  1243. default:
  1244. Unexpected( CurText() );
  1245. }
  1246. tok = NextTok();
  1247. if( tok == T_RIGHT )
  1248. {
  1249. if( !growth->rules )
  1250. Expecting( T_rule );
  1251. break;
  1252. }
  1253. }
  1254. }
  1255. void SPECCTRA_DB::doCLASS_CLASS( CLASS_CLASS* growth ) throw( IO_ERROR )
  1256. {
  1257. T tok = NextTok();
  1258. if( tok != T_LEFT )
  1259. Expecting( T_LEFT );
  1260. while( (tok = NextTok()) != T_RIGHT )
  1261. {
  1262. switch( tok )
  1263. {
  1264. case T_classes:
  1265. if( growth->classes )
  1266. Unexpected( tok );
  1267. growth->classes = new CLASSES( growth );
  1268. doCLASSES( growth->classes );
  1269. break;
  1270. case T_rule:
  1271. // only T_class_class takes a T_rule
  1272. if( growth->Type() == T_region_class_class )
  1273. Unexpected( tok );
  1274. RULE* rule;
  1275. rule = new RULE( growth, T_rule );
  1276. growth->Append( rule );
  1277. doRULE( rule );
  1278. break;
  1279. case T_layer_rule:
  1280. // only T_class_class takes a T_layer_rule
  1281. if( growth->Type() == T_region_class_class )
  1282. Unexpected( tok );
  1283. LAYER_RULE* layer_rule;
  1284. layer_rule = new LAYER_RULE( growth );
  1285. growth->Append( layer_rule );
  1286. doLAYER_RULE( layer_rule );
  1287. break;
  1288. default:
  1289. Unexpected( tok );
  1290. }
  1291. }
  1292. }
  1293. void SPECCTRA_DB::doCLASSES( CLASSES* growth ) throw( IO_ERROR )
  1294. {
  1295. T tok = NextTok();
  1296. // require at least 2 class_ids
  1297. if( !IsSymbol( tok ) )
  1298. Expecting( "class_id" );
  1299. growth->class_ids.push_back( CurText() );
  1300. do
  1301. {
  1302. tok = NextTok();
  1303. if( !IsSymbol( tok ) )
  1304. Expecting( "class_id" );
  1305. growth->class_ids.push_back( CurText() );
  1306. } while( (tok = NextTok()) != T_RIGHT );
  1307. }
  1308. void SPECCTRA_DB::doGRID( GRID* growth ) throw( IO_ERROR )
  1309. {
  1310. T tok = NextTok();
  1311. switch( tok )
  1312. {
  1313. case T_via:
  1314. case T_wire:
  1315. case T_via_keepout:
  1316. case T_snap:
  1317. case T_place:
  1318. growth->grid_type = tok;
  1319. if( NextTok() != T_NUMBER )
  1320. Expecting( T_NUMBER );
  1321. growth->dimension = strtod( CurText(), 0 );
  1322. tok = NextTok();
  1323. if( tok == T_LEFT )
  1324. {
  1325. while( (tok=NextTok()) != T_RIGHT )
  1326. {
  1327. if( tok==T_direction )
  1328. {
  1329. if( growth->grid_type == T_place )
  1330. Unexpected( tok );
  1331. tok = NextTok();
  1332. if( tok!=T_x && tok!=T_y )
  1333. Unexpected( CurText() );
  1334. growth->direction = tok;
  1335. if( NextTok() != T_RIGHT )
  1336. Expecting(T_RIGHT);
  1337. }
  1338. else if( tok==T_offset )
  1339. {
  1340. if( growth->grid_type == T_place )
  1341. Unexpected( tok );
  1342. if( NextTok() != T_NUMBER )
  1343. Expecting( T_NUMBER );
  1344. growth->offset = strtod( CurText(), 0 );
  1345. if( NextTok() != T_RIGHT )
  1346. Expecting(T_RIGHT);
  1347. }
  1348. else if( tok==T_image_type )
  1349. {
  1350. if( growth->grid_type != T_place )
  1351. Unexpected( tok );
  1352. tok = NextTok();
  1353. if( tok!=T_smd && tok!=T_pin )
  1354. Unexpected( CurText() );
  1355. growth->image_type = tok;
  1356. if( NextTok() != T_RIGHT )
  1357. Expecting(T_RIGHT);
  1358. }
  1359. }
  1360. }
  1361. break;
  1362. default:
  1363. Unexpected( tok );
  1364. }
  1365. }
  1366. void SPECCTRA_DB::doLAYER_RULE( LAYER_RULE* growth ) throw( IO_ERROR )
  1367. {
  1368. T tok;
  1369. NeedSYMBOL();
  1370. do
  1371. {
  1372. growth->layer_ids.push_back( CurText() );
  1373. } while( IsSymbol(tok = NextTok()) );
  1374. if( tok != T_LEFT )
  1375. Expecting( T_LEFT );
  1376. if( NextTok() != T_rule )
  1377. Expecting( T_rule );
  1378. growth->rule = new RULE( growth, T_rule );
  1379. doRULE( growth->rule );
  1380. NeedRIGHT();
  1381. }
  1382. void SPECCTRA_DB::doPLACE( PLACE* growth ) throw( IO_ERROR )
  1383. {
  1384. T tok = NextTok();
  1385. if( !IsSymbol( tok ) )
  1386. Expecting( "component_id" );
  1387. growth->component_id = CurText();
  1388. tok = NextTok();
  1389. if( tok == T_NUMBER )
  1390. {
  1391. POINT point;
  1392. point.x = strtod( CurText(), 0 );
  1393. if( NextTok() != T_NUMBER )
  1394. Expecting( T_NUMBER );
  1395. point.y = strtod( CurText(), 0 );
  1396. growth->SetVertex( point );
  1397. tok = NextTok();
  1398. if( tok!=T_front && tok!=T_back )
  1399. Expecting( "front|back" );
  1400. growth->side = tok;
  1401. if( NextTok() != T_NUMBER )
  1402. Expecting( "rotation" );
  1403. growth->SetRotation( strtod( CurText(), 0) );
  1404. }
  1405. while( (tok = NextTok()) != T_RIGHT )
  1406. {
  1407. if( tok != T_LEFT )
  1408. Expecting( T_LEFT );
  1409. tok = NextTok();
  1410. switch( tok )
  1411. {
  1412. case T_mirror:
  1413. tok = NextTok();
  1414. if( tok==T_x || tok==T_y || tok==T_xy || tok==T_off )
  1415. growth->mirror = tok;
  1416. else
  1417. Expecting("x|y|xy|off");
  1418. break;
  1419. case T_status:
  1420. tok = NextTok();
  1421. if( tok==T_added || tok==T_deleted || tok==T_substituted )
  1422. growth->status = tok;
  1423. else
  1424. Expecting("added|deleted|substituted");
  1425. break;
  1426. case T_logical_part:
  1427. if( growth->logical_part.size() )
  1428. Unexpected( tok );
  1429. tok = NextTok();
  1430. if( !IsSymbol( tok ) )
  1431. Expecting( "logical_part_id");
  1432. growth->logical_part = CurText();
  1433. break;
  1434. case T_place_rule:
  1435. if( growth->place_rules )
  1436. Unexpected( tok );
  1437. growth->place_rules = new RULE( growth, T_place_rule );
  1438. doRULE( growth->place_rules );
  1439. break;
  1440. case T_property:
  1441. if( growth->properties.size() )
  1442. Unexpected( tok );
  1443. doPROPERTIES( &growth->properties );
  1444. break;
  1445. case T_lock_type:
  1446. tok = NextTok();
  1447. if( tok==T_position || tok==T_gate || tok==T_subgate || tok==T_pin )
  1448. growth->lock_type = tok;
  1449. else
  1450. Expecting("position|gate|subgate|pin");
  1451. break;
  1452. case T_rule:
  1453. if( growth->rules || growth->region )
  1454. Unexpected( tok );
  1455. growth->rules = new RULE( growth, T_rule );
  1456. doRULE( growth->rules );
  1457. break;
  1458. case T_region:
  1459. if( growth->rules || growth->region )
  1460. Unexpected( tok );
  1461. growth->region = new REGION( growth );
  1462. doREGION( growth->region );
  1463. break;
  1464. case T_pn:
  1465. if( growth->part_number.size() )
  1466. Unexpected( tok );
  1467. NeedSYMBOLorNUMBER();
  1468. growth->part_number = CurText();
  1469. NeedRIGHT();
  1470. break;
  1471. default:
  1472. Unexpected( tok );
  1473. }
  1474. }
  1475. }
  1476. void SPECCTRA_DB::doCOMPONENT( COMPONENT* growth ) throw( IO_ERROR )
  1477. {
  1478. T tok = NextTok();
  1479. if( !IsSymbol( tok ) && tok != T_NUMBER )
  1480. Expecting( "image_id" );
  1481. growth->image_id = CurText();
  1482. while( (tok = NextTok()) != T_RIGHT )
  1483. {
  1484. if( tok != T_LEFT )
  1485. Expecting( T_LEFT );
  1486. tok = NextTok();
  1487. switch( tok )
  1488. {
  1489. case T_place:
  1490. PLACE* place;
  1491. place = new PLACE( growth );
  1492. growth->places.push_back( place );
  1493. doPLACE( place );
  1494. break;
  1495. default:
  1496. Unexpected(tok);
  1497. }
  1498. }
  1499. }
  1500. void SPECCTRA_DB::doPLACEMENT( PLACEMENT* growth ) throw( IO_ERROR )
  1501. {
  1502. T tok;
  1503. while( (tok = NextTok()) != T_RIGHT )
  1504. {
  1505. if( tok == T_EOF )
  1506. Unexpected( T_EOF );
  1507. if( tok != T_LEFT )
  1508. Expecting( T_LEFT );
  1509. tok = NextTok();
  1510. switch( tok )
  1511. {
  1512. case T_unit:
  1513. case T_resolution:
  1514. growth->unit = new UNIT_RES( growth, tok );
  1515. if( tok==T_resolution )
  1516. doRESOLUTION( growth->unit );
  1517. else
  1518. doUNIT( growth->unit );
  1519. break;
  1520. case T_place_control:
  1521. NeedRIGHT();
  1522. tok = NextTok();
  1523. if( tok != T_flip_style )
  1524. Expecting( T_flip_style );
  1525. tok = NextTok();
  1526. if( tok==T_mirror_first || tok==T_rotate_first )
  1527. growth->flip_style = tok;
  1528. else
  1529. Expecting( "mirror_first|rotate_first" );
  1530. NeedRIGHT();
  1531. NeedRIGHT();
  1532. break;
  1533. case T_component:
  1534. COMPONENT* component;
  1535. component = new COMPONENT( growth );
  1536. growth->components.push_back( component );
  1537. doCOMPONENT( component );
  1538. break;
  1539. default:
  1540. Unexpected( tok );
  1541. }
  1542. }
  1543. }
  1544. void SPECCTRA_DB::doPADSTACK( PADSTACK* growth ) throw( IO_ERROR )
  1545. {
  1546. T tok = NextTok();
  1547. /* (padstack <padstack_id >
  1548. [<unit_descriptor> ]
  1549. {(shape <shape_descriptor>
  1550. [<reduced_shape_descriptor> ]
  1551. [(connect [on | off])]
  1552. [{<window_descriptor> }]
  1553. )}
  1554. [<attach_descriptor> ]
  1555. [{<pad_via_site_descriptor> }]
  1556. [(rotate [on | off])]
  1557. [(absolute [on | off])]
  1558. [(rule <clearance_descriptor> )])
  1559. */
  1560. // padstack_id may be a number
  1561. if( !IsSymbol( tok ) && tok!=T_NUMBER )
  1562. Expecting( "padstack_id" );
  1563. growth->padstack_id = CurText();
  1564. while( (tok = NextTok()) != T_RIGHT )
  1565. {
  1566. if( tok != T_LEFT )
  1567. Expecting( T_LEFT );
  1568. tok = NextTok();
  1569. switch( tok )
  1570. {
  1571. case T_unit:
  1572. if( growth->unit )
  1573. Unexpected( tok );
  1574. growth->unit = new UNIT_RES( growth, tok );
  1575. doUNIT( growth->unit );
  1576. break;
  1577. case T_rotate:
  1578. tok = NextTok();
  1579. if( tok!=T_on && tok!=T_off )
  1580. Expecting( "on|off" );
  1581. growth->rotate = tok;
  1582. NeedRIGHT();
  1583. break;
  1584. case T_absolute:
  1585. tok = NextTok();
  1586. if( tok!=T_on && tok!=T_off )
  1587. Expecting( "on|off" );
  1588. growth->absolute = tok;
  1589. NeedRIGHT();
  1590. break;
  1591. case T_shape:
  1592. SHAPE* shape;
  1593. shape = new SHAPE( growth );
  1594. growth->Append( shape );
  1595. doSHAPE( shape );
  1596. break;
  1597. case T_attach:
  1598. tok = NextTok();
  1599. if( tok!=T_off && tok!=T_on )
  1600. Expecting( "off|on" );
  1601. growth->attach = tok;
  1602. tok = NextTok();
  1603. if( tok == T_LEFT )
  1604. {
  1605. if( NextTok() != T_use_via )
  1606. Expecting( T_use_via );
  1607. NeedSYMBOL();
  1608. growth->via_id = CurText();
  1609. NeedRIGHT();
  1610. NeedRIGHT();
  1611. }
  1612. break;
  1613. /*
  1614. case T_via_site: not supported
  1615. break;
  1616. */
  1617. case T_rule:
  1618. if( growth->rules )
  1619. Unexpected( tok );
  1620. growth->rules = new RULE( growth, T_rule );
  1621. doRULE( growth->rules );
  1622. break;
  1623. default:
  1624. Unexpected( CurText() );
  1625. }
  1626. }
  1627. }
  1628. void SPECCTRA_DB::doSHAPE( SHAPE* growth ) throw( IO_ERROR )
  1629. {
  1630. T tok;
  1631. /* (shape <shape_descriptor>
  1632. [<reduced_shape_descriptor> ]
  1633. [(connect [on | off])]
  1634. [{<window_descriptor> }])
  1635. */
  1636. while( (tok = NextTok()) != T_RIGHT )
  1637. {
  1638. if( tok != T_LEFT )
  1639. Expecting( T_LEFT );
  1640. tok = NextTok();
  1641. switch( tok )
  1642. {
  1643. case T_polyline_path:
  1644. tok = T_path;
  1645. case T_rect:
  1646. case T_circle:
  1647. case T_path:
  1648. case T_polygon:
  1649. case T_qarc:
  1650. L_done_that:
  1651. if( growth->shape )
  1652. Unexpected( tok );
  1653. break;
  1654. default:
  1655. // the example in the spec uses "circ" instead of "circle". Bad!
  1656. if( !strcmp( "circ", CurText() ) )
  1657. {
  1658. tok = T_circle;
  1659. goto L_done_that;
  1660. }
  1661. }
  1662. switch( tok )
  1663. {
  1664. case T_rect:
  1665. growth->shape = new RECTANGLE( growth );
  1666. doRECTANGLE( (RECTANGLE*) growth->shape );
  1667. break;
  1668. case T_circle:
  1669. growth->shape = new CIRCLE( growth );
  1670. doCIRCLE( (CIRCLE*)growth->shape );
  1671. break;
  1672. case T_path:
  1673. case T_polygon:
  1674. growth->shape = new PATH( growth, tok );
  1675. doPATH( (PATH*)growth->shape );
  1676. break;
  1677. case T_qarc:
  1678. growth->shape = new QARC( growth );
  1679. doQARC( (QARC*)growth->shape );
  1680. break;
  1681. case T_connect:
  1682. tok = NextTok();
  1683. if( tok!=T_on && tok!=T_off )
  1684. Expecting( "on|off" );
  1685. growth->connect = tok;
  1686. NeedRIGHT();
  1687. break;
  1688. case T_window:
  1689. WINDOW* window;
  1690. window = new WINDOW( growth );
  1691. growth->windows.push_back( window );
  1692. doWINDOW( window );
  1693. break;
  1694. default:
  1695. Unexpected( CurText() );
  1696. }
  1697. }
  1698. }
  1699. void SPECCTRA_DB::doIMAGE( IMAGE* growth ) throw( IO_ERROR )
  1700. {
  1701. T tok = NextTok();
  1702. /* <image_descriptor >::=
  1703. (image <image_id >
  1704. [(side [front | back | both])]
  1705. [<unit_descriptor> ]
  1706. [<outline_descriptor> ]
  1707. {(pin <padstack_id > [(rotate <rotation> )]
  1708. [<reference_descriptor> | <pin_array_descriptor> ]
  1709. [<user_property_descriptor> ])}
  1710. [{<conductor_shape_descriptor> }]
  1711. [{<conductor_via_descriptor> }]
  1712. [<rule_descriptor> ]
  1713. [<place_rule_descriptor> ]
  1714. [{<keepout_descriptor> }]
  1715. [<image_property_descriptor> ]
  1716. )
  1717. */
  1718. if( !IsSymbol( tok ) && tok != T_NUMBER )
  1719. Expecting( "image_id" );
  1720. growth->image_id = CurText();
  1721. while( (tok = NextTok()) != T_RIGHT )
  1722. {
  1723. if( tok != T_LEFT )
  1724. Expecting( T_LEFT );
  1725. tok = NextTok();
  1726. switch( tok )
  1727. {
  1728. case T_unit:
  1729. if( growth->unit )
  1730. Unexpected( tok );
  1731. growth->unit = new UNIT_RES( growth, tok );
  1732. doUNIT( growth->unit );
  1733. break;
  1734. case T_side:
  1735. tok = NextTok();
  1736. if( tok!=T_front && tok!=T_back && tok!=T_both )
  1737. Expecting( "front|back|both" );
  1738. growth->side = tok;
  1739. NeedRIGHT();
  1740. break;
  1741. case T_outline:
  1742. SHAPE* outline;
  1743. outline = new SHAPE( growth, T_outline ); // use SHAPE for T_outline
  1744. growth->Append( outline );
  1745. doSHAPE( outline );
  1746. break;
  1747. case T_pin:
  1748. PIN* pin;
  1749. pin = new PIN( growth );
  1750. growth->pins.push_back( pin );
  1751. doPIN( pin );
  1752. break;
  1753. case T_rule:
  1754. if( growth->rules )
  1755. Unexpected( tok );
  1756. growth->rules = new RULE( growth, tok );
  1757. doRULE( growth->rules );
  1758. break;
  1759. case T_place_rule:
  1760. if( growth->place_rules )
  1761. Unexpected( tok );
  1762. growth->place_rules = new RULE( growth, tok );
  1763. doRULE( growth->place_rules );
  1764. break;
  1765. case T_keepout:
  1766. case T_place_keepout:
  1767. case T_via_keepout:
  1768. case T_wire_keepout:
  1769. case T_bend_keepout:
  1770. case T_elongate_keepout:
  1771. KEEPOUT* keepout;
  1772. keepout = new KEEPOUT( growth, tok );
  1773. growth->keepouts.push_back( keepout );
  1774. doKEEPOUT( keepout );
  1775. break;
  1776. default:
  1777. Unexpected( CurText() );
  1778. }
  1779. }
  1780. }
  1781. void SPECCTRA_DB::doPIN( PIN* growth ) throw( IO_ERROR )
  1782. {
  1783. T tok = NextTok();
  1784. /* (pin <padstack_id > [(rotate <rotation> )]
  1785. [<reference_descriptor> | <pin_array_descriptor> ]
  1786. [<user_property_descriptor> ])
  1787. */
  1788. // a padstack_id may be a number
  1789. if( !IsSymbol( tok ) && tok!=T_NUMBER )
  1790. Expecting( "padstack_id" );
  1791. growth->padstack_id = CurText();
  1792. while( (tok = NextTok()) != T_RIGHT )
  1793. {
  1794. if( tok == T_LEFT )
  1795. {
  1796. tok = NextTok();
  1797. if( tok != T_rotate )
  1798. Expecting( T_rotate );
  1799. if( NextTok() != T_NUMBER )
  1800. Expecting( T_NUMBER );
  1801. growth->SetRotation( strtod( CurText(), 0 ) );
  1802. NeedRIGHT();
  1803. }
  1804. else
  1805. {
  1806. if( !IsSymbol(tok) && tok!=T_NUMBER )
  1807. Expecting( "pin_id" );
  1808. growth->pin_id = CurText();
  1809. if( NextTok() != T_NUMBER )
  1810. Expecting( T_NUMBER );
  1811. growth->vertex.x = strtod( CurText(), 0 );
  1812. if( NextTok() != T_NUMBER )
  1813. Expecting( T_NUMBER );
  1814. growth->vertex.y = strtod( CurText(), 0 );
  1815. }
  1816. }
  1817. }
  1818. void SPECCTRA_DB::doLIBRARY( LIBRARY* growth ) throw( IO_ERROR )
  1819. {
  1820. T tok;
  1821. /* <library_descriptor >::=
  1822. (library
  1823. [<unit_descriptor> ]
  1824. {<image_descriptor> }
  1825. [{<jumper_descriptor> }]
  1826. {<padstack_descriptor> }
  1827. {<via_array_template_descriptor> }
  1828. [<directory_descriptor> ]
  1829. [<extra_image_directory_descriptor> ]
  1830. [{<family_family_descriptor> }]
  1831. [{<image_image_descriptor> }]
  1832. )
  1833. */
  1834. while( (tok = NextTok()) != T_RIGHT )
  1835. {
  1836. if( tok != T_LEFT )
  1837. Expecting( T_LEFT );
  1838. tok = NextTok();
  1839. switch( tok )
  1840. {
  1841. case T_unit:
  1842. if( growth->unit )
  1843. Unexpected( tok );
  1844. growth->unit = new UNIT_RES( growth, tok );
  1845. doUNIT( growth->unit );
  1846. break;
  1847. case T_padstack:
  1848. PADSTACK* padstack;
  1849. padstack = new PADSTACK();
  1850. growth->AddPadstack( padstack );
  1851. doPADSTACK( padstack );
  1852. break;
  1853. case T_image:
  1854. IMAGE* image;
  1855. image = new IMAGE( growth );
  1856. growth->images.push_back( image );
  1857. doIMAGE( image );
  1858. break;
  1859. default:
  1860. Unexpected( CurText() );
  1861. }
  1862. }
  1863. }
  1864. void SPECCTRA_DB::doNET( NET* growth ) throw( IO_ERROR )
  1865. {
  1866. T tok = NextTok();
  1867. PIN_REFS* pin_refs;
  1868. /* <net_descriptor >::=
  1869. (net <net_id >
  1870. [(unassigned)]
  1871. [(net_number <integer >)]
  1872. [(pins {<pin_reference> }) | (order {<pin_reference> })]
  1873. [<component_order_descriptor> ]
  1874. [(type [fix | normal])]
  1875. [<user_property_descriptor> ]
  1876. [<circuit_descriptor> ]
  1877. [<rule_descriptor> ]
  1878. [{<layer_rule_descriptor> }]
  1879. [<fromto_descriptor> ]
  1880. [(expose {<pin_reference> })]
  1881. [(noexpose {<pin_reference> })]
  1882. [(source {<pin_reference> })]
  1883. [(load {<pin_reference> })]
  1884. [(terminator {<pin_reference> })]
  1885. [(supply [power | ground])]
  1886. )
  1887. */
  1888. if( !IsSymbol( tok ) )
  1889. Expecting( "net_id" );
  1890. growth->net_id = CurText();
  1891. while( (tok = NextTok()) != T_RIGHT )
  1892. {
  1893. if( tok != T_LEFT )
  1894. Expecting( T_LEFT );
  1895. tok = NextTok();
  1896. switch( tok )
  1897. {
  1898. case T_unassigned:
  1899. growth->unassigned = true;
  1900. NeedRIGHT();
  1901. break;
  1902. case T_net_number:
  1903. if( NextTok() != T_NUMBER )
  1904. Expecting( T_NUMBER );
  1905. growth->net_number = atoi( CurText() );
  1906. NeedRIGHT();
  1907. break;
  1908. case T_pins:
  1909. case T_order:
  1910. growth->pins_type = tok;
  1911. pin_refs = &growth->pins;
  1912. goto L_pins;
  1913. case T_expose:
  1914. pin_refs = &growth->expose;
  1915. goto L_pins;
  1916. case T_noexpose:
  1917. pin_refs = &growth->noexpose;
  1918. goto L_pins;
  1919. case T_source:
  1920. pin_refs = &growth->source;
  1921. goto L_pins;
  1922. case T_load:
  1923. pin_refs = &growth->load;
  1924. goto L_pins;
  1925. case T_terminator:
  1926. pin_refs = &growth->terminator;
  1927. //goto L_pins;
  1928. L_pins:
  1929. {
  1930. PIN_REF empty( growth );
  1931. while( (tok = NextTok()) != T_RIGHT )
  1932. {
  1933. // copy the empty one, then fill its copy later thru pin_ref.
  1934. pin_refs->push_back( empty );
  1935. PIN_REF* pin_ref = &pin_refs->back();
  1936. readCOMPnPIN( &pin_ref->component_id, &pin_ref->pin_id );
  1937. }
  1938. }
  1939. break;
  1940. case T_comp_order:
  1941. if( growth->comp_order )
  1942. Unexpected( tok );
  1943. growth->comp_order = new COMP_ORDER( growth );
  1944. doCOMP_ORDER( growth->comp_order );
  1945. break;
  1946. case T_type:
  1947. tok = NextTok();
  1948. if( tok!=T_fix && tok!=T_normal )
  1949. Expecting( "fix|normal" );
  1950. growth->type = tok;
  1951. NeedRIGHT();
  1952. break;
  1953. /* @todo
  1954. case T_circuit:
  1955. break;
  1956. */
  1957. case T_rule:
  1958. if( growth->rules )
  1959. Unexpected( tok );
  1960. growth->rules = new RULE( growth, T_rule );
  1961. doRULE( growth->rules );
  1962. break;
  1963. case T_layer_rule:
  1964. LAYER_RULE* layer_rule;
  1965. layer_rule = new LAYER_RULE( growth );
  1966. growth->layer_rules.push_back( layer_rule );
  1967. doLAYER_RULE( layer_rule );
  1968. break;
  1969. case T_fromto:
  1970. FROMTO* fromto;
  1971. fromto = new FROMTO( growth );
  1972. growth->fromtos.push_back( fromto );
  1973. doFROMTO( fromto );
  1974. break;
  1975. default:
  1976. Unexpected( CurText() );
  1977. }
  1978. }
  1979. }
  1980. void SPECCTRA_DB::doTOPOLOGY( TOPOLOGY* growth ) throw( IO_ERROR )
  1981. {
  1982. T tok;
  1983. /* <topology_descriptor >::=
  1984. (topology {[<fromto_descriptor> |
  1985. <component_order_descriptor> ]})
  1986. */
  1987. while( (tok = NextTok()) != T_RIGHT )
  1988. {
  1989. if( tok != T_LEFT )
  1990. Expecting( T_LEFT );
  1991. tok = NextTok();
  1992. switch( tok )
  1993. {
  1994. case T_fromto:
  1995. FROMTO* fromto;
  1996. fromto = new FROMTO( growth );
  1997. growth->fromtos.push_back( fromto );
  1998. doFROMTO( fromto );
  1999. break;
  2000. case T_comp_order:
  2001. COMP_ORDER* comp_order;
  2002. comp_order = new COMP_ORDER( growth );
  2003. growth->comp_orders.push_back( comp_order );
  2004. doCOMP_ORDER( comp_order );
  2005. break;
  2006. default:
  2007. Unexpected( CurText() );
  2008. }
  2009. }
  2010. }
  2011. void SPECCTRA_DB::doCLASS( CLASS* growth ) throw( IO_ERROR )
  2012. {
  2013. T tok;
  2014. /* <class_descriptor >::=
  2015. (class
  2016. <class_id > {[{<net_id >} | {<composite_name_list> }]}
  2017. [<circuit_descriptor> ]
  2018. [<rule_descriptor> ]
  2019. [{<layer_rule_descriptor> }]
  2020. [<topology_descriptor> ]
  2021. )
  2022. */
  2023. NeedSYMBOL();
  2024. growth->class_id = CurText();
  2025. // do net_ids, do not support <composite_name_list>s at this time
  2026. while( IsSymbol(tok = NextTok()) )
  2027. {
  2028. growth->net_ids.push_back( CurText() );
  2029. }
  2030. while( tok != T_RIGHT )
  2031. {
  2032. if( tok != T_LEFT )
  2033. Expecting( T_LEFT );
  2034. tok = NextTok();
  2035. switch( tok )
  2036. {
  2037. case T_rule:
  2038. if( growth->rules )
  2039. Unexpected( tok );
  2040. growth->rules = new RULE( growth, T_rule );
  2041. doRULE( growth->rules );
  2042. break;
  2043. case T_layer_rule:
  2044. LAYER_RULE* layer_rule;
  2045. layer_rule = new LAYER_RULE( growth );
  2046. growth->layer_rules.push_back( layer_rule );
  2047. doLAYER_RULE( layer_rule );
  2048. break;
  2049. case T_topology:
  2050. if( growth->topology )
  2051. Unexpected( tok );
  2052. growth->topology = new TOPOLOGY( growth );
  2053. doTOPOLOGY( growth->topology );
  2054. break;
  2055. case T_circuit: // handle all the circuit_descriptor here as strings
  2056. {
  2057. std::string builder;
  2058. int bracketNesting = 1; // we already saw the opening T_LEFT
  2059. T tok = T_NONE;
  2060. while( bracketNesting!=0 && tok!=T_EOF )
  2061. {
  2062. tok = NextTok();
  2063. if( tok==T_LEFT)
  2064. ++bracketNesting;
  2065. else if( tok==T_RIGHT )
  2066. --bracketNesting;
  2067. if( bracketNesting >= 1 )
  2068. {
  2069. T prevTok = (T) PrevTok();
  2070. if( prevTok!=T_LEFT && prevTok!=T_circuit && tok!=T_RIGHT )
  2071. builder += ' ';
  2072. if( tok==T_STRING )
  2073. builder += quote_char;
  2074. builder += CurText();
  2075. if( tok==T_STRING )
  2076. builder += quote_char;
  2077. }
  2078. // When the nested rule is closed with a T_RIGHT and we are back down
  2079. // to bracketNesting == 0, then save the builder and break;
  2080. if( bracketNesting == 0 )
  2081. {
  2082. growth->circuit.push_back( builder );
  2083. break;
  2084. }
  2085. }
  2086. if( tok==T_EOF )
  2087. Unexpected( T_EOF );
  2088. } // scope bracket
  2089. break;
  2090. default:
  2091. Unexpected( CurText() );
  2092. } // switch
  2093. tok = NextTok();
  2094. } // while
  2095. }
  2096. void SPECCTRA_DB::doNETWORK( NETWORK* growth ) throw( IO_ERROR )
  2097. {
  2098. T tok;
  2099. /* <network_descriptor >::=
  2100. (network
  2101. {<net_descriptor>}
  2102. [{<class_descriptor> }]
  2103. [{<class_class_descriptor> }]
  2104. [{<group_descriptor> }]
  2105. [{<group_set_descriptor> }]
  2106. [{<pair_descriptor> }]
  2107. [{<bundle_descriptor> }]
  2108. )
  2109. */
  2110. while( (tok = NextTok()) != T_RIGHT )
  2111. {
  2112. if( tok != T_LEFT )
  2113. Expecting( T_LEFT );
  2114. tok = NextTok();
  2115. switch( tok )
  2116. {
  2117. case T_net:
  2118. NET* net;
  2119. net = new NET( growth );
  2120. growth->nets.push_back( net );
  2121. doNET( net );
  2122. break;
  2123. case T_class:
  2124. CLASS* myclass;
  2125. myclass = new CLASS( growth );
  2126. growth->classes.push_back( myclass );
  2127. doCLASS( myclass );
  2128. break;
  2129. default:
  2130. Unexpected( CurText() );
  2131. }
  2132. }
  2133. }
  2134. void SPECCTRA_DB::doCOMP_ORDER( COMP_ORDER* growth ) throw( IO_ERROR )
  2135. {
  2136. T tok;
  2137. /* <component_order_descriptor >::=
  2138. (comp_order {<placement_id> })
  2139. */
  2140. while( IsSymbol(tok = NextTok()) )
  2141. {
  2142. growth->placement_ids.push_back( CurText() );
  2143. }
  2144. if( tok != T_RIGHT )
  2145. Expecting( T_RIGHT );
  2146. }
  2147. void SPECCTRA_DB::doFROMTO( FROMTO* growth ) throw( IO_ERROR )
  2148. {
  2149. T tok;
  2150. /* <fromto_descriptor >::=
  2151. {(fromto
  2152. [<pin_reference> | <virtual_pin_descriptor> ] | <component_id >]
  2153. [<pin_reference> | <virtual_pin_descriptor> | <component_id >]
  2154. [(type [fix | normal | soft])]
  2155. [(net <net_id >)]
  2156. [<rule_descriptor> ]
  2157. [<circuit_descriptor> ]
  2158. [{<layer_rule_descriptor> }]
  2159. )}
  2160. */
  2161. // read the first two grammar items in as 2 single tokens, i.e. do not
  2162. // split apart the <pin_reference>s into 3 separate tokens. Do this by
  2163. // turning off the string delimiter in the lexer.
  2164. char old = SetStringDelimiter( 0 );
  2165. if( !IsSymbol(NextTok() ) )
  2166. {
  2167. SetStringDelimiter( old );
  2168. Expecting( T_SYMBOL );
  2169. }
  2170. growth->fromText = CurText();
  2171. if( !IsSymbol(NextTok() ) )
  2172. {
  2173. SetStringDelimiter( old );
  2174. Expecting( T_SYMBOL );
  2175. }
  2176. growth->toText = CurText();
  2177. SetStringDelimiter( old );
  2178. while( (tok = NextTok()) != T_RIGHT )
  2179. {
  2180. if( tok != T_LEFT )
  2181. Expecting( T_LEFT );
  2182. tok = NextTok();
  2183. switch( tok )
  2184. {
  2185. case T_type:
  2186. tok = NextTok();
  2187. if( tok!=T_fix && tok!=T_normal && tok!=T_soft )
  2188. Expecting( "fix|normal|soft" );
  2189. growth->fromto_type = tok;
  2190. NeedRIGHT();
  2191. break;
  2192. case T_rule:
  2193. if( growth->rules )
  2194. Unexpected( tok );
  2195. growth->rules = new RULE( growth, T_rule );
  2196. doRULE( growth->rules );
  2197. break;
  2198. case T_layer_rule:
  2199. LAYER_RULE* layer_rule;
  2200. layer_rule = new LAYER_RULE( growth );
  2201. growth->layer_rules.push_back( layer_rule );
  2202. doLAYER_RULE( layer_rule );
  2203. break;
  2204. case T_net:
  2205. if( growth->net_id.size() )
  2206. Unexpected( tok );
  2207. NeedSYMBOL();
  2208. growth->net_id = CurText();
  2209. NeedRIGHT();
  2210. break;
  2211. // circuit descriptor not supported at this time
  2212. default:
  2213. Unexpected( CurText() );
  2214. }
  2215. }
  2216. }
  2217. void SPECCTRA_DB::doWIRE( WIRE* growth ) throw( IO_ERROR )
  2218. {
  2219. T tok;
  2220. /* <wire_shape_descriptor >::=
  2221. (wire
  2222. <shape_descriptor>
  2223. [(net <net_id >)]
  2224. [(turret <turret#> )]
  2225. [(type [fix | route | normal | protect])]
  2226. [(attr [test | fanout | bus | jumper])]
  2227. [(shield <net_id >)]
  2228. [{<window_descriptor> }]
  2229. [(connect
  2230. (terminal <object_type> [<pin_reference> ])
  2231. (terminal <object_type> [<pin_reference> ])
  2232. )]
  2233. [(supply)]
  2234. )
  2235. */
  2236. while( (tok = NextTok()) != T_RIGHT )
  2237. {
  2238. if( tok != T_LEFT )
  2239. Expecting( T_LEFT );
  2240. tok = NextTok();
  2241. switch( tok )
  2242. {
  2243. case T_rect:
  2244. if( growth->shape )
  2245. Unexpected( tok );
  2246. growth->shape = new RECTANGLE( growth );
  2247. doRECTANGLE( (RECTANGLE*) growth->shape );
  2248. break;
  2249. case T_circle:
  2250. if( growth->shape )
  2251. Unexpected( tok );
  2252. growth->shape = new CIRCLE( growth );
  2253. doCIRCLE( (CIRCLE*) growth->shape );
  2254. break;
  2255. case T_polyline_path:
  2256. tok = T_path;
  2257. case T_path:
  2258. case T_polygon:
  2259. if( growth->shape )
  2260. Unexpected( tok );
  2261. growth->shape = new PATH( growth, tok );
  2262. doPATH( (PATH*) growth->shape );
  2263. break;
  2264. case T_qarc:
  2265. if( growth->shape )
  2266. Unexpected( tok );
  2267. growth->shape = new QARC( growth );
  2268. doQARC( (QARC*) growth->shape );
  2269. break;
  2270. case T_net:
  2271. NeedSYMBOL();
  2272. growth->net_id = CurText();
  2273. NeedRIGHT();
  2274. break;
  2275. case T_turret:
  2276. if( NextTok() != T_NUMBER )
  2277. Expecting( T_NUMBER );
  2278. growth->turret = atoi( CurText() );
  2279. NeedRIGHT();
  2280. break;
  2281. case T_type:
  2282. tok = NextTok();
  2283. if( tok!=T_fix && tok!=T_route && tok!=T_normal && tok!=T_protect )
  2284. Expecting( "fix|route|normal|protect" );
  2285. growth->wire_type = tok;
  2286. NeedRIGHT();
  2287. break;
  2288. case T_attr:
  2289. tok = NextTok();
  2290. if( tok!=T_test && tok!=T_fanout && tok!=T_bus && tok!=T_jumper )
  2291. Expecting( "test|fanout|bus|jumper" );
  2292. growth->attr = tok;
  2293. NeedRIGHT();
  2294. break;
  2295. case T_shield:
  2296. NeedSYMBOL();
  2297. growth->shield = CurText();
  2298. NeedRIGHT();
  2299. break;
  2300. case T_window:
  2301. WINDOW* window;
  2302. window = new WINDOW( growth );
  2303. growth->windows.push_back( window );
  2304. doWINDOW( window );
  2305. break;
  2306. case T_connect:
  2307. if( growth->connect )
  2308. Unexpected( tok );
  2309. growth->connect = new CONNECT( growth );
  2310. doCONNECT( growth->connect );
  2311. break;
  2312. case T_supply:
  2313. growth->supply = true;
  2314. NeedRIGHT();
  2315. break;
  2316. default:
  2317. Unexpected( CurText() );
  2318. }
  2319. }
  2320. }
  2321. void SPECCTRA_DB::doWIRE_VIA( WIRE_VIA* growth ) throw( IO_ERROR )
  2322. {
  2323. T tok;
  2324. POINT point;
  2325. /* <wire_via_descriptor >::=
  2326. (via
  2327. <padstack_id > {<vertex> }
  2328. [(net <net_id >)]
  2329. [(via_number <via#> )]
  2330. [(type [fix | route | normal | protect])]
  2331. [(attr [test | fanout | jumper |
  2332. virtual_pin <virtual_pin_name> ])]
  2333. [(contact {<layer_id >})]
  2334. [(supply)]
  2335. )
  2336. (virtual_pin
  2337. <virtual_pin_name> <vertex> (net <net_id >)
  2338. )
  2339. */
  2340. NeedSYMBOL();
  2341. growth->padstack_id = CurText();
  2342. while( (tok = NextTok()) == T_NUMBER )
  2343. {
  2344. point.x = strtod( CurText(), 0 );
  2345. if( NextTok() != T_NUMBER )
  2346. Expecting( "vertex.y" );
  2347. point.y = strtod( CurText(), 0 );
  2348. growth->vertexes.push_back( point );
  2349. }
  2350. while( tok != T_RIGHT )
  2351. {
  2352. if( tok != T_LEFT )
  2353. Expecting( T_LEFT );
  2354. tok = NextTok();
  2355. switch( tok )
  2356. {
  2357. case T_net:
  2358. NeedSYMBOL();
  2359. growth->net_id = CurText();
  2360. NeedRIGHT();
  2361. break;
  2362. case T_via_number:
  2363. if( NextTok() != T_NUMBER )
  2364. Expecting( "<via#>" );
  2365. growth->via_number = atoi( CurText() );
  2366. NeedRIGHT();
  2367. break;
  2368. case T_type:
  2369. tok = NextTok();
  2370. if( tok!=T_fix && tok!=T_route && tok!=T_normal && tok!=T_protect )
  2371. Expecting( "fix|route|normal|protect" );
  2372. growth->via_type = tok;
  2373. NeedRIGHT();
  2374. break;
  2375. case T_attr:
  2376. tok = NextTok();
  2377. if( tok!=T_test && tok!=T_fanout && tok!=T_jumper && tok!=T_virtual_pin )
  2378. Expecting( "test|fanout|jumper|virtual_pin" );
  2379. growth->attr = tok;
  2380. if( tok == T_virtual_pin )
  2381. {
  2382. NeedSYMBOL();
  2383. growth->virtual_pin_name = CurText();
  2384. }
  2385. NeedRIGHT();
  2386. break;
  2387. case T_contact:
  2388. NeedSYMBOL();
  2389. tok = T_SYMBOL;
  2390. while( IsSymbol(tok) )
  2391. {
  2392. growth->contact_layers.push_back( CurText() );
  2393. tok = NextTok();
  2394. }
  2395. if( tok != T_RIGHT )
  2396. Expecting( T_RIGHT );
  2397. break;
  2398. case T_supply:
  2399. growth->supply = true;
  2400. NeedRIGHT();
  2401. break;
  2402. default:
  2403. Unexpected( CurText() );
  2404. }
  2405. tok = NextTok();
  2406. }
  2407. }
  2408. void SPECCTRA_DB::doWIRING( WIRING* growth ) throw( IO_ERROR )
  2409. {
  2410. T tok;
  2411. /* <wiring_descriptor >::=
  2412. (wiring
  2413. [<unit_descriptor> | <resolution_descriptor> | null]
  2414. {<wire_descriptor> }
  2415. [<test_points_descriptor> ]
  2416. {[<supply_pin_descriptor> ]}
  2417. )
  2418. */
  2419. while( (tok = NextTok()) != T_RIGHT )
  2420. {
  2421. if( tok != T_LEFT )
  2422. Expecting( T_LEFT );
  2423. tok = NextTok();
  2424. switch( tok )
  2425. {
  2426. case T_unit:
  2427. if( growth->unit )
  2428. Unexpected( tok );
  2429. growth->unit = new UNIT_RES( growth, tok );
  2430. doUNIT( growth->unit );
  2431. break;
  2432. case T_resolution:
  2433. if( growth->unit )
  2434. Unexpected( tok );
  2435. growth->unit = new UNIT_RES( growth, tok );
  2436. doRESOLUTION( growth->unit );
  2437. break;
  2438. case T_wire:
  2439. WIRE* wire;
  2440. wire = new WIRE( growth );
  2441. growth->wires.push_back( wire );
  2442. doWIRE( wire );
  2443. break;
  2444. case T_via:
  2445. WIRE_VIA* wire_via;
  2446. wire_via = new WIRE_VIA( growth );
  2447. growth->wire_vias.push_back( wire_via );
  2448. doWIRE_VIA( wire_via );
  2449. break;
  2450. default:
  2451. Unexpected( CurText() );
  2452. }
  2453. }
  2454. }
  2455. void SPECCTRA_DB::doANCESTOR( ANCESTOR* growth ) throw( IO_ERROR )
  2456. {
  2457. T tok;
  2458. /* <ancestor_file_descriptor >::=
  2459. (ancestor <file_path_name> (created_time <time_stamp> )
  2460. [(comment <comment_string> )])
  2461. */
  2462. NeedSYMBOL();
  2463. growth->filename = CurText();
  2464. while( (tok = NextTok()) != T_RIGHT )
  2465. {
  2466. if( tok != T_LEFT )
  2467. Expecting( T_LEFT );
  2468. tok = NextTok();
  2469. switch( tok )
  2470. {
  2471. case T_created_time:
  2472. readTIME( &growth->time_stamp );
  2473. NeedRIGHT();
  2474. break;
  2475. case T_comment:
  2476. NeedSYMBOL();
  2477. growth->comment = CurText();
  2478. NeedRIGHT();
  2479. break;
  2480. default:
  2481. Unexpected( CurText() );
  2482. }
  2483. }
  2484. }
  2485. void SPECCTRA_DB::doHISTORY( HISTORY* growth ) throw( IO_ERROR )
  2486. {
  2487. T tok;
  2488. /* <history_descriptor >::=
  2489. (history [{<ancestor_file_descriptor> }] <self_descriptor> )
  2490. */
  2491. while( (tok = NextTok()) != T_RIGHT )
  2492. {
  2493. if( tok != T_LEFT )
  2494. Expecting( T_LEFT );
  2495. tok = NextTok();
  2496. switch( tok )
  2497. {
  2498. case T_ancestor:
  2499. ANCESTOR* ancestor;
  2500. ancestor = new ANCESTOR( growth );
  2501. growth->ancestors.push_back( ancestor );
  2502. doANCESTOR( ancestor );
  2503. break;
  2504. case T_self:
  2505. while( (tok = NextTok()) != T_RIGHT )
  2506. {
  2507. if( tok != T_LEFT )
  2508. Expecting( T_LEFT );
  2509. tok = NextTok();
  2510. switch( tok )
  2511. {
  2512. case T_created_time:
  2513. readTIME( &growth->time_stamp );
  2514. NeedRIGHT();
  2515. break;
  2516. case T_comment:
  2517. NeedSYMBOL();
  2518. growth->comments.push_back( CurText() );
  2519. NeedRIGHT();
  2520. break;
  2521. default:
  2522. Unexpected( CurText() );
  2523. }
  2524. }
  2525. break;
  2526. default:
  2527. Unexpected( CurText() );
  2528. }
  2529. }
  2530. }
  2531. void SPECCTRA_DB::doSESSION( SESSION* growth ) throw( IO_ERROR )
  2532. {
  2533. T tok;
  2534. /* <session_file_descriptor >::=
  2535. (session <session_id >
  2536. (base_design <path/filename >)
  2537. [<history_descriptor> ]
  2538. [<session_structure_descriptor> ]
  2539. [<placement_descriptor> ]
  2540. [<floor_plan_descriptor> ]
  2541. [<net_pin_changes_descriptor> ]
  2542. [<was_is_descriptor> ]
  2543. <swap_history_descriptor> ]
  2544. [<route_descriptor> ]
  2545. )
  2546. */
  2547. NeedSYMBOL();
  2548. growth->session_id = CurText();
  2549. while( (tok = NextTok()) != T_RIGHT )
  2550. {
  2551. if( tok != T_LEFT )
  2552. Expecting( T_LEFT );
  2553. tok = NextTok();
  2554. switch( tok )
  2555. {
  2556. case T_base_design:
  2557. NeedSYMBOL();
  2558. growth->base_design = CurText();
  2559. NeedRIGHT();
  2560. break;
  2561. case T_history:
  2562. if( growth->history )
  2563. Unexpected( tok );
  2564. growth->history = new HISTORY( growth );
  2565. doHISTORY( growth->history );
  2566. break;
  2567. case T_structure:
  2568. if( growth->structure )
  2569. Unexpected( tok );
  2570. growth->structure = new STRUCTURE( growth );
  2571. doSTRUCTURE( growth->structure );
  2572. break;
  2573. case T_placement:
  2574. if( growth->placement )
  2575. Unexpected( tok );
  2576. growth->placement = new PLACEMENT( growth );
  2577. doPLACEMENT( growth->placement );
  2578. break;
  2579. case T_was_is:
  2580. if( growth->was_is )
  2581. Unexpected( tok );
  2582. growth->was_is = new WAS_IS( growth );
  2583. doWAS_IS( growth->was_is );
  2584. break;
  2585. case T_routes:
  2586. if( growth->route )
  2587. Unexpected( tok );
  2588. growth->route = new ROUTE( growth );
  2589. doROUTE( growth->route );
  2590. break;
  2591. default:
  2592. Unexpected( CurText() );
  2593. }
  2594. }
  2595. }
  2596. void SPECCTRA_DB::doWAS_IS( WAS_IS* growth ) throw( IO_ERROR )
  2597. {
  2598. T tok;
  2599. PIN_PAIR empty( growth );
  2600. PIN_PAIR* pin_pair;
  2601. /* <was_is_descriptor >::=
  2602. (was_is {(pins <pin_reference> <pin_reference> )})
  2603. */
  2604. // none of the pins is ok too
  2605. while( (tok = NextTok()) != T_RIGHT )
  2606. {
  2607. if( tok != T_LEFT )
  2608. Expecting( T_LEFT );
  2609. tok = NextTok();
  2610. switch( tok )
  2611. {
  2612. case T_pins:
  2613. // copy the empty one, then fill its copy later thru pin_pair.
  2614. growth->pin_pairs.push_back( empty );
  2615. pin_pair= &growth->pin_pairs.back();
  2616. NeedSYMBOL(); // readCOMPnPIN() expects 1st token to have been read
  2617. readCOMPnPIN( &pin_pair->was.component_id, &pin_pair->was.pin_id );
  2618. NeedSYMBOL(); // readCOMPnPIN() expects 1st token to have been read
  2619. readCOMPnPIN( &pin_pair->is.component_id, &pin_pair->is.pin_id );
  2620. NeedRIGHT();
  2621. break;
  2622. default:
  2623. Unexpected( CurText() );
  2624. }
  2625. }
  2626. }
  2627. void SPECCTRA_DB::doROUTE( ROUTE* growth ) throw( IO_ERROR )
  2628. {
  2629. T tok;
  2630. /* <route_descriptor >::=
  2631. (routes
  2632. <resolution_descriptor>
  2633. <parser_descriptor>
  2634. <structure_out_descriptor>
  2635. <library_out_descriptor>
  2636. <network_out_descriptor>
  2637. <test_points_descriptor>
  2638. )
  2639. */
  2640. while( (tok = NextTok()) != T_RIGHT )
  2641. {
  2642. if( tok != T_LEFT )
  2643. Expecting( T_LEFT );
  2644. tok = NextTok();
  2645. switch( tok )
  2646. {
  2647. case T_resolution:
  2648. if( growth->resolution )
  2649. Unexpected( tok );
  2650. growth->resolution = new UNIT_RES( growth, tok );
  2651. doRESOLUTION( growth->resolution );
  2652. break;
  2653. case T_parser:
  2654. if( growth->parser )
  2655. {
  2656. #if 0 // Electra 2.9.1 emits two (parser ) elements in a row.
  2657. // Work around their bug for now.
  2658. Unexpected( tok );
  2659. #else
  2660. delete growth->parser;
  2661. #endif
  2662. }
  2663. growth->parser = new PARSER( growth );
  2664. doPARSER( growth->parser );
  2665. break;
  2666. case T_structure_out:
  2667. if( growth->structure_out )
  2668. Unexpected( tok );
  2669. growth->structure_out = new STRUCTURE_OUT( growth );
  2670. doSTRUCTURE_OUT( growth->structure_out );
  2671. break;
  2672. case T_library_out:
  2673. if( growth->library )
  2674. Unexpected( tok );
  2675. growth->library = new LIBRARY( growth, tok );
  2676. doLIBRARY( growth->library );
  2677. break;
  2678. case T_network_out:
  2679. while( (tok = NextTok()) != T_RIGHT )
  2680. {
  2681. if( tok != T_LEFT )
  2682. Expecting( T_LEFT );
  2683. tok = NextTok();
  2684. if( tok != T_net ) // it is class NET_OUT, but token T_net
  2685. Unexpected( CurText() );
  2686. NET_OUT* net_out;
  2687. net_out = new NET_OUT( growth );
  2688. growth->net_outs.push_back( net_out );
  2689. doNET_OUT( net_out );
  2690. }
  2691. break;
  2692. default:
  2693. Unexpected( CurText() );
  2694. }
  2695. }
  2696. }
  2697. void SPECCTRA_DB::doNET_OUT( NET_OUT* growth ) throw( IO_ERROR )
  2698. {
  2699. T tok;
  2700. /* <net_out_descriptor >::=
  2701. (net <net_id >
  2702. [(net_number <integer >)]
  2703. [<rule_descriptor> ]
  2704. {[<wire_shape_descriptor> | <wire_guide_descriptor> |
  2705. <wire_via_descriptor> | <bond_shape_descriptor> ]}
  2706. {[<supply_pin_descriptor> ]}
  2707. )
  2708. */
  2709. NeedSYMBOLorNUMBER();
  2710. growth->net_id = CurText();
  2711. while( (tok = NextTok()) != T_RIGHT )
  2712. {
  2713. if( tok != T_LEFT )
  2714. Expecting( T_LEFT );
  2715. tok = NextTok();
  2716. switch( tok )
  2717. {
  2718. case T_net_number:
  2719. tok = NextTok();
  2720. if( tok!= T_NUMBER )
  2721. Expecting( T_NUMBER );
  2722. growth->net_number = atoi( CurText() );
  2723. NeedRIGHT();
  2724. break;
  2725. case T_rule:
  2726. if( growth->rules )
  2727. Unexpected( tok );
  2728. growth->rules = new RULE( growth, tok );
  2729. doRULE( growth->rules );
  2730. break;
  2731. case T_wire:
  2732. WIRE* wire;
  2733. wire = new WIRE( growth );
  2734. growth->wires.push_back( wire );
  2735. doWIRE( wire );
  2736. break;
  2737. case T_via:
  2738. WIRE_VIA* wire_via;
  2739. wire_via = new WIRE_VIA( growth );
  2740. growth->wire_vias.push_back( wire_via );
  2741. doWIRE_VIA( wire_via );
  2742. break;
  2743. case T_supply_pin:
  2744. SUPPLY_PIN* supply_pin;
  2745. supply_pin = new SUPPLY_PIN( growth );
  2746. growth->supply_pins.push_back( supply_pin );
  2747. doSUPPLY_PIN( supply_pin );
  2748. break;
  2749. default:
  2750. Unexpected( CurText() );
  2751. }
  2752. }
  2753. }
  2754. void SPECCTRA_DB::doSUPPLY_PIN( SUPPLY_PIN* growth ) throw( IO_ERROR )
  2755. {
  2756. T tok;
  2757. PIN_REF empty(growth);
  2758. /* <supply_pin_descriptor >::=
  2759. (supply_pin {<pin_reference> } [(net <net_id >)])
  2760. */
  2761. NeedSYMBOL();
  2762. growth->net_id = CurText();
  2763. while( (tok = NextTok()) != T_RIGHT )
  2764. {
  2765. if( IsSymbol(tok) )
  2766. {
  2767. growth->pin_refs.push_back( empty );
  2768. PIN_REF* pin_ref = &growth->pin_refs.back();
  2769. readCOMPnPIN( &pin_ref->component_id, &pin_ref->pin_id );
  2770. }
  2771. else if( tok == T_LEFT )
  2772. {
  2773. tok = NextTok();
  2774. if( tok != T_net )
  2775. Expecting( T_net );
  2776. growth->net_id = CurText();
  2777. NeedRIGHT();
  2778. }
  2779. else
  2780. Unexpected( CurText() );
  2781. }
  2782. }
  2783. void SPECCTRA_DB::ExportPCB( wxString filename, bool aNameChange ) throw( IO_ERROR )
  2784. {
  2785. if( pcb )
  2786. {
  2787. FILE_OUTPUTFORMATTER formatter( filename, wxT( "wt" ), quote_char[0] );
  2788. if( aNameChange )
  2789. pcb->pcbname = TO_UTF8( filename );
  2790. pcb->Format( &formatter, 0 );
  2791. }
  2792. }
  2793. void SPECCTRA_DB::ExportSESSION( wxString filename )
  2794. {
  2795. if( session )
  2796. {
  2797. FILE_OUTPUTFORMATTER formatter( filename, wxT( "wt" ), quote_char[0] );
  2798. session->Format( &formatter, 0 );
  2799. }
  2800. }
  2801. PCB* SPECCTRA_DB::MakePCB()
  2802. {
  2803. PCB* pcb = new PCB();
  2804. pcb->parser = new PARSER( pcb );
  2805. pcb->resolution = new UNIT_RES( pcb, T_resolution );
  2806. pcb->unit = new UNIT_RES( pcb, T_unit );
  2807. pcb->structure = new STRUCTURE( pcb );
  2808. pcb->structure->boundary = new BOUNDARY( pcb->structure );
  2809. pcb->structure->via = new VIA( pcb->structure );
  2810. pcb->structure->rules = new RULE( pcb->structure, T_rule );
  2811. pcb->placement = new PLACEMENT( pcb );
  2812. pcb->library = new LIBRARY( pcb );
  2813. pcb->network = new NETWORK( pcb );
  2814. pcb->wiring = new WIRING( pcb );
  2815. return pcb;
  2816. }
  2817. //-----<ELEM>---------------------------------------------------------------
  2818. ELEM::ELEM( T aType, ELEM* aParent ) :
  2819. type( aType ),
  2820. parent( aParent )
  2821. {
  2822. }
  2823. ELEM::~ELEM()
  2824. {
  2825. }
  2826. const char* ELEM::Name() const
  2827. {
  2828. return SPECCTRA_DB::TokenName( type );
  2829. }
  2830. UNIT_RES* ELEM::GetUnits() const
  2831. {
  2832. if( parent )
  2833. return parent->GetUnits();
  2834. return &UNIT_RES::Default;
  2835. }
  2836. void ELEM::Format( OUTPUTFORMATTER* out, int nestLevel ) throw( IO_ERROR )
  2837. {
  2838. out->Print( nestLevel, "(%s\n", Name() );
  2839. FormatContents( out, nestLevel+1 );
  2840. out->Print( nestLevel, ")\n" );
  2841. }
  2842. void ELEM_HOLDER::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IO_ERROR )
  2843. {
  2844. for( int i=0; i<Length(); ++i )
  2845. {
  2846. At(i)->Format( out, nestLevel );
  2847. }
  2848. }
  2849. int ELEM_HOLDER::FindElem( T aType, int instanceNum )
  2850. {
  2851. int repeats=0;
  2852. for( unsigned i=0; i<kids.size(); ++i )
  2853. {
  2854. if( kids[i].Type() == aType )
  2855. {
  2856. if( repeats == instanceNum )
  2857. return i;
  2858. ++repeats;
  2859. }
  2860. }
  2861. return -1;
  2862. }
  2863. // a reasonably small memory price to pay for improved performance
  2864. STRING_FORMATTER ELEM::sf;
  2865. //-----<UNIT_RES>---------------------------------------------------------
  2866. UNIT_RES UNIT_RES::Default( NULL, T_resolution );
  2867. //-----<PADSTACK>---------------------------------------------------------
  2868. int PADSTACK::Compare( PADSTACK* lhs, PADSTACK* rhs )
  2869. {
  2870. // printf( "PADSTACK::Compare( %p, %p)\n", lhs, rhs );
  2871. if( !lhs->hash.size() )
  2872. lhs->hash = lhs->makeHash();
  2873. if( !rhs->hash.size() )
  2874. rhs->hash = rhs->makeHash();
  2875. int result = lhs->hash.compare( rhs->hash );
  2876. if( result )
  2877. return result;
  2878. // Via names hold the drill diameters, so we have to include those to discern
  2879. // between two vias with same copper size but with different drill sizes.
  2880. result = lhs->padstack_id.compare( rhs->padstack_id );
  2881. return result;
  2882. }
  2883. //-----<IMAGE>------------------------------------------------------------
  2884. int IMAGE::Compare( IMAGE* lhs, IMAGE* rhs )
  2885. {
  2886. if( !lhs->hash.size() )
  2887. lhs->hash = lhs->makeHash();
  2888. if( !rhs->hash.size() )
  2889. rhs->hash = rhs->makeHash();
  2890. int result = lhs->hash.compare( rhs->hash );
  2891. // printf("\"%s\" \"%s\" ret=%d\n", lhs->hash.c_str(), rhs->hash.c_str(), result );
  2892. return result;
  2893. }
  2894. //-----<COMPONENT>--------------------------------------------------------
  2895. /*
  2896. int COMPONENT::Compare( COMPONENT* lhs, COMPONENT* rhs )
  2897. {
  2898. if( !lhs->hash.size() )
  2899. lhs->hash = lhs->makeHash();
  2900. if( !rhs->hash.size() )
  2901. rhs->hash = rhs->makeHash();
  2902. int result = lhs->hash.compare( rhs->hash );
  2903. return result;
  2904. }
  2905. */
  2906. //-----<PARSER>-----------------------------------------------------------
  2907. PARSER::PARSER( ELEM* aParent ) :
  2908. ELEM( T_parser, aParent )
  2909. {
  2910. string_quote = '"';
  2911. space_in_quoted_tokens = false;
  2912. case_sensitive = false;
  2913. wires_include_testpoint = false;
  2914. routes_include_testpoint = false;
  2915. routes_include_guides = false;
  2916. routes_include_image_conductor = false;
  2917. via_rotate_first = true;
  2918. generated_by_freeroute = false;
  2919. host_cad = "KiCad's Pcbnew";
  2920. wxString msg = GetBuildVersion();
  2921. host_version = TO_UTF8(msg);
  2922. }
  2923. void PARSER::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IO_ERROR )
  2924. {
  2925. out->Print( nestLevel, "(string_quote %c)\n", string_quote );
  2926. out->Print( nestLevel, "(space_in_quoted_tokens %s)\n", space_in_quoted_tokens ? "on" : "off" );
  2927. out->Print( nestLevel, "(host_cad \"%s\")\n", host_cad.c_str() );
  2928. out->Print( nestLevel, "(host_version \"%s\")\n", host_version.c_str() );
  2929. for( STRINGS::iterator i=constants.begin(); i!=constants.end(); )
  2930. {
  2931. const std::string& s1 = *i++;
  2932. const std::string& s2 = *i++;
  2933. const char* q1 = out->GetQuoteChar( s1.c_str() );
  2934. const char* q2 = out->GetQuoteChar( s2.c_str() );
  2935. out->Print( nestLevel, "(constant %s%s%s %s%s%s)\n",
  2936. q1, s1.c_str(), q1,
  2937. q2, s2.c_str(), q2 );
  2938. }
  2939. if( routes_include_testpoint || routes_include_guides || routes_include_image_conductor )
  2940. out->Print( nestLevel, "(routes_include%s%s%s)\n",
  2941. routes_include_testpoint ? " testpoint" : "",
  2942. routes_include_guides ? " guides" : "",
  2943. routes_include_image_conductor ? " image_conductor" : "");
  2944. if( wires_include_testpoint )
  2945. out->Print( nestLevel, "(wires_include testpoint)\n" );
  2946. if( !via_rotate_first )
  2947. out->Print( nestLevel, "(via_rotate_first off)\n" );
  2948. if( case_sensitive )
  2949. out->Print( nestLevel, "(case_sensitive %s)\n", case_sensitive ? "on" : "off" );
  2950. }
  2951. void PLACE::Format( OUTPUTFORMATTER* out, int nestLevel ) throw( IO_ERROR )
  2952. {
  2953. bool useMultiLine;
  2954. const char* quote = out->GetQuoteChar( component_id.c_str() );
  2955. if( place_rules || properties.size() || rules || region )
  2956. {
  2957. useMultiLine = true;
  2958. out->Print( nestLevel, "(%s %s%s%s\n", Name(),
  2959. quote, component_id.c_str(), quote );
  2960. out->Print( nestLevel+1, "%s", "" );
  2961. }
  2962. else
  2963. {
  2964. useMultiLine = false;
  2965. out->Print( nestLevel, "(%s %s%s%s", Name(),
  2966. quote, component_id.c_str(), quote );
  2967. }
  2968. if( hasVertex )
  2969. {
  2970. out->Print( 0, " %.6g %.6g", vertex.x, vertex.y );
  2971. out->Print( 0, " %s", GetTokenText( side ) );
  2972. out->Print( 0, " %.6g", rotation );
  2973. }
  2974. const char* space = " "; // one space, as c string.
  2975. if( mirror != T_NONE )
  2976. {
  2977. out->Print( 0, "%s(mirror %s)", space, GetTokenText( mirror ) );
  2978. space = "";
  2979. }
  2980. if( status != T_NONE )
  2981. {
  2982. out->Print( 0, "%s(status %s)", space, GetTokenText( status ) );
  2983. space = "";
  2984. }
  2985. if( logical_part.size() )
  2986. {
  2987. quote = out->GetQuoteChar( logical_part.c_str() );
  2988. out->Print( 0, "%s(logical_part %s%s%s)", space,
  2989. quote, logical_part.c_str(), quote );
  2990. space = "";
  2991. }
  2992. if( useMultiLine )
  2993. {
  2994. out->Print( 0, "\n" );
  2995. if( place_rules )
  2996. {
  2997. place_rules->Format( out, nestLevel+1 );
  2998. }
  2999. if( properties.size() )
  3000. {
  3001. out->Print( nestLevel+1, "(property \n" );
  3002. for( PROPERTIES::const_iterator i = properties.begin();
  3003. i != properties.end(); ++i )
  3004. {
  3005. i->Format( out, nestLevel+2 );
  3006. }
  3007. out->Print( nestLevel+1, ")\n" );
  3008. }
  3009. if( lock_type != T_NONE )
  3010. out->Print( nestLevel+1, "(lock_type %s)\n", GetTokenText(lock_type) );
  3011. if( rules )
  3012. rules->Format( out, nestLevel+1 );
  3013. if( region )
  3014. region->Format( out, nestLevel+1 );
  3015. if( part_number.size() )
  3016. {
  3017. const char* quote = out->GetQuoteChar( part_number.c_str() );
  3018. out->Print( nestLevel+1, "(PN %s%s%s)\n",
  3019. quote, part_number.c_str(), quote );
  3020. }
  3021. }
  3022. else
  3023. {
  3024. if( lock_type != T_NONE )
  3025. {
  3026. out->Print( 0, "%s(lock_type %s)", space, GetTokenText(lock_type) );
  3027. space = "";
  3028. }
  3029. if( part_number.size() )
  3030. {
  3031. const char* quote = out->GetQuoteChar( part_number.c_str() );
  3032. out->Print( 0, "%s(PN %s%s%s)", space,
  3033. quote, part_number.c_str(), quote );
  3034. }
  3035. }
  3036. out->Print( 0, ")\n" );
  3037. }
  3038. } // namespace DSN
  3039. //EOF