Commit e737a308 authored by Dick Hollenbeck's avatar Dick Hollenbeck

fill out more SWEET "inherits" support

parent 3d8c48e0
...@@ -96,6 +96,7 @@ for C in ${CATEGORIES}; do ...@@ -96,6 +96,7 @@ for C in ${CATEGORIES}; do
mkdir -p $BASEDIR/$C mkdir -p $BASEDIR/$C
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)(datasheet http://favorite.pdf) echo "(part $C/$P (value 22)(footprint SM0805)(model Airplane)(datasheet http://favorite.pdf)
$REFERENCE $REFERENCE
...@@ -119,6 +120,7 @@ for C in ${CATEGORIES}; do ...@@ -119,6 +120,7 @@ for C in ${CATEGORIES}; do
$PIN_MERGE $PIN_MERGE
)" > $BASEDIR/$C/$P.part.$R )" > $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)(datasheet http://favorite.pdf) echo "(part $C/$P (value 22)(footprint SM0805)(model Airplane)(datasheet http://favorite.pdf)
$REFERENCE $REFERENCE
...@@ -141,6 +143,8 @@ for C in ${CATEGORIES}; do ...@@ -141,6 +143,8 @@ for C in ${CATEGORIES}; do
$PIN_DELETE $PIN_DELETE
$PIN_MERGE $PIN_MERGE
)" > $BASEDIR/$C/$P.part )" > $BASEDIR/$C/$P.part
done done
done done
...@@ -155,6 +155,25 @@ PROPERTY* PART::FieldLookup( PROP_ID aPropertyId ) ...@@ -155,6 +155,25 @@ PROPERTY* PART::FieldLookup( PROP_ID aPropertyId )
return p; return p;
} }
PROPERTY& PROPERTY::operator = ( const PROPERTY& r )
{
*(BASE_GRAPHIC*) this = (BASE_GRAPHIC&) r;
name = r.name;
text = r.text;
delete effects;
if( r.effects )
effects = new TEXT_EFFECTS( *r.effects );
else
effects = 0;
return *this;
}
PINS::iterator PART::pinFindByPad( const wxString& aPad ) PINS::iterator PART::pinFindByPad( const wxString& aPad )
{ {
PINS::iterator it; PINS::iterator it;
...@@ -196,7 +215,6 @@ bool PART::PinDelete( const wxString& aPad ) ...@@ -196,7 +215,6 @@ bool PART::PinDelete( const wxString& aPad )
} }
PART::~PART() PART::~PART()
{ {
clear(); clear();
...@@ -210,25 +228,60 @@ void PART::setExtends( LPID* aLPID ) ...@@ -210,25 +228,60 @@ void PART::setExtends( LPID* aLPID )
} }
void PART::inherit( const PART& other ) void PART::inherit( const PART& r )
{ {
contains = other.contains; // Inherit can be called at any time, even from an interactive text
// editor, so cannot assume 'this' object is new. Clear it.
clear();
// copy anything inherited, such as drawables, properties, pins, etc. here
contains = r.contains;
base = &r;
// @todo copy the inherited drawables, properties, and pins here anchor = r.anchor;
for( int i=REFERENCE; i<END; ++i )
{
if( r.mandatory[i] )
mandatory[i] = (PROPERTY*) r.mandatory[i]->Clone( this );
}
for( PROPERTIES::const_iterator it = r.properties.begin(); it != r.properties.end(); ++it )
properties.push_back( (PROPERTY*) (*it)->Clone( this ) );
for( GRAPHICS::const_iterator it = r.graphics.begin(); it != r.graphics.end(); ++it )
graphics.push_back( (*it)->Clone( this ) );
for( PINS::const_iterator it = r.pins.begin(); it != r.pins.end(); ++it )
pins.push_back( (PIN*) (*it)->Clone( this ) );
/* not sure about this concept yet:
for( PART_REFS::const_iterator it = r.alternates.begin(); it != r.alternates.end(); ++it )
alternates.push_back( *it );
*/
for( KEYWORDS::const_iterator it = r.keywords.begin(); it != r.keywords.end(); ++it )
keywords.insert( *it );
for( MERGE_SETS::const_iterator it = r.pin_merges.begin(); it != r.pin_merges.end(); ++it )
{
pin_merges[ *it->first ] = * new MERGE_SET( *it->second );
}
} }
PART& PART::operator=( const PART& other ) PART& PART::operator=( const PART& r )
{ {
owner = other.owner; // maintain in concert with inherit(), which is a partial assignment operator.
partNameAndRev = other.partNameAndRev; inherit( r );
body = other.body;
base = other.base;
setExtends( other.extends ? new LPID( *other.extends ) : 0 ); owner = r.owner;
partNameAndRev = r.partNameAndRev;
body = r.body;
base = r.base;
// maintain in concert with inherit(), which is a partial assignment operator. setExtends( r.extends ? new LPID( *r.extends ) : 0 );
inherit( other );
return *this; return *this;
} }
......
...@@ -110,9 +110,15 @@ public: ...@@ -110,9 +110,15 @@ public:
wxPoint( x, y ) wxPoint( x, y )
{} {}
POINT( const POINT& r ) :
wxPoint( r )
{}
POINT() : POINT() :
wxPoint() wxPoint()
{} {}
// assume assignment operator is inherited.
}; };
}; };
...@@ -146,6 +152,7 @@ public: ...@@ -146,6 +152,7 @@ public:
int width; int width;
}; };
typedef float ANGLE; typedef float ANGLE;
typedef int STROKE; ///< will be a class someday, currently only line width typedef int STROKE; ///< will be a class someday, currently only line width
...@@ -172,6 +179,8 @@ public: ...@@ -172,6 +179,8 @@ public:
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
// trust compiler to write its own assignment operator for this class OK.
}; };
...@@ -193,6 +202,8 @@ struct TEXT_EFFECTS ...@@ -193,6 +202,8 @@ struct TEXT_EFFECTS
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
// trust compiler to write its own assignment operator for this class OK.
}; };
...@@ -200,7 +211,6 @@ struct TEXT_EFFECTS ...@@ -200,7 +211,6 @@ struct TEXT_EFFECTS
#define FILL_TYPE_DEFAULT PR::T_none ///< fillType defaut #define FILL_TYPE_DEFAULT PR::T_none ///< fillType defaut
class BASE_GRAPHIC class BASE_GRAPHIC
{ {
friend class PART; friend class PART;
...@@ -218,6 +228,14 @@ public: ...@@ -218,6 +228,14 @@ public:
virtual ~BASE_GRAPHIC() {} virtual ~BASE_GRAPHIC() {}
/**
* Function Clone
* invokes the copy constructor on a heap allocated object of this same
* type and creates a deep copy of 'this' into it
* @param aOwner is the owner of the returned, new object.
*/
virtual BASE_GRAPHIC* Clone( PART* aOwner ) const = 0;
static const char* ShowFill( int aFillType ) static const char* ShowFill( int aFillType )
{ {
return SWEET_LEXER::TokenName( PR::T( aFillType ) ); return SWEET_LEXER::TokenName( PR::T( aFillType ) );
...@@ -232,6 +250,7 @@ public: ...@@ -232,6 +250,7 @@ public:
{} {}
}; };
typedef std::deque<POINT> POINTS; typedef std::deque<POINT> POINTS;
class POLY_LINE : public BASE_GRAPHIC class POLY_LINE : public BASE_GRAPHIC
...@@ -257,8 +276,16 @@ public: ...@@ -257,8 +276,16 @@ public:
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
BASE_GRAPHIC* Clone( PART* aOwner ) const
{
POLY_LINE* n = new POLY_LINE( *this );
n->owner = aOwner;
return n;
}
}; };
class BEZIER : public POLY_LINE class BEZIER : public POLY_LINE
{ {
friend class PART; friend class PART;
...@@ -274,8 +301,16 @@ public: ...@@ -274,8 +301,16 @@ public:
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
BASE_GRAPHIC* Clone( PART* aOwner ) const
{
BEZIER* n = new BEZIER( *this );
n->owner = aOwner;
return n;
}
}; };
class RECTANGLE : public BASE_GRAPHIC class RECTANGLE : public BASE_GRAPHIC
{ {
friend class PART; friend class PART;
...@@ -297,6 +332,13 @@ public: ...@@ -297,6 +332,13 @@ public:
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
BASE_GRAPHIC* Clone( PART* aOwner ) const
{
RECTANGLE* n = new RECTANGLE( *this );
n->owner = aOwner;
return n;
}
}; };
...@@ -322,6 +364,13 @@ public: ...@@ -322,6 +364,13 @@ public:
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
BASE_GRAPHIC* Clone( PART* aOwner ) const
{
CIRCLE* n = new CIRCLE( *this );
n->owner = aOwner;
return n;
}
}; };
...@@ -349,6 +398,13 @@ public: ...@@ -349,6 +398,13 @@ public:
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
BASE_GRAPHIC* Clone( PART* aOwner ) const
{
ARC* n = new ARC( *this );
n->owner = aOwner;
return n;
}
}; };
...@@ -387,6 +443,13 @@ public: ...@@ -387,6 +443,13 @@ public:
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
BASE_GRAPHIC* Clone( PART* aOwner ) const
{
GR_TEXT* n = new GR_TEXT( *this );
n->owner = aOwner;
return n;
}
}; };
...@@ -416,6 +479,16 @@ public: ...@@ -416,6 +479,16 @@ public:
effects( 0 ) effects( 0 )
{} {}
PROPERTY( const PROPERTY& r ) :
BASE_GRAPHIC( NULL ),
effects( 0 )
{
// use assignment operator
*this = r;
}
PROPERTY& operator = ( const PROPERTY& r ); // @todo
~PROPERTY() ~PROPERTY()
{ {
clear(); clear();
...@@ -436,6 +509,13 @@ public: ...@@ -436,6 +509,13 @@ public:
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
BASE_GRAPHIC* Clone( PART* aOwner ) const
{
PROPERTY* n = new PROPERTY( *this );
n->owner = aOwner;
return n;
}
}; };
...@@ -488,6 +568,13 @@ public: ...@@ -488,6 +568,13 @@ public:
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ); throw( IO_ERROR );
BASE_GRAPHIC* Clone( PART* aOwner ) const
{
PIN* n = new PIN( *this );
n->owner = aOwner;
return n;
}
protected: protected:
POINT pos; POINT pos;
ANGLE angle; ANGLE angle;
...@@ -533,7 +620,6 @@ public: ...@@ -533,7 +620,6 @@ public:
{ {
} }
/** /**
* Function Lookup * Function Lookup
* returns the PART that this LPID refers to. Never returns NULL, because * returns the PART that this LPID refers to. Never returns NULL, because
...@@ -556,7 +642,6 @@ protected: ...@@ -556,7 +642,6 @@ protected:
typedef std::vector<PART_REF> PART_REFS; typedef std::vector<PART_REF> PART_REFS;
} // namespace SCH } // namespace SCH
...@@ -766,17 +851,15 @@ protected: // not likely to have C++ descendants, but protected none-the-le ...@@ -766,17 +851,15 @@ protected: // not likely to have C++ descendants, but protected none-the-le
*/ */
PINS::iterator pinFindByPad( const wxString& aPad ); PINS::iterator pinFindByPad( const wxString& aPad );
POINT anchor;
//PART( LIB* aOwner );
LIB* owner; ///< which LIB am I a part of (pun if you want) LIB* owner; ///< which LIB am I a part of (pun if you want)
int contains; ///< has bits from Enum PartParts int contains; ///< has bits from Enum PartParts
STRING partNameAndRev; ///< example "passives/R[/revN..]", immutable. STRING partNameAndRev; ///< example "passives/R[/revN..]", immutable.
LPID* extends; ///< of base part, NULL if none, otherwise I own it. LPID* extends; ///< of base part, NULL if none, otherwise I own it.
PART* base; ///< which PART am I extending, if any. no ownership. const PART* base; ///< which PART am I extending, if any. no ownership.
POINT anchor;
/// encapsulate the old version deletion, take ownership of @a aLPID /// encapsulate the old version deletion, take ownership of @a aLPID
void setExtends( LPID* aLPID ); void setExtends( LPID* aLPID );
......
...@@ -346,7 +346,7 @@ void SWEET_PARSER::parseExtends( PART* me ) ...@@ -346,7 +346,7 @@ void SWEET_PARSER::parseExtends( PART* me )
// we could be going in circles here, recursively, or too deep, set limits // we could be going in circles here, recursively, or too deep, set limits
// and disallow extending from self (even indirectly) // and disallow extending from self (even indirectly)
int extendsDepth = 0; int extendsDepth = 0;
for( PART* ancestor = base; ancestor && extendsDepth<MAX_INHERITANCE_NESTING; for( const PART* ancestor = base; ancestor && extendsDepth<MAX_INHERITANCE_NESTING;
++extendsDepth, ancestor = ancestor->base ) ++extendsDepth, ancestor = ancestor->base )
{ {
if( ancestor == me ) if( ancestor == me )
......
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