kicad/new/sch_part.h

306 lines
6.5 KiB
C
Raw Normal View History

2010-12-27 16:49:39 +00:00
#ifndef SCH_PART_H_
#define SCH_PART_H_
#include <sch_lib.h>
2011-01-01 22:56:43 +00:00
2011-02-14 06:39:51 +00:00
//-----<temporary home for PART sub objects, move after stable>------------------
typedef wxPoint POINT;
#include <wx/gdicmn.h>
2011-02-28 05:45:58 +00:00
#include <deque>
2010-12-27 16:49:39 +00:00
namespace SCH {
2011-02-14 06:39:51 +00:00
class PART;
class SWEET_PARSER;
2011-01-01 22:56:43 +00:00
2011-02-14 06:39:51 +00:00
class BASE_GRAPHIC
{
2011-02-14 06:39:51 +00:00
friend class PART;
friend class SWEET_PARSER;
protected:
PART* owner;
public:
BASE_GRAPHIC( PART* aOwner ) :
owner( aOwner )
{}
virtual ~BASE_GRAPHIC() {}
};
2011-02-28 05:45:58 +00:00
typedef std::deque<POINT> POINTS;
2011-01-03 17:47:08 +00:00
2011-02-14 06:39:51 +00:00
class POLY_LINE : BASE_GRAPHIC
{
2011-02-14 06:39:51 +00:00
friend class PART;
friend class SWEET_PARSER;
protected:
2011-02-27 08:16:05 +00:00
double lineWidth;
2011-02-28 05:45:58 +00:00
int fillType; // T_none, T_filled, or T_transparent
2011-02-27 08:16:05 +00:00
POINTS pts;
2011-02-14 06:39:51 +00:00
public:
POLY_LINE( PART* aOwner ) :
BASE_GRAPHIC( aOwner )
{}
};
2011-02-28 05:45:58 +00:00
class BEZIER : POLY_LINE
{
friend class PART;
friend class SWEET_PARSER;
public:
BEZIER( PART* aOwner ) :
POLY_LINE( aOwner )
{}
};
2011-02-14 06:39:51 +00:00
2011-02-27 08:16:05 +00:00
class RECTANGLE : BASE_GRAPHIC
{
friend class PART;
friend class SWEET_PARSER;
protected:
double lineWidth;
int fillType; // T_none, T_filled, or T_transparent
POINT start;
POINT end;
public:
RECTANGLE( PART* aOwner ) :
BASE_GRAPHIC( aOwner )
{}
};
class CIRCLE : BASE_GRAPHIC
{
friend class PART;
friend class SWEET_PARSER;
protected:
double lineWidth;
int fillType; // T_none, T_filled, or T_transparent
POINT center;
int radius;
public:
CIRCLE( PART* aOwner ) :
BASE_GRAPHIC( aOwner )
{}
};
class ARC : BASE_GRAPHIC
{
friend class PART;
friend class SWEET_PARSER;
protected:
double lineWidth;
int fillType; // T_none, T_filled, or T_transparent
POINT pos;
int radius;
POINT start;
POINT end;
public:
ARC( PART* aOwner ) :
BASE_GRAPHIC( aOwner )
{}
2011-02-14 06:39:51 +00:00
};
2011-02-28 05:45:58 +00:00
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 )
*/
{}
};
2011-02-27 08:16:05 +00:00
} // namespace SCH
2011-02-14 06:39:51 +00:00
//-----</temporary home for PART sub objects, move after stable>-----------------
namespace SCH {
2011-02-28 05:45:58 +00:00
typedef std::deque< BASE_GRAPHIC* > GRAPHICS;
2011-02-14 06:39:51 +00:00
class LPID;
class SWEET_PARSER;
2010-12-27 16:49:39 +00:00
/**
* Class PART
* will have to be unified with what Wayne is doing. I want a separate copy
* here until I can get the state management correct. Since a PART only lives
* within a cache called a LIB, its constructor is private (only a LIB
* can instantiate one), and it exists in various states of freshness and
* completeness relative to the LIB_SOURCE within the LIB.
*/
class PART
{
2011-01-01 22:56:43 +00:00
friend class LIB; // is the owner of all PARTS, afterall
2011-02-14 06:39:51 +00:00
friend class SWEET_PARSER;
2010-12-27 16:49:39 +00:00
protected: // not likely to have C++ descendants, but protected none-the-less.
2011-01-01 22:56:43 +00:00
/// a protected constructor, only a LIB can instantiate a PART.
2011-01-03 17:47:08 +00:00
PART( LIB* aOwner, const STRING& aPartNameAndRev );
2011-01-01 22:56:43 +00:00
2011-02-14 06:39:51 +00:00
/**
* Function destroy
* clears out this object, deleting all graphics, all fields, all properties,
* etc.
*/
void clear();
2011-01-01 22:56:43 +00:00
/**
* Function inherit
* is a specialized assignment function that copies a specific subset, enough
* to fulfill the requirements of the Sweet s-expression language.
*/
void inherit( const PART& aBasePart );
2011-02-14 06:39:51 +00:00
POINT anchor;
2011-01-01 22:56:43 +00:00
//PART( LIB* aOwner );
2011-02-14 06:39:51 +00:00
LIB* owner; ///< which LIB am I a part of (pun if you want)
int contains; ///< has bits from Enum PartParts
2011-02-14 06:39:51 +00:00
STRING partNameAndRev; ///< example "passives/R[/revN..]", immutable.
2010-12-27 16:49:39 +00:00
2011-02-14 06:39:51 +00:00
LPID* extends; ///< of base part, NULL if none, otherwise I own it.
PART* base; ///< which PART am I extending, if any. no ownership.
2011-01-01 22:56:43 +00:00
/// encapsulate the old version deletion, take ownership of @a aLPID
void setExtends( LPID* aLPID );
2010-12-27 16:49:39 +00:00
/// s-expression text for the part, initially empty, and read in as this part
/// actually becomes cached in RAM.
2011-02-14 06:39:51 +00:00
STRING body;
2010-12-27 16:49:39 +00:00
2011-01-03 17:47:08 +00:00
// bool cachedRevisions; ///< allows lazy loading of revision of this same part name
2011-01-01 22:56:43 +00:00
2010-12-27 16:49:39 +00:00
// 3 separate lists for speed:
/// A property list.
2011-02-14 06:39:51 +00:00
//PROPERTIES properties;
2010-12-27 16:49:39 +00:00
2011-02-28 05:45:58 +00:00
/**
* Member graphics
* owns : POLY_LINE, RECTANGLE, CIRCLE, ARC, BEZIER, and GR_TEXT objects.
*/
2011-02-14 06:39:51 +00:00
GRAPHICS graphics;
2010-12-27 16:49:39 +00:00
/// A pin list
//PINS pins;
/// Alternate body forms.
//ALTERNATES alternates;
2011-02-27 08:16:05 +00:00
// mandatory properties
wxString value;
wxString footprint;
wxString model;
wxString keywords;
2010-12-27 16:49:39 +00:00
public:
2011-02-14 06:39:51 +00:00
virtual ~PART();
2011-01-01 22:56:43 +00:00
PART& operator=( const PART& other );
2010-12-27 16:49:39 +00:00
/**
* Function Owner
* returns the LIB* owner of this part.
*/
LIB* Owner() { return owner; }
/**
* Function Parse
* translates a Sweet string into a binary form that is represented
2010-12-27 16:49:39 +00:00
* by the normal fields of this class. Parse is expected to call Inherit()
* if this part extends any other.
*
2011-02-14 06:39:51 +00:00
* @param aParser is an instance of SWEET_PARSER, rewound at the first line.
*
2011-01-04 18:53:11 +00:00
* @param aLibTable is the LIB_TABLE "view" that is in effect for inheritance,
* and comes from the big containing SCHEMATIC object.
2010-12-27 16:49:39 +00:00
*/
2011-02-14 06:39:51 +00:00
void Parse( SWEET_PARSER* aParser, LIB_TABLE* aLibTable ) throw( IO_ERROR, PARSE_ERROR );
2010-12-27 16:49:39 +00:00
2011-02-27 08:16:05 +00:00
void SetValue( const wxString& aValue )
{
value = aValue;
}
const wxString& GetValue()
{
return value;
}
void SetFootprint( const wxString& aFootprint )
{
footprint = aFootprint;
}
const wxString& GetFootprint()
{
return footprint;
}
void SetModel( const wxString& aModel )
{
model = aModel;
}
const wxString& GetModel()
{
return model;
}
/*
void SetBody( const STR_UTF& aSExpression )
{
body = aSExpression;
}
*/
2010-12-27 16:49:39 +00:00
};
} // namespace PART
#endif // SCH_PART_