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))"
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))"
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
......@@ -20,10 +21,24 @@ for C in ${CATEGORIES}; do
for P in ${PARTS}; 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
# 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
......@@ -53,6 +53,7 @@ void PART::clear()
extends = 0;
}
// graphics objects I own, and the container will not destroy them:
for( GRAPHICS::iterator it = graphics.begin(); it != graphics.end(); ++it )
delete *it;
graphics.clear();
......
......@@ -10,7 +10,7 @@
typedef wxPoint POINT;
#include <wx/gdicmn.h>
#include <vector>
#include <deque>
namespace SCH {
......@@ -34,7 +34,7 @@ public:
virtual ~BASE_GRAPHIC() {}
};
typedef std::vector<POINT> POINTS;
typedef std::deque<POINT> POINTS;
class POLY_LINE : BASE_GRAPHIC
{
......@@ -43,6 +43,7 @@ class POLY_LINE : BASE_GRAPHIC
protected:
double lineWidth;
int fillType; // T_none, T_filled, or T_transparent
POINTS pts;
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
{
......@@ -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
......@@ -115,7 +156,7 @@ public:
namespace SCH {
typedef std::vector< BASE_GRAPHIC* > GRAPHICS;
typedef std::deque< BASE_GRAPHIC* > GRAPHICS;
class LPID;
class SWEET_PARSER;
......@@ -180,7 +221,10 @@ protected: // not likely to have C++ descendants, but protected none-the-le
/// A property list.
//PROPERTIES properties;
/// A drawing list for graphics
/**
* Member graphics
* owns : POLY_LINE, RECTANGLE, CIRCLE, ARC, BEZIER, and GR_TEXT objects.
*/
GRAPHICS graphics;
/// A pin list
......
......@@ -180,6 +180,9 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
if( tok == T_LEFT )
tok = NextTok();
// because exceptions are thrown, any 'new' allocation has to be stored
// somewhere other than on the stack, ASAP.
switch( tok )
{
default:
......@@ -233,6 +236,20 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
parseArc( arc );
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:
if( contains & PB(VALUE) )
Duplicate( tok );
......@@ -263,7 +280,6 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
NeedRIGHT();
break;
/*
case T_keywords:
break;
......@@ -295,11 +311,6 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E
case T_route_pin_swap:
break;
case T_bezier:
break;
case T_text:
break;
*/
// 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
void SWEET_PARSER::parsePolyLine( POLY_LINE* me )
{
T tok;
int count;
int count = 0;
bool sawWidth = false;
bool sawFill = false;
NeedLEFT();
while( ( tok = NextTok() ) != T_RIGHT )
......@@ -332,13 +345,18 @@ void SWEET_PARSER::parsePolyLine( POLY_LINE* me )
switch( tok )
{
case T_line_width:
if( sawWidth )
Duplicate( tok );
NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL );
NeedRIGHT();
sawWidth = true;
break;
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 )
Expecting( T_LEFT );
......@@ -357,10 +375,26 @@ void SWEET_PARSER::parsePolyLine( POLY_LINE* me )
NeedRIGHT();
}
if( count < 2 )
Expecting( ">= 2 pts" );
break;
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;
default:
......@@ -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 )
{
T tok;
......@@ -391,8 +431,8 @@ void SWEET_PARSER::parseRectangle( RECTANGLE* me )
Duplicate( tok );
NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL );
sawWidth = true;
NeedRIGHT();
sawWidth = true;
break;
case T_fill:
......@@ -463,8 +503,8 @@ void SWEET_PARSER::parseCircle( CIRCLE* me )
Duplicate( tok );
NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL );
sawWidth = true;
NeedRIGHT();
sawWidth = true;
break;
case T_fill:
......@@ -535,8 +575,8 @@ void SWEET_PARSER::parseArc( ARC* me )
Duplicate( tok );
NeedNUMBER( "line_width" );
me->lineWidth = strtod( CurText(), NULL );
sawWidth = true;
NeedRIGHT();
sawWidth = true;
break;
case T_fill:
......@@ -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 {
class LIB_TABLE;
class PART;
// GRAPHICS
class POLY_LINE;
class RECTANGLE;
class CIRCLE;
class ARC;
class BEZIER;
class GR_TEXT;
/**
......@@ -57,9 +61,11 @@ class SWEET_PARSER : public SWEET_LEXER
void parseExtends( PART* me );
void parsePolyLine( POLY_LINE* me );
void parseBezier( BEZIER* me );
void parseRectangle( RECTANGLE* me );
void parseCircle( CIRCLE* me );
void parseArc( ARC* me );
void parseText( GR_TEXT* me );
public:
......
......@@ -4,6 +4,7 @@ arc
at
bezier
bidirectional
bottom
center
circle
clock
......@@ -23,11 +24,13 @@ inverted
inverted_clk
justify
keywords
left
length
line
line_width
model
name
no
none
number
open_collector
......@@ -51,12 +54,14 @@ pts
radius
rectangle
reference
right
route_alt_swap
route_pin_swap
size
start
start_angle
text
top
transparent
tristate
unconnected
......@@ -65,3 +70,5 @@ unspecified
value
visible
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