Commit bd7e8e53 authored by Dick Hollenbeck's avatar Dick Hollenbeck

more sweet parsing

parent c86a65c9
...@@ -12,7 +12,8 @@ LINE="(line (pts (xy 12 13)(xy 12 20))(line_width 1.5))" ...@@ -12,7 +12,8 @@ LINE="(line (pts (xy 12 13)(xy 12 20))(line_width 1.5))"
RECT="(rectangle (start 4 5)(end 6 8)(line_width 2.3)(fill transparent))" RECT="(rectangle (start 4 5)(end 6 8)(line_width 2.3)(fill transparent))"
CIRCLE="(circle (center 1 0)(radius 5)(line_width 2.1)(fill none))" CIRCLE="(circle (center 1 0)(radius 5)(line_width 2.1)(fill none))"
ARC="(arc (pos 22 33)(radius 12)(start 2 4)(end 13 33)(line_width 2.3)(fill filled))" ARC="(arc (pos 22 33)(radius 12)(start 2 4)(end 13 33)(line_width 2.3)(fill filled))"
BEZIER="(bezier (fill none)(line_width 2.0)(pts (xy 0 1)(xy 2 4)))"
TEXT="(text \"This is some text\" (at 23 23 90.0)(justify left bottom)(visible yes)(fill filled))"
for C in ${CATEGORIES}; do for C in ${CATEGORIES}; do
...@@ -20,10 +21,24 @@ for C in ${CATEGORIES}; do ...@@ -20,10 +21,24 @@ for C in ${CATEGORIES}; do
for P in ${PARTS}; do for P in ${PARTS}; do
for R in ${REVS}; do for R in ${REVS}; do
echo "(part $C/$P (value 22)(footprint SM0805)(model Airplane)$LINE$RECT$CIRCLE$ARC)" > $BASEDIR/$C/$P.part.$R echo "(part $C/$P (value 22)(footprint SM0805)(model Airplane)
$LINE
$RECT
$CIRCLE
$ARC
$BEZIER
$TEXT
)" > $BASEDIR/$C/$P.part.$R
done done
# also make the part without a rev: # also make the part without a rev:
echo "(part $C/$P (value 22)(footprint SM0805)(model Airplane)$LINE$RECT$CIRCLE$ARC)" > $BASEDIR/$C/$P.part echo "(part $C/$P (value 22)(footprint SM0805)(model Airplane)
$LINE
$RECT
$CIRCLE
$ARC
$BEZIER
$TEXT
)" > $BASEDIR/$C/$P.part
done done
done done
...@@ -53,6 +53,7 @@ void PART::clear() ...@@ -53,6 +53,7 @@ void PART::clear()
extends = 0; extends = 0;
} }
// graphics objects I own, and the container will not destroy them:
for( GRAPHICS::iterator it = graphics.begin(); it != graphics.end(); ++it ) for( GRAPHICS::iterator it = graphics.begin(); it != graphics.end(); ++it )
delete *it; delete *it;
graphics.clear(); graphics.clear();
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
typedef wxPoint POINT; typedef wxPoint POINT;
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
#include <vector> #include <deque>
namespace SCH { namespace SCH {
...@@ -34,7 +34,7 @@ public: ...@@ -34,7 +34,7 @@ public:
virtual ~BASE_GRAPHIC() {} virtual ~BASE_GRAPHIC() {}
}; };
typedef std::vector<POINT> POINTS; typedef std::deque<POINT> POINTS;
class POLY_LINE : BASE_GRAPHIC class POLY_LINE : BASE_GRAPHIC
{ {
...@@ -43,6 +43,7 @@ class POLY_LINE : BASE_GRAPHIC ...@@ -43,6 +43,7 @@ class POLY_LINE : BASE_GRAPHIC
protected: protected:
double lineWidth; double lineWidth;
int fillType; // T_none, T_filled, or T_transparent
POINTS pts; POINTS pts;
public: public:
...@@ -51,6 +52,16 @@ public: ...@@ -51,6 +52,16 @@ public:
{} {}
}; };
class BEZIER : POLY_LINE
{
friend class PART;
friend class SWEET_PARSER;
public:
BEZIER( PART* aOwner ) :
POLY_LINE( aOwner )
{}
};
class RECTANGLE : BASE_GRAPHIC class RECTANGLE : BASE_GRAPHIC
{ {
...@@ -107,6 +118,36 @@ public: ...@@ -107,6 +118,36 @@ public:
{} {}
}; };
class GR_TEXT : BASE_GRAPHIC
{
friend class PART;
friend class SWEET_PARSER;
protected:
POINT pos;
float angle;
int fillType; // T_none, T_filled, or T_transparent
int hjustify; // T_center, T_right, or T_left
int vjustify; // T_center, T_top, or T_bottom
bool isVisible;
wxString text;
// FONT font;
public:
GR_TEXT( PART* aOwner ) :
BASE_GRAPHIC( aOwner )
/*
,
fillType( T_filled ),
hjustify( T_left ),
vjustify( T_bottom ),
angle( 0 ),
isVisible( true )
*/
{}
};
} // namespace SCH } // namespace SCH
...@@ -115,7 +156,7 @@ public: ...@@ -115,7 +156,7 @@ public:
namespace SCH { namespace SCH {
typedef std::vector< BASE_GRAPHIC* > GRAPHICS; typedef std::deque< BASE_GRAPHIC* > GRAPHICS;
class LPID; class LPID;
class SWEET_PARSER; class SWEET_PARSER;
...@@ -180,7 +221,10 @@ protected: // not likely to have C++ descendants, but protected none-the-le ...@@ -180,7 +221,10 @@ protected: // not likely to have C++ descendants, but protected none-the-le
/// A property list. /// A property list.
//PROPERTIES properties; //PROPERTIES properties;
/// A drawing list for graphics /**
* Member graphics
* owns : POLY_LINE, RECTANGLE, CIRCLE, ARC, BEZIER, and GR_TEXT objects.
*/
GRAPHICS graphics; GRAPHICS graphics;
/// A pin list /// A pin list
......
...@@ -180,6 +180,9 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E ...@@ -180,6 +180,9 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
if( tok == T_LEFT ) if( tok == T_LEFT )
tok = NextTok(); tok = NextTok();
// because exceptions are thrown, any 'new' allocation has to be stored
// somewhere other than on the stack, ASAP.
switch( tok ) switch( tok )
{ {
default: default:
...@@ -233,6 +236,20 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E ...@@ -233,6 +236,20 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
parseArc( arc ); parseArc( arc );
break; break;
case T_bezier:
BEZIER* bezier;
bezier = new BEZIER( me );
me->graphics.push_back( bezier );
parseBezier( bezier );
break;
case T_text:
GR_TEXT* text;
text = new GR_TEXT( me );
me->graphics.push_back( text );
parseText( text );
break;
case T_value: case T_value:
if( contains & PB(VALUE) ) if( contains & PB(VALUE) )
Duplicate( tok ); Duplicate( tok );
...@@ -263,7 +280,6 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E ...@@ -263,7 +280,6 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
NeedRIGHT(); NeedRIGHT();
break; break;
/* /*
case T_keywords: case T_keywords:
break; break;
...@@ -295,11 +311,6 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E ...@@ -295,11 +311,6 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
case T_route_pin_swap: case T_route_pin_swap:
break; break;
case T_bezier:
break;
case T_text:
break;
*/ */
// Not sure about reference in a PART, comes in at COMPONENT object. // Not sure about reference in a PART, comes in at COMPONENT object.
...@@ -321,7 +332,9 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E ...@@ -321,7 +332,9 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
void SWEET_PARSER::parsePolyLine( POLY_LINE* me ) void SWEET_PARSER::parsePolyLine( POLY_LINE* me )
{ {
T tok; T tok;
int count; int count = 0;
bool sawWidth = false;
bool sawFill = false;
NeedLEFT(); NeedLEFT();
while( ( tok = NextTok() ) != T_RIGHT ) while( ( tok = NextTok() ) != T_RIGHT )
...@@ -332,13 +345,18 @@ void SWEET_PARSER::parsePolyLine( POLY_LINE* me ) ...@@ -332,13 +345,18 @@ void SWEET_PARSER::parsePolyLine( POLY_LINE* me )
switch( tok ) switch( tok )
{ {
case T_line_width: case T_line_width:
if( sawWidth )
Duplicate( tok );
NeedNUMBER( "line_width" ); NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL ); me->lineWidth = strtod( CurText(), NULL );
NeedRIGHT(); NeedRIGHT();
sawWidth = true;
break; break;
case T_pts: case T_pts:
for( count=0; ( tok = NextTok() ) != T_RIGHT; ++count ) if( count )
Duplicate( tok );
for( ; ( tok = NextTok() ) != T_RIGHT; ++count )
{ {
if( tok != T_LEFT ) if( tok != T_LEFT )
Expecting( T_LEFT ); Expecting( T_LEFT );
...@@ -357,10 +375,26 @@ void SWEET_PARSER::parsePolyLine( POLY_LINE* me ) ...@@ -357,10 +375,26 @@ void SWEET_PARSER::parsePolyLine( POLY_LINE* me )
NeedRIGHT(); NeedRIGHT();
} }
if( count < 2 )
Expecting( ">= 2 pts" );
break; break;
case T_fill: case T_fill:
// @todo figure this out, maybe spit into polygon 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; break;
default: default:
...@@ -370,6 +404,12 @@ void SWEET_PARSER::parsePolyLine( POLY_LINE* me ) ...@@ -370,6 +404,12 @@ void SWEET_PARSER::parsePolyLine( POLY_LINE* me )
} }
void SWEET_PARSER::parseBezier( BEZIER* me )
{
parsePolyLine( me );
}
void SWEET_PARSER::parseRectangle( RECTANGLE* me ) void SWEET_PARSER::parseRectangle( RECTANGLE* me )
{ {
T tok; T tok;
...@@ -391,8 +431,8 @@ void SWEET_PARSER::parseRectangle( RECTANGLE* me ) ...@@ -391,8 +431,8 @@ void SWEET_PARSER::parseRectangle( RECTANGLE* me )
Duplicate( tok ); Duplicate( tok );
NeedNUMBER( "line_width" ); NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL ); me->lineWidth = strtod( CurText(), NULL );
sawWidth = true;
NeedRIGHT(); NeedRIGHT();
sawWidth = true;
break; break;
case T_fill: case T_fill:
...@@ -463,8 +503,8 @@ void SWEET_PARSER::parseCircle( CIRCLE* me ) ...@@ -463,8 +503,8 @@ void SWEET_PARSER::parseCircle( CIRCLE* me )
Duplicate( tok ); Duplicate( tok );
NeedNUMBER( "line_width" ); NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL ); me->lineWidth = strtod( CurText(), NULL );
sawWidth = true;
NeedRIGHT(); NeedRIGHT();
sawWidth = true;
break; break;
case T_fill: case T_fill:
...@@ -535,8 +575,8 @@ void SWEET_PARSER::parseArc( ARC* me ) ...@@ -535,8 +575,8 @@ void SWEET_PARSER::parseArc( ARC* me )
Duplicate( tok ); Duplicate( tok );
NeedNUMBER( "line_width" ); NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL ); me->lineWidth = strtod( CurText(), NULL );
sawWidth = true;
NeedRIGHT(); NeedRIGHT();
sawWidth = true;
break; break;
case T_fill: case T_fill:
...@@ -604,3 +644,121 @@ void SWEET_PARSER::parseArc( ARC* me ) ...@@ -604,3 +644,121 @@ void SWEET_PARSER::parseArc( ARC* me )
} }
} }
} }
void SWEET_PARSER::parseText( GR_TEXT* me )
{
T tok;
bool sawAt = false;
bool sawFill = false;
bool sawFont = false;
bool sawVis = false;
bool sawJust = false;
NeedSYMBOLorNUMBER();
me->text = FROM_UTF8( CurText() );
NeedLEFT();
while( ( tok = NextTok() ) != T_RIGHT )
{
if( tok == T_LEFT )
tok = NextTok();
switch( tok )
{
case T_at:
if( sawAt )
Duplicate( tok );
NeedNUMBER( "at x" );
me->pos.x = internal( CurText() );
NeedNUMBER( "at y" );
me->pos.y = internal( CurText() );
tok = NextTok();
if( tok == T_NUMBER )
{
me->angle = strtod( CurText(), NULL );
tok = NextTok();
}
if( tok != T_RIGHT )
Expecting( T_RIGHT );
sawAt = true;
break;
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;
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 );
tok = NeedSYMBOL();
switch( tok )
{
case T_yes:
case T_no:
me->isVisible = (tok == T_yes);
break;
default:
Expecting( "yes|no" );
}
NeedRIGHT();
sawVis = true;
break;
case T_font:
// @todo
sawFont = true;
break;
default:
Expecting( "at|justify|font|visible|fill" );
}
}
}
...@@ -33,10 +33,14 @@ namespace SCH { ...@@ -33,10 +33,14 @@ namespace SCH {
class LIB_TABLE; class LIB_TABLE;
class PART; class PART;
// GRAPHICS
class POLY_LINE; class POLY_LINE;
class RECTANGLE; class RECTANGLE;
class CIRCLE; class CIRCLE;
class ARC; class ARC;
class BEZIER;
class GR_TEXT;
/** /**
...@@ -57,9 +61,11 @@ class SWEET_PARSER : public SWEET_LEXER ...@@ -57,9 +61,11 @@ class SWEET_PARSER : public SWEET_LEXER
void parseExtends( PART* me ); void parseExtends( PART* me );
void parsePolyLine( POLY_LINE* me ); void parsePolyLine( POLY_LINE* me );
void parseBezier( BEZIER* me );
void parseRectangle( RECTANGLE* me ); void parseRectangle( RECTANGLE* me );
void parseCircle( CIRCLE* me ); void parseCircle( CIRCLE* me );
void parseArc( ARC* me ); void parseArc( ARC* me );
void parseText( GR_TEXT* me );
public: public:
......
...@@ -4,6 +4,7 @@ arc ...@@ -4,6 +4,7 @@ arc
at at
bezier bezier
bidirectional bidirectional
bottom
center center
circle circle
clock clock
...@@ -23,11 +24,13 @@ inverted ...@@ -23,11 +24,13 @@ inverted
inverted_clk inverted_clk
justify justify
keywords keywords
left
length length
line line
line_width line_width
model model
name name
no
none none
number number
open_collector open_collector
...@@ -51,12 +54,14 @@ pts ...@@ -51,12 +54,14 @@ pts
radius radius
rectangle rectangle
reference reference
right
route_alt_swap route_alt_swap
route_pin_swap route_pin_swap
size size
start start
start_angle start_angle
text text
top
transparent transparent
tristate tristate
unconnected unconnected
...@@ -65,3 +70,5 @@ unspecified ...@@ -65,3 +70,5 @@ unspecified
value value
visible visible
xy xy
yes
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