Commit d597dfc9 authored by dickelbeck's avatar dickelbeck

more specctra dsn work

parent e6c93885
...@@ -60,8 +60,11 @@ ...@@ -60,8 +60,11 @@
namespace DSN { namespace DSN {
#define NESTWIDTH 4 ///< how many spaces per nestLevel
class SPECCTRA_DB; class SPECCTRA_DB;
class PCB; class PCB;
...@@ -91,9 +94,10 @@ public: ...@@ -91,9 +94,10 @@ public:
* @param fmt A printf() style format string. * @param fmt A printf() style format string.
* @param ... a variable list of parameters that will get blended into * @param ... a variable list of parameters that will get blended into
* the output under control of the format string. * the output under control of the format string.
* @throw IOError if there is a problem outputting, such as a full disk. * @return int - the number of characters output.
* @throw IOError, if there is a problem outputting, such as a full disk.
*/ */
virtual void PRINTF_FUNC Print( int nestLevel, const char* fmt, ... ) throw( IOError ) = 0; virtual int PRINTF_FUNC Print( int nestLevel, const char* fmt, ... ) throw( IOError ) = 0;
/** /**
* Function GetQuoteChar * Function GetQuoteChar
...@@ -161,21 +165,15 @@ typedef std::vector<PROPERTY> PROPERTIES; ...@@ -161,21 +165,15 @@ typedef std::vector<PROPERTY> PROPERTIES;
/** /**
* Class ELEM * Class ELEM
* is a holder for any DSN element. It can contain other * is a base class for any DSN element class.
* elements, including elements derived from this class. * See class ELEM_HOLDER also.
*/ */
class ELEM class ELEM
{ {
protected: protected:
DSN_T type; DSN_T type;
ELEM* parent; ELEM* parent;
// see http://www.boost.org/libs/ptr_container/doc/ptr_sequence_adapter.html
typedef boost::ptr_vector<ELEM> ELEM_ARRAY;
ELEM_ARRAY kids; ///< ELEM pointers
public: public:
ELEM( DSN_T aType, ELEM* aParent = 0 ); ELEM( DSN_T aType, ELEM* aParent = 0 );
...@@ -220,6 +218,32 @@ public: ...@@ -220,6 +218,32 @@ public:
* @param nestLevel A multiple of the number of spaces to preceed the output with. * @param nestLevel A multiple of the number of spaces to preceed the output with.
* @throw IOError if a system error writing the output, such as a full disk. * @throw IOError if a system error writing the output, such as a full disk.
*/ */
virtual void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError )
{
// overridden in ELEM_HOLDER
}
};
/**
* Class ELEM_HOLDER
* is a holder for any DSN class. It can contain other
* class instances, including classes derived from this class.
*/
class ELEM_HOLDER : public ELEM
{
// see http://www.boost.org/libs/ptr_container/doc/ptr_sequence_adapter.html
typedef boost::ptr_vector<ELEM> ELEM_ARRAY;
ELEM_ARRAY kids; ///< ELEM pointers
public:
ELEM_HOLDER( DSN_T aType, ELEM* aParent = 0 ) :
ELEM( aType, aParent )
{
}
virtual void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError ); virtual void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError );
...@@ -488,16 +512,21 @@ public: ...@@ -488,16 +512,21 @@ public:
delete rule; delete rule;
} }
void FormatContent( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError ) void Format( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError )
{ {
out->Print( nestLevel, "(%s", LEXER::GetTokenText( Type() ) );
for( STRINGS::const_iterator i=layer_ids.begin(); i!=layer_ids.end(); ++i ) for( STRINGS::const_iterator i=layer_ids.begin(); i!=layer_ids.end(); ++i )
{ {
const char* quote = out->GetQuoteChar( i->c_str() ); const char* quote = out->GetQuoteChar( i->c_str() );
out->Print( nestLevel, "%s%s%s\n", quote, i->c_str(), quote ); out->Print( 0, " %s%s%s", quote, i->c_str(), quote );
} }
out->Print( 0 , "\n" );
if( rule ) if( rule )
rule->Format( out, nestLevel ); rule->Format( out, nestLevel+1 );
out->Print( nestLevel, ")\n" );
} }
}; };
...@@ -867,7 +896,7 @@ public: ...@@ -867,7 +896,7 @@ public:
}; };
class CLASS_CLASS : public ELEM class CLASS_CLASS : public ELEM_HOLDER
{ {
friend class SPECCTRA_DB; friend class SPECCTRA_DB;
...@@ -884,7 +913,7 @@ public: ...@@ -884,7 +913,7 @@ public:
* @param aType May be either T_class_class or T_region_class_class * @param aType May be either T_class_class or T_region_class_class
*/ */
CLASS_CLASS( ELEM* aParent, DSN_T aType ) : CLASS_CLASS( ELEM* aParent, DSN_T aType ) :
ELEM( aType, aParent ) ELEM_HOLDER( aType, aParent )
{ {
classes = 0; classes = 0;
} }
...@@ -900,23 +929,21 @@ public: ...@@ -900,23 +929,21 @@ public:
classes->Format( out, nestLevel ); classes->Format( out, nestLevel );
// format the kids // format the kids
ELEM::FormatContents( out, nestLevel ); ELEM_HOLDER::FormatContents( out, nestLevel );
} }
}; };
class CONTROL : public ELEM class CONTROL : public ELEM_HOLDER
{ {
friend class SPECCTRA_DB; friend class SPECCTRA_DB;
bool via_at_smd; bool via_at_smd;
bool via_at_smd_grid_on; bool via_at_smd_grid_on;
public: public:
CONTROL( ELEM* aParent ) : CONTROL( ELEM* aParent ) :
ELEM( T_control, aParent ) ELEM_HOLDER( T_control, aParent )
{ {
via_at_smd = false; via_at_smd = false;
via_at_smd_grid_on = false; via_at_smd_grid_on = false;
...@@ -1158,7 +1185,7 @@ public: ...@@ -1158,7 +1185,7 @@ public:
}; };
class REGION : public ELEM class REGION : public ELEM_HOLDER
{ {
friend class SPECCTRA_DB; friend class SPECCTRA_DB;
...@@ -1177,7 +1204,7 @@ class REGION : public ELEM ...@@ -1177,7 +1204,7 @@ class REGION : public ELEM
public: public:
REGION( ELEM* aParent ) : REGION( ELEM* aParent ) :
ELEM( T_region, aParent ) ELEM_HOLDER( T_region, aParent )
{ {
rectangle = 0; rectangle = 0;
polygon = 0; polygon = 0;
...@@ -1205,7 +1232,7 @@ public: ...@@ -1205,7 +1232,7 @@ public:
if( polygon ) if( polygon )
polygon->Format( out, nestLevel ); polygon->Format( out, nestLevel );
ELEM::FormatContents( out, nestLevel ); ELEM_HOLDER::FormatContents( out, nestLevel );
if( rules ) if( rules )
rules->Format( out, nestLevel ); rules->Format( out, nestLevel );
...@@ -1264,7 +1291,7 @@ public: ...@@ -1264,7 +1291,7 @@ public:
}; };
class STRUCTURE : public ELEM class STRUCTURE : public ELEM_HOLDER
{ {
friend class SPECCTRA_DB; friend class SPECCTRA_DB;
...@@ -1298,7 +1325,7 @@ class STRUCTURE : public ELEM ...@@ -1298,7 +1325,7 @@ class STRUCTURE : public ELEM
public: public:
STRUCTURE( ELEM* aParent ) : STRUCTURE( ELEM* aParent ) :
ELEM( T_structure, aParent ) ELEM_HOLDER( T_structure, aParent )
{ {
unit = 0; unit = 0;
layer_noise_weight = 0; layer_noise_weight = 0;
...@@ -1632,7 +1659,7 @@ public: ...@@ -1632,7 +1659,7 @@ public:
}; };
class IMAGE : public ELEM class IMAGE : public ELEM_HOLDER
{ {
friend class SPECCTRA_DB; friend class SPECCTRA_DB;
...@@ -1654,7 +1681,7 @@ class IMAGE : public ELEM ...@@ -1654,7 +1681,7 @@ class IMAGE : public ELEM
public: public:
IMAGE( ELEM* aParent ) : IMAGE( ELEM* aParent ) :
ELEM( T_image, aParent ) ELEM_HOLDER( T_image, aParent )
{ {
side = T_both; side = T_both;
unit = 0; unit = 0;
...@@ -1685,7 +1712,7 @@ public: ...@@ -1685,7 +1712,7 @@ public:
unit->Format( out, nestLevel+1 ); unit->Format( out, nestLevel+1 );
// format the kids, which in this class are the shapes // format the kids, which in this class are the shapes
ELEM::FormatContents( out, nestLevel+1 ); ELEM_HOLDER::FormatContents( out, nestLevel+1 );
for( PINS::iterator i=pins.begin(); i!=pins.end(); ++i ) for( PINS::iterator i=pins.begin(); i!=pins.end(); ++i )
i->Format( out, nestLevel+1 ); i->Format( out, nestLevel+1 );
...@@ -1710,7 +1737,7 @@ public: ...@@ -1710,7 +1737,7 @@ public:
}; };
class PADSTACK : public ELEM class PADSTACK : public ELEM_HOLDER
{ {
friend class SPECCTRA_DB; friend class SPECCTRA_DB;
...@@ -1729,7 +1756,7 @@ class PADSTACK : public ELEM ...@@ -1729,7 +1756,7 @@ class PADSTACK : public ELEM
public: public:
PADSTACK( ELEM* aParent ) : PADSTACK( ELEM* aParent ) :
ELEM( T_padstack, aParent ) ELEM_HOLDER( T_padstack, aParent )
{ {
unit = 0; unit = 0;
rotate = T_on; rotate = T_on;
...@@ -1754,7 +1781,7 @@ public: ...@@ -1754,7 +1781,7 @@ public:
unit->Format( out, nestLevel+1 ); unit->Format( out, nestLevel+1 );
// format the kids, which in this class are the shapes // format the kids, which in this class are the shapes
ELEM::FormatContents( out, nestLevel+1 ); ELEM_HOLDER::FormatContents( out, nestLevel+1 );
out->Print( nestLevel+1, "%s", "" ); out->Print( nestLevel+1, "%s", "" );
...@@ -1930,6 +1957,136 @@ public: ...@@ -1930,6 +1957,136 @@ public:
}; };
class FROMTO : public ELEM
{
friend class SPECCTRA_DB;
public:
FROMTO( ELEM* aParent ) :
ELEM( T_fromto, aParent )
{
}
};
class COMP_ORDER : public ELEM
{
friend class SPECCTRA_DB;
public:
COMP_ORDER( ELEM* aParent ) :
ELEM( T_comp_order, aParent )
{
}
};
class TOPOLOGY : public ELEM
{
friend class SPECCTRA_DB;
typedef boost::ptr_vector<FROMTO> FROMTOS;
FROMTOS fromtos;
typedef boost::ptr_vector<COMP_ORDER> COMP_ORDERS;
COMP_ORDERS comp_orders;
public:
TOPOLOGY( ELEM* aParent ) :
ELEM( T_topology, aParent )
{
}
void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError )
{
for( FROMTOS::iterator i=fromtos.begin(); i!=fromtos.end(); ++i )
i->Format( out, nestLevel );
for( COMP_ORDERS::iterator i=comp_orders.begin(); i!=comp_orders.end(); ++i )
i->Format( out, nestLevel );
}
};
class CLASS : public ELEM
{
friend class SPECCTRA_DB;
std::string class_id;
STRINGS net_ids;
/// <circuit_descriptors>
STRINGS circuit;
RULE* rules;
typedef boost::ptr_vector<LAYER_RULE> LAYER_RULES;
LAYER_RULES layer_rules;
TOPOLOGY* topology;
public:
CLASS( ELEM* aParent ) :
ELEM( T_class, aParent )
{
rules = 0;
topology = 0;
}
~CLASS()
{
delete rules;
delete topology;
}
void Format( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError )
{
const char* quote = out->GetQuoteChar( class_id.c_str() );
out->Print( nestLevel, "(%s %s%s%s", LEXER::GetTokenText( Type() ),
quote, class_id.c_str(), quote );
const int NETGAP = 2;
const int RIGHTMARGIN = 92;
int perRow=RIGHTMARGIN;
for( STRINGS::iterator i=net_ids.begin(); i!=net_ids.end(); ++i )
{
quote = out->GetQuoteChar( i->c_str() );
int slength = strlen( i->c_str() );
if( *quote!='\0' )
slength += 2;
if( perRow + slength + NETGAP > RIGHTMARGIN )
{
out->Print( 0, "\n" );
perRow = 0;
perRow += out->Print( nestLevel+1, "%s%s%s",
quote, i->c_str(), quote );
}
else
{
perRow += out->Print( 0, "%*c%s%s%s", NETGAP, ' ',
quote, i->c_str(), quote );
}
}
out->Print( 0, "\n" );
for( STRINGS::iterator i=circuit.begin(); i!=circuit.end(); ++i )
out->Print( nestLevel+1, "%s\n", i->c_str() );
for( LAYER_RULES::iterator i=layer_rules.begin(); i!=layer_rules.end(); ++i )
i->Format( out, nestLevel+1 );
if( topology )
topology->Format( out, nestLevel+1 );
out->Print( nestLevel, ")\n" );
}
};
class NETWORK : public ELEM class NETWORK : public ELEM
{ {
friend class SPECCTRA_DB; friend class SPECCTRA_DB;
...@@ -1937,6 +2094,10 @@ class NETWORK : public ELEM ...@@ -1937,6 +2094,10 @@ class NETWORK : public ELEM
typedef boost::ptr_vector<NET> NETS; typedef boost::ptr_vector<NET> NETS;
NETS nets; NETS nets;
typedef boost::ptr_vector<CLASS> CLASSLIST;
CLASSLIST classes;
public: public:
NETWORK( ELEM* aParent ) : NETWORK( ELEM* aParent ) :
...@@ -1948,6 +2109,9 @@ public: ...@@ -1948,6 +2109,9 @@ public:
{ {
for( NETS::iterator i=nets.begin(); i!=nets.end(); ++i ) for( NETS::iterator i=nets.begin(); i!=nets.end(); ++i )
i->Format( out, nestLevel ); i->Format( out, nestLevel );
for( CLASSLIST::iterator i=classes.begin(); i!=classes.end(); ++i )
i->Format( out, nestLevel );
} }
}; };
...@@ -2066,6 +2230,31 @@ class SPECCTRA_DB : public OUTPUTFORMATTER ...@@ -2066,6 +2230,31 @@ class SPECCTRA_DB : public OUTPUTFORMATTER
} }
/**
* Function needLEFT
* calls nextTok() and then verifies that the token read in is a T_LEFT.
* If it is not, an IOError is thrown.
* @throw IOError, if the next token is not a T_LEFT
*/
void needLEFT() throw( IOError );
/**
* Function needRIGHT
* calls nextTok() and then verifies that the token read in is a T_RIGHT.
* If it is not, an IOError is thrown.
* @throw IOError, if the next token is not a T_RIGHT
*/
void needRIGHT() throw( IOError );
/**
* Function needSYMBOL
* calls nextTok() and then verifies that the token read in
* satisfies bool isSymbol().
* If not, an IOError is thrown.
* @throw IOError, if the next token does not satisfy isSymbol()
*/
void needSYMBOL() throw( IOError );
/** /**
* Function expecting * Function expecting
* throws an IOError exception with an input file specific error message. * throws an IOError exception with an input file specific error message.
...@@ -2113,6 +2302,11 @@ class SPECCTRA_DB : public OUTPUTFORMATTER ...@@ -2113,6 +2302,11 @@ class SPECCTRA_DB : public OUTPUTFORMATTER
void doPIN( PIN* growth ) throw( IOError ); void doPIN( PIN* growth ) throw( IOError );
void doNET( NET* growth ) throw( IOError ); void doNET( NET* growth ) throw( IOError );
void doNETWORK( NETWORK* growth ) throw( IOError ); void doNETWORK( NETWORK* growth ) throw( IOError );
void doCLASS( CLASS* growth ) throw( IOError );
void doTOPOLOGY( TOPOLOGY* growth ) throw( IOError );
void doFROMTO( FROMTO* growth ) throw( IOError );
void doCOMP_ORDER( COMP_ORDER* growth ) throw( IOError );
public: public:
...@@ -2135,7 +2329,7 @@ public: ...@@ -2135,7 +2329,7 @@ public:
//-----<OUTPUTFORMATTER>------------------------------------------------- //-----<OUTPUTFORMATTER>-------------------------------------------------
void PRINTF_FUNC Print( int nestLevel, const char* fmt, ... ) throw( IOError ); int PRINTF_FUNC Print( int nestLevel, const char* fmt, ... ) throw( IOError );
const char* GetQuoteChar( const char* wrapee ); const char* GetQuoteChar( const char* wrapee );
//-----</OUTPUTFORMATTER>------------------------------------------------ //-----</OUTPUTFORMATTER>------------------------------------------------
...@@ -2178,7 +2372,6 @@ public: ...@@ -2178,7 +2372,6 @@ public:
}; };
//-----<SPECCTRA_DB>------------------------------------------------- //-----<SPECCTRA_DB>-------------------------------------------------
void SPECCTRA_DB::ThrowIOError( const wxChar* fmt, ... ) throw( IOError ) void SPECCTRA_DB::ThrowIOError( const wxChar* fmt, ... ) throw( IOError )
...@@ -2230,6 +2423,29 @@ DSN_T SPECCTRA_DB::nextTok() ...@@ -2230,6 +2423,29 @@ DSN_T SPECCTRA_DB::nextTok()
} }
void SPECCTRA_DB::needLEFT() throw( IOError )
{
DSN_T tok = nextTok();
if( tok != T_LEFT )
expecting( T_LEFT );
}
void SPECCTRA_DB::needRIGHT() throw( IOError )
{
DSN_T tok = nextTok();
if( tok != T_RIGHT )
expecting( T_RIGHT );
}
void SPECCTRA_DB::needSYMBOL() throw( IOError )
{
DSN_T tok = nextTok();
if( !isSymbol( tok ) )
expecting( T_SYMBOL );
}
void SPECCTRA_DB::Load( const wxString& filename ) throw( IOError ) void SPECCTRA_DB::Load( const wxString& filename ) throw( IOError )
{ {
wxFFile file; wxFFile file;
...@@ -2262,10 +2478,9 @@ void SPECCTRA_DB::Load( const wxString& filename ) throw( IOError ) ...@@ -2262,10 +2478,9 @@ void SPECCTRA_DB::Load( const wxString& filename ) throw( IOError )
void SPECCTRA_DB::doPCB( PCB* growth ) throw( IOError ) void SPECCTRA_DB::doPCB( PCB* growth ) throw( IOError )
{ {
DSN_T tok = nextTok(); DSN_T tok;
if( !isSymbol(tok) ) needSYMBOL();
expecting( T_SYMBOL );
growth->pcbname = lexer->CurText(); growth->pcbname = lexer->CurText();
...@@ -2367,27 +2582,19 @@ void SPECCTRA_DB::doPARSER( PARSER* growth ) throw( IOError ) ...@@ -2367,27 +2582,19 @@ void SPECCTRA_DB::doPARSER( PARSER* growth ) throw( IOError )
break; break;
case T_host_cad: case T_host_cad:
tok = nextTok(); needSYMBOL();
if( tok!=T_STRING && tok!=T_SYMBOL )
expecting( T_SYMBOL );
growth->host_cad = lexer->CurText(); growth->host_cad = lexer->CurText();
break; break;
case T_host_version: case T_host_version:
tok = nextTok(); needSYMBOL();
if( tok!=T_STRING && tok!=T_SYMBOL )
expecting( T_SYMBOL );
growth->host_version = lexer->CurText(); growth->host_version = lexer->CurText();
break; break;
case T_constant: case T_constant:
tok = nextTok(); needSYMBOL();
if( tok!=T_STRING && tok!=T_SYMBOL )
expecting( T_SYMBOL );
growth->const_id1 = lexer->CurText(); growth->const_id1 = lexer->CurText();
tok = nextTok(); needSYMBOL();
if( tok!=T_STRING && tok!=T_SYMBOL )
expecting( T_SYMBOL );
growth->const_id2 = lexer->CurText(); growth->const_id2 = lexer->CurText();
break; break;
...@@ -2448,9 +2655,7 @@ void SPECCTRA_DB::doPARSER( PARSER* growth ) throw( IOError ) ...@@ -2448,9 +2655,7 @@ void SPECCTRA_DB::doPARSER( PARSER* growth ) throw( IOError )
unexpected( lexer->CurText() ); unexpected( lexer->CurText() );
} }
tok = nextTok(); needRIGHT();
if( tok != T_RIGHT )
expecting( T_RIGHT );
} }
} }
...@@ -2478,9 +2683,7 @@ void SPECCTRA_DB::doRESOLUTION( UNIT_RES* growth ) throw(IOError) ...@@ -2478,9 +2683,7 @@ void SPECCTRA_DB::doRESOLUTION( UNIT_RES* growth ) throw(IOError)
growth->value = atoi( lexer->CurText() ); growth->value = atoi( lexer->CurText() );
tok = nextTok(); needRIGHT();
if( tok != T_RIGHT )
expecting( T_RIGHT );
} }
...@@ -2501,31 +2704,23 @@ void SPECCTRA_DB::doUNIT( UNIT_RES* growth ) throw(IOError) ...@@ -2501,31 +2704,23 @@ void SPECCTRA_DB::doUNIT( UNIT_RES* growth ) throw(IOError)
expecting( "inch|mil|cm|mm|um" ); expecting( "inch|mil|cm|mm|um" );
} }
tok = nextTok(); needRIGHT();
if( tok != T_RIGHT )
expecting( T_RIGHT );
} }
void SPECCTRA_DB::doLAYER_PAIR( LAYER_PAIR* growth ) throw( IOError ) void SPECCTRA_DB::doLAYER_PAIR( LAYER_PAIR* growth ) throw( IOError )
{ {
DSN_T tok = nextTok(); needSYMBOL();
if( !isSymbol( tok ) )
expecting( T_SYMBOL );
growth->layer_id0 = lexer->CurText(); growth->layer_id0 = lexer->CurText();
tok = nextTok(); needSYMBOL();
if( !isSymbol( tok ) )
expecting( T_SYMBOL );
growth->layer_id1 = lexer->CurText(); growth->layer_id1 = lexer->CurText();
if( nextTok() != T_NUMBER ) if( nextTok() != T_NUMBER )
expecting( T_NUMBER ); expecting( T_NUMBER );
growth->layer_weight = strtod( lexer->CurText(), 0 ); growth->layer_weight = strtod( lexer->CurText(), 0 );
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
} }
...@@ -2700,8 +2895,7 @@ void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth ) throw( IOError ) ...@@ -2700,8 +2895,7 @@ void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth ) throw( IOError )
if( nextTok() != T_NUMBER ) if( nextTok() != T_NUMBER )
expecting( T_NUMBER ); expecting( T_NUMBER );
growth->sequence_number = atoi( lexer->CurText() ); growth->sequence_number = atoi( lexer->CurText() );
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
break; break;
case T_rule: case T_rule:
...@@ -2812,8 +3006,7 @@ void SPECCTRA_DB::doBOUNDARY( BOUNDARY* growth ) throw( IOError ) ...@@ -2812,8 +3006,7 @@ void SPECCTRA_DB::doBOUNDARY( BOUNDARY* growth ) throw( IOError )
growth->rectangle = new RECTANGLE( growth ); growth->rectangle = new RECTANGLE( growth );
doRECTANGLE( growth->rectangle ); doRECTANGLE( growth->rectangle );
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
} }
else if( tok == T_path ) else if( tok == T_path )
{ {
...@@ -2888,19 +3081,14 @@ void SPECCTRA_DB::doPATH( PATH* growth ) throw( IOError ) ...@@ -2888,19 +3081,14 @@ void SPECCTRA_DB::doPATH( PATH* growth ) throw( IOError )
growth->aperture_type = tok; growth->aperture_type = tok;
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
} }
} }
void SPECCTRA_DB::doRECTANGLE( RECTANGLE* growth ) throw( IOError ) void SPECCTRA_DB::doRECTANGLE( RECTANGLE* growth ) throw( IOError )
{ {
DSN_T tok = nextTok(); needSYMBOL();
if( !isSymbol( tok ) )
expecting( T_SYMBOL );
growth->layer_id = lexer->CurText(); growth->layer_id = lexer->CurText();
if( nextTok() != T_NUMBER ) if( nextTok() != T_NUMBER )
...@@ -2919,18 +3107,15 @@ void SPECCTRA_DB::doRECTANGLE( RECTANGLE* growth ) throw( IOError ) ...@@ -2919,18 +3107,15 @@ void SPECCTRA_DB::doRECTANGLE( RECTANGLE* growth ) throw( IOError )
expecting( T_NUMBER ); expecting( T_NUMBER );
growth->point1.y = strtod( lexer->CurText(), NULL ); growth->point1.y = strtod( lexer->CurText(), NULL );
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
} }
void SPECCTRA_DB::doCIRCLE( CIRCLE* growth ) throw( IOError ) void SPECCTRA_DB::doCIRCLE( CIRCLE* growth ) throw( IOError )
{ {
DSN_T tok = nextTok(); DSN_T tok;
if( !isSymbol(tok) )
expecting( T_SYMBOL );
needSYMBOL();
growth->layer_id = lexer->CurText(); growth->layer_id = lexer->CurText();
if( nextTok() != T_NUMBER ) if( nextTok() != T_NUMBER )
...@@ -2956,11 +3141,7 @@ void SPECCTRA_DB::doCIRCLE( CIRCLE* growth ) throw( IOError ) ...@@ -2956,11 +3141,7 @@ void SPECCTRA_DB::doCIRCLE( CIRCLE* growth ) throw( IOError )
void SPECCTRA_DB::doQARC( QARC* growth ) throw( IOError ) void SPECCTRA_DB::doQARC( QARC* growth ) throw( IOError )
{ {
DSN_T tok = nextTok(); needSYMBOL();
if( !isSymbol(tok) )
expecting( T_SYMBOL );
growth->layer_id = lexer->CurText(); growth->layer_id = lexer->CurText();
if( nextTok() != T_NUMBER ) if( nextTok() != T_NUMBER )
...@@ -2978,22 +3159,15 @@ void SPECCTRA_DB::doQARC( QARC* growth ) throw( IOError ) ...@@ -2978,22 +3159,15 @@ void SPECCTRA_DB::doQARC( QARC* growth ) throw( IOError )
growth->vertex[i].y = strtod( lexer->CurText(), 0 ); growth->vertex[i].y = strtod( lexer->CurText(), 0 );
} }
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
} }
void SPECCTRA_DB::doSTRINGPROP( STRINGPROP* growth ) throw( IOError ) void SPECCTRA_DB::doSTRINGPROP( STRINGPROP* growth ) throw( IOError )
{ {
DSN_T tok = nextTok(); needSYMBOL();
if( !isSymbol( tok ) )
expecting( T_SYMBOL );
growth->value = lexer->CurText(); growth->value = lexer->CurText();
needRIGHT();
if( nextTok() != T_RIGHT )
expecting( T_RIGHT );
} }
...@@ -3006,8 +3180,7 @@ void SPECCTRA_DB::doTOKPROP( TOKPROP* growth ) throw( IOError ) ...@@ -3006,8 +3180,7 @@ void SPECCTRA_DB::doTOKPROP( TOKPROP* growth ) throw( IOError )
growth->value = tok; growth->value = tok;
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
} }
...@@ -3057,8 +3230,7 @@ void SPECCTRA_DB::doCONTROL( CONTROL* growth ) throw( IOError ) ...@@ -3057,8 +3230,7 @@ void SPECCTRA_DB::doCONTROL( CONTROL* growth ) throw( IOError )
if( tok!=T_on && tok!=T_off ) if( tok!=T_on && tok!=T_off )
expecting( "on|off" ); expecting( "on|off" );
growth->via_at_smd = (tok==T_on); growth->via_at_smd = (tok==T_on);
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
break; break;
case T_off_grid: case T_off_grid:
...@@ -3098,20 +3270,15 @@ void SPECCTRA_DB::doPROPERTIES( PROPERTIES* growth ) throw( IOError ) ...@@ -3098,20 +3270,15 @@ void SPECCTRA_DB::doPROPERTIES( PROPERTIES* growth ) throw( IOError )
if( tok != T_LEFT ) if( tok != T_LEFT )
expecting( T_LEFT ); expecting( T_LEFT );
tok = nextTok(); needSYMBOL();
if( !isSymbol(tok) )
expecting( T_SYMBOL );
property.name = lexer->CurText(); property.name = lexer->CurText();
tok = nextTok(); needSYMBOL();
if( !isSymbol(tok) )
expecting( T_SYMBOL );
property.value = lexer->CurText(); property.value = lexer->CurText();
growth->push_back( property ); growth->push_back( property );
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
} }
} }
...@@ -3339,8 +3506,7 @@ void SPECCTRA_DB::doPLACE_RULE( PLACE_RULE* growth, bool expect_object_type ) th ...@@ -3339,8 +3506,7 @@ void SPECCTRA_DB::doPLACE_RULE( PLACE_RULE* growth, bool expect_object_type ) th
if( tok!=T_smd && tok!=T_pin ) if( tok!=T_smd && tok!=T_pin )
expecting( "smd|pin" ); expecting( "smd|pin" );
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
tok = nextTok(); tok = nextTok();
} }
...@@ -3558,10 +3724,9 @@ void SPECCTRA_DB::doGRID( GRID* growth ) throw( IOError ) ...@@ -3558,10 +3724,9 @@ void SPECCTRA_DB::doGRID( GRID* growth ) throw( IOError )
void SPECCTRA_DB::doLAYER_RULE( LAYER_RULE* growth ) throw( IOError ) void SPECCTRA_DB::doLAYER_RULE( LAYER_RULE* growth ) throw( IOError )
{ {
DSN_T tok = nextTok(); DSN_T tok;
if( !isSymbol(tok ) ) needSYMBOL();
expecting( "layer_id" );
do do
{ {
...@@ -3569,7 +3734,7 @@ void SPECCTRA_DB::doLAYER_RULE( LAYER_RULE* growth ) throw( IOError ) ...@@ -3569,7 +3734,7 @@ void SPECCTRA_DB::doLAYER_RULE( LAYER_RULE* growth ) throw( IOError )
} while( isSymbol(tok = nextTok()) ); } while( isSymbol(tok = nextTok()) );
if( nextTok() != T_LEFT ) if( tok != T_LEFT )
expecting( T_LEFT ); expecting( T_LEFT );
if( nextTok() != T_rule ) if( nextTok() != T_rule )
...@@ -3578,8 +3743,7 @@ void SPECCTRA_DB::doLAYER_RULE( LAYER_RULE* growth ) throw( IOError ) ...@@ -3578,8 +3743,7 @@ void SPECCTRA_DB::doLAYER_RULE( LAYER_RULE* growth ) throw( IOError )
growth->rule = new RULE( growth, T_rule ); growth->rule = new RULE( growth, T_rule );
doRULE( growth->rule ); doRULE( growth->rule );
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
} }
...@@ -3758,13 +3922,9 @@ void SPECCTRA_DB::doPLACEMENT( PLACEMENT* growth ) throw( IOError ) ...@@ -3758,13 +3922,9 @@ void SPECCTRA_DB::doPLACEMENT( PLACEMENT* growth ) throw( IOError )
else else
expecting("mirror_first|rotate_first"); expecting("mirror_first|rotate_first");
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT ); needRIGHT();
if( nextTok() != T_RIGHT ) needLEFT();
expecting( T_RIGHT );
if( nextTok() != T_LEFT )
expecting( T_LEFT );
tok = nextTok(); tok = nextTok();
} }
...@@ -3829,8 +3989,7 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth ) throw( IOError ) ...@@ -3829,8 +3989,7 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth ) throw( IOError )
if( tok!=T_on && tok!=T_off ) if( tok!=T_on && tok!=T_off )
expecting( "on|off" ); expecting( "on|off" );
growth->rotate = tok; growth->rotate = tok;
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
break; break;
case T_absolute: case T_absolute:
...@@ -3838,8 +3997,7 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth ) throw( IOError ) ...@@ -3838,8 +3997,7 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth ) throw( IOError )
if( tok!=T_on && tok!=T_off ) if( tok!=T_on && tok!=T_off )
expecting( "on|off" ); expecting( "on|off" );
growth->absolute = tok; growth->absolute = tok;
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
break; break;
case T_shape: case T_shape:
...@@ -3860,13 +4018,11 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth ) throw( IOError ) ...@@ -3860,13 +4018,11 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth ) throw( IOError )
if( nextTok() != T_use_via ) if( nextTok() != T_use_via )
expecting( T_use_via ); expecting( T_use_via );
tok = nextTok(); needSYMBOL();
if( !isSymbol( tok ) )
expecting( T_SYMBOL );
growth->via_id = lexer->CurText(); growth->via_id = lexer->CurText();
if( nextTok()!=T_RIGHT || nextTok()!=T_RIGHT ) needRIGHT();
expecting( T_RIGHT ); needRIGHT();
} }
break; break;
...@@ -3945,8 +4101,7 @@ void SPECCTRA_DB::doSHAPE( SHAPE* growth ) throw( IOError ) ...@@ -3945,8 +4101,7 @@ void SPECCTRA_DB::doSHAPE( SHAPE* growth ) throw( IOError )
if( tok!=T_on && tok!=T_off ) if( tok!=T_on && tok!=T_off )
expecting( "on|off" ); expecting( "on|off" );
growth->connect = tok; growth->connect = tok;
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
break; break;
case T_window: case T_window:
...@@ -4009,8 +4164,7 @@ void SPECCTRA_DB::doIMAGE( IMAGE* growth ) throw( IOError ) ...@@ -4009,8 +4164,7 @@ void SPECCTRA_DB::doIMAGE( IMAGE* growth ) throw( IOError )
if( tok!=T_front && tok!=T_back && tok!=T_both ) if( tok!=T_front && tok!=T_back && tok!=T_both )
expecting( "front|back|both" ); expecting( "front|back|both" );
growth->side = tok; growth->side = tok;
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
break; break;
case T_outline: case T_outline:
...@@ -4072,8 +4226,7 @@ void SPECCTRA_DB::doPIN( PIN* growth ) throw( IOError ) ...@@ -4072,8 +4226,7 @@ void SPECCTRA_DB::doPIN( PIN* growth ) throw( IOError )
if( nextTok() != T_NUMBER ) if( nextTok() != T_NUMBER )
expecting( T_NUMBER ); expecting( T_NUMBER );
growth->SetRotation( strtod( lexer->CurText(), 0 ) ); growth->SetRotation( strtod( lexer->CurText(), 0 ) );
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
tok = nextTok(); tok = nextTok();
} }
...@@ -4189,8 +4342,7 @@ void SPECCTRA_DB::doNET( NET* growth ) throw( IOError ) ...@@ -4189,8 +4342,7 @@ void SPECCTRA_DB::doNET( NET* growth ) throw( IOError )
{ {
case T_unassigned: case T_unassigned:
growth->unassigned = true; growth->unassigned = true;
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
break; break;
case T_net_number: case T_net_number:
...@@ -4206,8 +4358,7 @@ void SPECCTRA_DB::doNET( NET* growth ) throw( IOError ) ...@@ -4206,8 +4358,7 @@ void SPECCTRA_DB::doNET( NET* growth ) throw( IOError )
if( tok!=T_fix && tok!=T_normal ) if( tok!=T_fix && tok!=T_normal )
expecting( "fix|normal" ); expecting( "fix|normal" );
growth->type = tok; growth->type = tok;
if( nextTok() != T_RIGHT ) needRIGHT();
expecting( T_RIGHT );
break; break;
case T_pins: case T_pins:
...@@ -4246,6 +4397,152 @@ void SPECCTRA_DB::doNET( NET* growth ) throw( IOError ) ...@@ -4246,6 +4397,152 @@ void SPECCTRA_DB::doNET( NET* growth ) throw( IOError )
} }
void SPECCTRA_DB::doTOPOLOGY( TOPOLOGY* growth ) throw( IOError )
{
DSN_T tok;
/* <topology_descriptor >::=
(topology {[<fromto_descriptor> |
<component_order_descriptor> ]})
*/
while( (tok = nextTok()) != T_RIGHT )
{
if( tok != T_LEFT )
expecting( T_LEFT );
tok = nextTok();
switch( tok )
{
case T_fromto:
FROMTO* fromto;
fromto = new FROMTO( growth );
growth->fromtos.push_back( fromto );
// doFROMTO( fromto );
break;
case T_comp_order:
COMP_ORDER* comp_order;
comp_order = new COMP_ORDER( growth );
growth->comp_orders.push_back( comp_order );
// doCOMP_ORDER( comp_order );
break;
default:
unexpected( lexer->CurText() );
}
}
}
void SPECCTRA_DB::doCLASS( CLASS* growth ) throw( IOError )
{
DSN_T tok;
/* <class_descriptor >::=
(class
<class_id > {[{<net_id >} | {<composite_name_list> }]}
[<circuit_descriptor> ]
[<rule_descriptor> ]
[{<layer_rule_descriptor> }]
[<topology_descriptor> ]
)
*/
needSYMBOL();
growth->class_id = lexer->CurText();
// do net_ids, do not support <composite_name_list>s at this time
while( isSymbol(tok = nextTok()) )
{
growth->net_ids.push_back( lexer->CurText() );
}
while( tok != T_RIGHT )
{
if( tok != T_LEFT )
expecting( T_LEFT );
tok = nextTok();
switch( tok )
{
case T_rule:
if( growth->rules )
unexpected( tok );
growth->rules = new RULE( growth, T_rule );
doRULE( growth->rules );
break;
case T_layer_rule:
LAYER_RULE* layer_rule;
layer_rule = new LAYER_RULE( growth );
growth->layer_rules.push_back( layer_rule );
doLAYER_RULE( layer_rule );
break;
case T_topology:
if( growth->topology )
unexpected( tok );
growth->topology = new TOPOLOGY( growth );
doTOPOLOGY( growth->topology );
break;
default: // handle all the circuit_descriptor here as strings
{
std::string builder;
int bracketNesting = 1; // we already saw the opening T_LEFT
DSN_T tok = T_NONE;
builder += '(';
builder += lexer->CurText();
while( bracketNesting!=0 && tok!=T_EOF )
{
tok = nextTok();
if( tok==T_LEFT)
++bracketNesting;
else if( tok==T_RIGHT )
--bracketNesting;
if( bracketNesting >= 1 )
{
if( lexer->PrevTok() != T_LEFT && tok!=T_RIGHT )
builder += ' ';
if( tok==T_STRING )
builder += quote_char;
builder += lexer->CurText();
if( tok==T_STRING )
builder += quote_char;
}
// When the nested rule is closed with a T_RIGHT and we are back down
// to bracketNesting == 0, then save the builder and break;
if( bracketNesting == 0 )
{
builder += ')';
growth->circuit.push_back( builder );
break;
}
}
if( tok==T_EOF )
unexpected( T_EOF );
} // scope bracket
} // switch
tok = nextTok();
} // while
}
void SPECCTRA_DB::doNETWORK( NETWORK* growth ) throw( IOError ) void SPECCTRA_DB::doNETWORK( NETWORK* growth ) throw( IOError )
{ {
DSN_T tok; DSN_T tok;
...@@ -4277,6 +4574,13 @@ void SPECCTRA_DB::doNETWORK( NETWORK* growth ) throw( IOError ) ...@@ -4277,6 +4574,13 @@ void SPECCTRA_DB::doNETWORK( NETWORK* growth ) throw( IOError )
doNET( net ); doNET( net );
break; break;
case T_class:
CLASS* myclass;
myclass = new CLASS( growth );
growth->classes.push_back( myclass );
doCLASS( myclass );
break;
default: default:
unexpected( lexer->CurText() ); unexpected( lexer->CurText() );
} }
...@@ -4284,25 +4588,31 @@ void SPECCTRA_DB::doNETWORK( NETWORK* growth ) throw( IOError ) ...@@ -4284,25 +4588,31 @@ void SPECCTRA_DB::doNETWORK( NETWORK* growth ) throw( IOError )
} }
void SPECCTRA_DB::Print( int nestLevel, const char* fmt, ... ) throw( IOError ) int SPECCTRA_DB::Print( int nestLevel, const char* fmt, ... ) throw( IOError )
{ {
va_list args; va_list args;
va_start( args, fmt ); va_start( args, fmt );
int ret = 0; int result = 0;
int total = 0;
for( int i=0; i<nestLevel; ++i ) for( int i=0; i<nestLevel; ++i )
{ {
ret = fprintf( fp, " " ); result = fprintf( fp, "%*c", NESTWIDTH, ' ' );
if( ret < 0 ) if( result < 0 )
break; break;
total += result;
} }
if( ret<0 || vfprintf( fp, fmt, args )<0 ) if( result<0 || (result=vfprintf( fp, fmt, args ))<0 )
ThrowIOError( _("System file error writing to file \"%s\""), filename.GetData() ); ThrowIOError( _("System file error writing to file \"%s\""), filename.GetData() );
va_end( args ); va_end( args );
total += result;
return total;
} }
...@@ -4382,7 +4692,7 @@ void ELEM::Format( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError ) ...@@ -4382,7 +4692,7 @@ void ELEM::Format( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError )
} }
void ELEM::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError ) void ELEM_HOLDER::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError )
{ {
for( int i=0; i<Length(); ++i ) for( int i=0; i<Length(); ++i )
{ {
...@@ -4391,7 +4701,7 @@ void ELEM::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError ...@@ -4391,7 +4701,7 @@ void ELEM::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError
} }
int ELEM::FindElem( DSN_T aType, int instanceNum ) int ELEM_HOLDER::FindElem( DSN_T aType, int instanceNum )
{ {
int repeats=0; int repeats=0;
for( unsigned i=0; i<kids.size(); ++i ) for( unsigned i=0; i<kids.size(); ++i )
...@@ -4553,8 +4863,9 @@ int main( int argc, char** argv ) ...@@ -4553,8 +4863,9 @@ int main( int argc, char** argv )
// db.SetPCB( SPECCTRA_DB::MakePCB() ); // db.SetPCB( SPECCTRA_DB::MakePCB() );
db.Export( wxT("/tmp/export.dsn"), 0 );
// export what we read in, making this test program basically a beautifier
db.Export( wxT("/tmp/export.dsn"), 0 );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment