more free sweet work

This commit is contained in:
Dick Hollenbeck 2011-04-03 13:24:45 -05:00
parent 39194ef669
commit 5dc3cf9816
5 changed files with 146 additions and 132 deletions

View File

@ -40,7 +40,7 @@ BEZIER="
)"
TEXT="
(text \"This is some text\" (at 23 23 90.0)(justify left bottom)(visible yes)(fill filled)
(text (at 23 23 90.0) \"This is some text\" (justify left bottom)(visible yes)(fill filled)
(font arial (size .8 1.2))
)"

View File

@ -31,6 +31,20 @@
#include <macros.h>
//#include <richio.h>
/**
* Function formatAt
* returns a formatted "(at X Y [ANGLE])" s-expression
*/
static void formatAt( OUTPUTFORMATTER* out, const POINT& aPos, ANGLE aAngle, int indent=0 )
throw( IO_ERROR )
{
out->Print( indent, aAngle==0.0 ? "(at %.6g %.6g %.6g)" : "(at %.6g %.6g)",
InternalToLogical( aPos.x ), InternalToLogical( aPos.y ),
double( aAngle ) );
}
using namespace SCH;
@ -40,13 +54,6 @@ PART::PART( LIB* aOwner, const STRING& aPartNameAndRev ) :
partNameAndRev( aPartNameAndRev ),
extends( 0 ),
base( 0 )
/*
reference( this, wxT( "reference " ) ),
value( this, wxT( "value" ) ),
footprint( this, wxT( "footprint" ) ),
model( this, wxT( "model" ) ),
datasheet( this, wxT( "datasheet" ) )
*/
{
// Our goal is to have class LIB only instantiate what is needed, so print here
// what it is doing. It is the only class where PART can be instantiated.
@ -307,12 +314,7 @@ void TEXT_EFFECTS::Format( OUTPUTFORMATTER* out, int indent, int ctl ) const
else
out->Print( indent, "(effects %s ", out->Quotew( propName ).c_str() );
out->Print( 0, "(at %.6g %.6g", InternalToLogical( pos.x ), InternalToLogical( pos.y ) );
if( angle )
out->Print( 0, " %.6g)", double( angle ) );
else
out->Print( 0, ")" );
formatAt( out, pos, angle );
font.Format( out, 0, ctl | CTL_OMIT_NL );
@ -349,13 +351,8 @@ void PIN::Format( OUTPUTFORMATTER* out, int indent, int ctl ) const
{
out->Print( indent, "(pin %s %s ", ShowType(), ShowShape() );
if( angle )
out->Print( 0, "(at %.6g %.6g %.6g)", InternalToLogical( pos.x ), InternalToLogical( pos.y ), double(angle) );
else
out->Print( 0, "(at %.6g %.6g)", InternalToLogical( pos.x ), InternalToLogical( pos.y ) );
formatAt( out, pos, angle );
out->Print( 0, "(length %.6g)", InternalToLogical( length ) );
out->Print( 0, "(visible %s)\n", isVisible ? "yes" : "no" );
signal.Format( out, "signal", indent+1, 0 );
@ -386,7 +383,7 @@ void POLY_LINE::Format( OUTPUTFORMATTER* out, int indent, int ctl ) const
void POLY_LINE::formatContents( OUTPUTFORMATTER* out, int indent, int ctl ) const
throw( IO_ERROR )
{
out->Print( 0, "(line_width %.6g)", lineWidth ); // @todo use logical units?
out->Print( 0, "(line_width %.6g)", InternalToWidth( lineWidth ) );
if( fillType != PR::T_none )
out->Print( 0, "(fill %s)", ShowFill( fillType ) );
@ -437,7 +434,7 @@ void RECTANGLE::Format( OUTPUTFORMATTER* out, int indent, int ctl ) const
out->Print( indent, "(rectangle (start %.6g %.6g)(end %.6g %.6g)(line_width %.6g)",
InternalToLogical( start.x ), InternalToLogical( start.y ),
InternalToLogical( end.x ), InternalToLogical( end.y ),
lineWidth );
InternalToWidth( lineWidth ) );
if( fillType != PR::T_none )
out->Print( 0, "(fill %s)", ShowFill( fillType ) );
@ -456,7 +453,7 @@ void CIRCLE::Format( OUTPUTFORMATTER* out, int indent, int ctl ) const
out->Print( indent, "(circle (center %.6g %.6g)(radius %.6g)(line_width %.6g)",
InternalToLogical( center.x ), InternalToLogical( center.y ),
InternalToLogical( radius),
lineWidth );
InternalToWidth( lineWidth ) );
if( fillType != PR::T_none )
out->Print( 0, "(fill %s)", ShowFill( fillType ) );
@ -477,7 +474,7 @@ void ARC::Format( OUTPUTFORMATTER* out, int indent, int ctl ) const
InternalToLogical( radius),
InternalToLogical( start.x ), InternalToLogical( start.y ),
InternalToLogical( end.x ), InternalToLogical( end.y ),
lineWidth );
InternalToWidth( lineWidth ) );
if( fillType != PR::T_none )
out->Print( 0, "(fill %s)", ShowFill( fillType ) );
@ -491,23 +488,14 @@ void GR_TEXT::Format( OUTPUTFORMATTER* out, int indent, int ctl ) const
{
/*
(text "This is the text that gets drawn."
(at X Y [ANGLE])
# Valid horizontal justification values are center, right, and left. Valid
# vertical justification values are center, top, bottom.
(justify HORIZONTAL_JUSTIFY VERTICAL_JUSTIFY)
(at X Y [ANGLE])(justify HORIZONTAL_JUSTIFY VERTICAL_JUSTIFY)(visible YES)(fill FILL_TYPE)
(font [FONT] (size HEIGHT WIDTH) [italic] [bold])
(visible YES)
(fill FILL_TYPE)
)
*/
out->Print( indent, "(text %s\n", out->Quotew( text ).c_str() );
if( angle )
out->Print( indent+1, "(at %.6g %.6g %.6g)", InternalToLogical( pos.x ), InternalToLogical( pos.y ), double( angle ) );
else
out->Print( indent+1, "(at %.6g %.6g)", InternalToLogical( pos.x ), InternalToLogical( pos.y ) );
formatAt( out, pos, angle, indent+1 );
out->Print( 0, "(justify %s %s)(visible %s)",
ShowJustify( hjustify ), ShowJustify( vjustify ),
@ -516,8 +504,7 @@ void GR_TEXT::Format( OUTPUTFORMATTER* out, int indent, int ctl ) const
if( fillType != PR::T_none )
out->Print( 0, "(fill %s)", ShowFill( fillType ) );
out->Print( 0, "\n" );
font.Format( out, indent+1, CTL_OMIT_NL );
font.Format( out, 0, CTL_OMIT_NL );
out->Print( 0, ")\n" );
}

View File

@ -55,6 +55,19 @@ static inline int LogicalToInternal( double aCoord )
return int( aCoord * INTERNAL_PER_LOGICAL );
}
static inline int WidthToInternal( double aWidth )
{
// sweet line widths are a "percent of a logical unit"
return LogicalToInternal( aWidth ) / 100;
}
static inline double InternalToWidth( int aWidth )
{
// sweet line widths are a "percent of a logical unit"
return InternalToLogical( aWidth ) * 100;
}
//-----<temporary home for PART sub objects, move after stable>------------------
#include <wx/gdicmn.h>
@ -174,7 +187,7 @@ class POLY_LINE : public BASE_GRAPHIC
friend class SWEET_PARSER;
protected:
double lineWidth;
int lineWidth;
int fillType; // T_none, T_filled, or T_transparent
POINTS pts;
@ -216,7 +229,7 @@ class RECTANGLE : public BASE_GRAPHIC
friend class SWEET_PARSER;
protected:
double lineWidth;
int lineWidth;
int fillType; // T_none, T_filled, or T_transparent
POINT start;
POINT end;
@ -242,7 +255,7 @@ class CIRCLE : public BASE_GRAPHIC
protected:
POINT center;
int radius;
double lineWidth;
int lineWidth;
int fillType; // T_none, T_filled, or T_transparent
public:
@ -266,7 +279,7 @@ class ARC : public BASE_GRAPHIC
protected:
POINT pos;
double lineWidth;
int lineWidth;
int fillType; // T_none, T_filled, or T_transparent
int radius;
POINT start;

View File

@ -41,6 +41,11 @@ static inline int internal( const STRING& aCoord )
return LogicalToInternal( strtod( aCoord.c_str(), NULL ) );
}
static inline int fromWidth( const STRING& aWidth )
{
return WidthToInternal( strtod( aWidth.c_str(), NULL ) );
}
/**
* Enum PartBit
@ -315,13 +320,14 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
parseKeywords( me );
break;
/*
@todo
// do we want to inherit alternates?
case T_alternates:
break;
// do we want to inherit alternates?
case T_pin_merge:
break;
@ -735,8 +741,7 @@ void SWEET_PARSER::parsePolyLine( POLY_LINE* me )
if( sawWidth )
Duplicate( tok );
NeedNUMBER( "line_width" );
// @todo Use logical units?
me->lineWidth = strtod( CurText(), NULL );
me->lineWidth = fromWidth( CurText() );
NeedRIGHT();
sawWidth = true;
break;
@ -822,15 +827,16 @@ void SWEET_PARSER::parseRectangle( RECTANGLE* me )
case T_line_width:
if( sawWidth )
Duplicate( tok );
NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL );
NeedRIGHT();
sawWidth = true;
NeedNUMBER( "line_width" );
me->lineWidth = fromWidth( CurText() );
NeedRIGHT();
break;
case T_fill:
if( sawFill )
Duplicate( tok );
sawFill = true;
tok = NeedSYMBOL();
switch( tok )
{
@ -843,29 +849,28 @@ void SWEET_PARSER::parseRectangle( RECTANGLE* me )
Expecting( "none|filled|transparent" );
}
NeedRIGHT();
sawFill = true;
break;
case T_start:
if( sawStart )
Duplicate( tok );
sawStart = true;
NeedNUMBER( "x" );
me->start.x = internal( CurText() );
NeedNUMBER( "y" );
me->start.y = internal( CurText() );
NeedRIGHT();
sawStart = true;
break;
case T_end:
if( sawEnd )
Duplicate( tok );
sawEnd = true;
NeedNUMBER( "x" );
me->end.x = internal( CurText() );
NeedNUMBER( "y" );
me->end.y = internal( CurText() );
NeedRIGHT();
sawEnd = true;
break;
default:
@ -904,15 +909,16 @@ void SWEET_PARSER::parseCircle( CIRCLE* me )
case T_line_width:
if( sawWidth )
Duplicate( tok );
NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL );
NeedRIGHT();
sawWidth = true;
NeedNUMBER( "line_width" );
me->lineWidth = fromWidth( CurText() );
NeedRIGHT();
break;
case T_fill:
if( sawFill )
Duplicate( tok );
sawFill = true;
tok = NeedSYMBOL();
switch( tok )
{
@ -925,27 +931,26 @@ void SWEET_PARSER::parseCircle( CIRCLE* me )
Expecting( "none|filled|transparent" );
}
NeedRIGHT();
sawFill = true;
break;
case T_center:
if( sawCenter )
Duplicate( tok );
sawCenter = true;
NeedNUMBER( "center x" );
me->center.x = internal( CurText() );
NeedNUMBER( "center y" );
me->center.y = internal( CurText() );
NeedRIGHT();
sawCenter = true;
break;
case T_radius:
if( sawRadius )
Duplicate( tok );
sawRadius = true;
NeedNUMBER( "radius" );
me->radius = internal( CurText() );
NeedRIGHT();
sawRadius = true;
break;
default:
@ -984,15 +989,16 @@ void SWEET_PARSER::parseArc( ARC* me )
case T_line_width:
if( sawWidth )
Duplicate( tok );
NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL );
NeedRIGHT();
sawWidth = true;
NeedNUMBER( "line_width" );
me->lineWidth = fromWidth( CurText() );
NeedRIGHT();
break;
case T_fill:
if( sawFill )
Duplicate( tok );
sawFill = true;
tok = NeedSYMBOL();
switch( tok )
{
@ -1005,49 +1011,48 @@ void SWEET_PARSER::parseArc( ARC* me )
Expecting( "none|filled|transparent" );
}
NeedRIGHT();
sawFill = true;
break;
case T_pos:
if( sawPos )
Duplicate( tok );
sawPos = true;
NeedNUMBER( "pos x" );
me->pos.x = internal( CurText() );
NeedNUMBER( "pos y" );
me->pos.y = internal( CurText() );
NeedRIGHT();
sawPos = true;
break;
case T_radius:
if( sawRadius )
Duplicate( tok );
sawRadius = true;
NeedNUMBER( "radius" );
me->radius = internal( CurText() );
NeedRIGHT();
sawRadius = true;
break;
case T_start:
if( sawStart )
Duplicate( tok );
sawStart = true;
NeedNUMBER( "start x" );
me->start.x = internal( CurText() );
NeedNUMBER( "start y" );
me->start.y = internal( CurText() );
NeedRIGHT();
sawStart = true;
break;
case T_end:
if( sawEnd )
Duplicate( tok );
sawEnd = true;
NeedNUMBER( "end x" );
me->end.x = internal( CurText() );
NeedNUMBER( "end y" );
me->end.y = internal( CurText() );
NeedRIGHT();
sawEnd = true;
break;
default:
@ -1099,91 +1104,100 @@ void SWEET_PARSER::parseText( GR_TEXT* me )
bool sawFont = false;
bool sawVis = false;
bool sawJust = false;
NeedSYMBOLorNUMBER();
me->text = FROM_UTF8( CurText() );
bool sawText = false;
while( ( tok = NextTok() ) != T_RIGHT )
{
if( tok != T_LEFT )
Expecting( T_LEFT );
tok = NextTok();
switch( tok )
if( tok == T_LEFT )
{
case T_at:
if( sawAt )
Duplicate( tok );
parseAt( &me->pos, &me->angle );
sawAt = true;
break;
tok = NextTok();
case T_fill:
if( sawFill )
Duplicate( tok );
tok = NeedSYMBOL();
switch( tok )
{
case T_none:
case T_filled:
case T_transparent:
me->fillType = tok;
case T_at:
if( sawAt )
Duplicate( tok );
parseAt( &me->pos, &me->angle );
sawAt = true;
break;
default:
Expecting( "none|filled|transparent" );
}
NeedRIGHT();
sawFill = true;
break;
case T_justify:
if( sawJust )
Duplicate( tok );
tok = NeedSYMBOL();
switch( tok )
{
case T_center:
case T_right:
case T_left:
me->hjustify = tok;
case T_fill:
if( sawFill )
Duplicate( tok );
tok = NeedSYMBOL();
switch( tok )
{
case T_none:
case T_filled:
case T_transparent:
me->fillType = tok;
break;
default:
Expecting( "none|filled|transparent" );
}
NeedRIGHT();
sawFill = true;
break;
default:
Expecting( "center|right|left" );
}
tok = NeedSYMBOL();
switch( tok )
{
case T_center:
case T_top:
case T_bottom:
me->vjustify = tok;
case T_justify:
if( sawJust )
Duplicate( tok );
tok = NeedSYMBOL();
switch( tok )
{
case T_center:
case T_right:
case T_left:
me->hjustify = tok;
break;
default:
Expecting( "center|right|left" );
}
tok = NeedSYMBOL();
switch( tok )
{
case T_center:
case T_top:
case T_bottom:
me->vjustify = tok;
break;
default:
Expecting( "center|top|bottom" );
}
NeedRIGHT();
sawJust = true;
break;
case T_visible:
if( sawVis )
Duplicate( tok );
parseBool( &me->isVisible );
NeedRIGHT();
sawVis = true;
break;
case T_font:
if( sawFont )
Duplicate( tok );
sawFont = true;
parseFont( &me->font );
break;
default:
Expecting( "center|top|bottom" );
Expecting( "at|justify|font|visible|fill" );
}
NeedRIGHT();
sawJust = true;
break;
}
else
{
if( !IsSymbol( tok ) && tok != T_NUMBER )
Expecting( T_STRING );
case T_visible:
if( sawVis )
if( sawText )
Duplicate( tok );
parseBool( &me->isVisible );
NeedRIGHT();
sawVis = true;
break;
sawText = true;
case T_font:
if( sawFont )
Duplicate( tok );
sawFont = true;
parseFont( &me->font );
break;
default:
Expecting( "at|justify|font|visible|fill" );
me->text = FROM_UTF8( CurText() );
}
}
}