2008-12-31 09:27:19 +00:00
|
|
|
/**************************************************************/
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Lib component definitions (libentry) definition of fields */
|
2008-12-31 09:27:19 +00:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
|
|
#ifndef CLASS_LIBENTRY_FIELDS_H
|
|
|
|
#define CLASS_LIBENTRY_FIELDS_H
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
#include "program.h"
|
2010-10-08 20:40:57 +00:00
|
|
|
#include "lib_draw_item.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
/**
|
|
|
|
* Class LIB_FIELD
|
|
|
|
* is used in symbol libraries. At least MANDATORY_FIELDS are always present
|
|
|
|
* in a ram resident library symbol. All constructors must ensure this because
|
|
|
|
* the component property editor assumes it.
|
|
|
|
* @see enum NumFieldType
|
2008-12-31 09:27:19 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
class LIB_FIELD : public LIB_DRAW_ITEM, public EDA_TextStruct
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2010-10-22 12:11:52 +00:00
|
|
|
wxString m_savedText; ///< Temporary storage for the string when edition.
|
2010-10-20 20:24:26 +00:00
|
|
|
bool m_rotate; ///< Flag to indicate a rotation occurred while editing.
|
2010-10-22 12:11:52 +00:00
|
|
|
bool m_updateText; ///< Flag to indicate text change occurred while editing.
|
2010-10-20 20:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the field.
|
|
|
|
*/
|
|
|
|
void drawGraphic( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset,
|
|
|
|
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the new circle at \a aPosition when editing.
|
|
|
|
*
|
|
|
|
* @param aPosition - The position to edit the circle in drawing coordinates.
|
|
|
|
*/
|
|
|
|
void calcEdit( const wxPoint& aPosition );
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
public:
|
2010-06-17 16:30:10 +00:00
|
|
|
int m_FieldId; ///< @see enum NumFieldType
|
|
|
|
|
|
|
|
wxString m_Name; ///< Name (not the field text value itself, that is .m_Text)
|
2008-12-31 09:27:19 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD( int idfield = 2 );
|
|
|
|
LIB_FIELD( LIB_COMPONENT * aParent, int idfield = 2 );
|
|
|
|
LIB_FIELD( const LIB_FIELD& field );
|
|
|
|
~LIB_FIELD();
|
2009-10-20 19:36:58 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
virtual wxString GetClass() const
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
return wxT( "LIB_FIELD" );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
/**
|
|
|
|
* Object constructor initialization helper.
|
|
|
|
*/
|
|
|
|
void Init( int idfield );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2010-10-22 12:11:52 +00:00
|
|
|
/**
|
|
|
|
* Returns the field name.
|
|
|
|
*
|
|
|
|
* The first four field IDs are reserved and therefore always return their respective
|
|
|
|
* names. The user definable fields will return FieldN where N is the ID of the field
|
|
|
|
* when the m_Name member is empty.
|
|
|
|
*
|
|
|
|
* @return Name of the field.
|
|
|
|
*/
|
|
|
|
wxString GetName();
|
|
|
|
|
2009-06-30 17:57:27 +00:00
|
|
|
/** Function GetPenSize virtual pure
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
|
|
|
int GetPenSize( );
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
/**
|
2009-10-30 19:26:25 +00:00
|
|
|
* Writes field object out to a FILE in "*.lib" format.
|
|
|
|
*
|
2008-12-31 09:27:19 +00:00
|
|
|
* @param aFile The FILE to write to.
|
2009-10-30 19:26:25 +00:00
|
|
|
* @return True if success writing else false.
|
2008-12-31 09:27:19 +00:00
|
|
|
*/
|
2009-10-30 19:26:25 +00:00
|
|
|
virtual bool Save( FILE* aFile );
|
2009-04-05 20:49:15 +00:00
|
|
|
virtual bool Load( char* line, wxString& errorMsg );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-10-30 19:26:25 +00:00
|
|
|
/**
|
|
|
|
* Copy parameters of this field to another field. Pointers are not copied.
|
|
|
|
*
|
|
|
|
* @param aTarget = Target field to copy values to.
|
2008-12-31 09:27:19 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
void Copy( LIB_FIELD* aTarget ) const;
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void SetFields( const std::vector <LIB_FIELD> aFields );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
/**
|
|
|
|
* Function IsVisible
|
2009-12-30 18:06:12 +00:00
|
|
|
* @return true is this field is visible, false if flagged invisible
|
|
|
|
*/
|
|
|
|
bool IsVisible()
|
|
|
|
{
|
|
|
|
return (m_Attributs & TEXT_NO_VISIBLE) == 0 ? true : false;
|
|
|
|
}
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
/**
|
|
|
|
* Return the bounding rectangle of the field text.
|
2009-10-30 19:26:25 +00:00
|
|
|
* @return Bounding rectangle.
|
2009-09-29 18:38:21 +00:00
|
|
|
*/
|
2009-10-01 14:17:47 +00:00
|
|
|
virtual EDA_Rect GetBoundingBox();
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
/**
|
2009-10-30 19:26:25 +00:00
|
|
|
* Test if the given point is within the bounds of this object.
|
|
|
|
*
|
|
|
|
* @param refPos A point to test in field coordinate system
|
|
|
|
* @return True if a hit, else false
|
2008-12-31 09:27:19 +00:00
|
|
|
*/
|
2008-12-31 15:01:29 +00:00
|
|
|
bool HitTest( const wxPoint& refPos );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
/**
|
2009-10-30 19:26:25 +00:00
|
|
|
* @param aPosRef = a wxPoint to test
|
|
|
|
* @param aThreshold = max distance to this object (usually the half
|
|
|
|
* thickness of a line)
|
2010-10-20 20:24:26 +00:00
|
|
|
* @param aTransform = the transform matrix
|
2009-10-30 19:26:25 +00:00
|
|
|
* @return True if the point aPosRef is near this object
|
|
|
|
*/
|
2010-10-20 20:24:26 +00:00
|
|
|
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
|
2009-06-13 17:06:07 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void operator=( const LIB_FIELD& field )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
m_FieldId = field.m_FieldId;
|
|
|
|
m_Text = field.m_Text;
|
2010-02-22 19:56:32 +00:00
|
|
|
m_Name = field.m_Name;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_Pos = field.m_Pos;
|
|
|
|
m_Size = field.m_Size;
|
|
|
|
m_Width = field.m_Width;
|
|
|
|
m_Orient = field.m_Orient;
|
|
|
|
m_Mirror = field.m_Mirror;
|
|
|
|
m_Attributs = field.m_Attributs;
|
|
|
|
m_Italic = field.m_Italic;
|
2009-05-28 17:39:40 +00:00
|
|
|
m_Bold = field.m_Bold;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_HJustify = field.m_HJustify;
|
|
|
|
m_VJustify = field.m_VJustify;
|
2009-06-18 13:30:52 +00:00
|
|
|
m_Parent = field.m_Parent;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-09-02 18:12:45 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
/**
|
|
|
|
* Return the text of a field.
|
|
|
|
*
|
|
|
|
* If the field is the reference field, the unit number is used to
|
|
|
|
* create a pseudo reference text. If the base reference field is U,
|
|
|
|
* the string U?A will be returned for unit = 1.
|
|
|
|
*
|
|
|
|
* @param unit - The package unit number. Only effects reference field.
|
2009-10-30 19:26:25 +00:00
|
|
|
* @return Field text.
|
2009-09-25 18:49:04 +00:00
|
|
|
*/
|
|
|
|
wxString GetFullText( int unit = 1 );
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2010-10-20 20:24:26 +00:00
|
|
|
int GetDefaultColor();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See LIB_DRAW_ITEM::BeginEdit().
|
|
|
|
*/
|
|
|
|
void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See LIB_DRAW_ITEM::ContinueEdit().
|
|
|
|
*/
|
|
|
|
bool ContinueEdit( const wxPoint aNextPoint );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See LIB_DRAW_ITEM::AbortEdit().
|
|
|
|
*/
|
|
|
|
void EndEdit( const wxPoint& aPosition, bool aAbort = false );
|
|
|
|
|
|
|
|
void Rotate();
|
|
|
|
|
2010-10-22 12:11:52 +00:00
|
|
|
/**
|
|
|
|
* Sets the field text to \a aText.
|
|
|
|
*
|
|
|
|
* This method does more than juat set the set the field text. There are special
|
|
|
|
* cases when changing the text string alone is not enough. If the field is the
|
|
|
|
* value field, the parent component's name is changed as well. If the field is
|
|
|
|
* being moved, the name change must be delayed until the next redraw to prevent
|
|
|
|
* drawing artifacts.
|
|
|
|
*
|
|
|
|
* @param aText - New text value.
|
|
|
|
*/
|
|
|
|
void SetText( const wxString& aText );
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
protected:
|
2009-09-25 18:49:04 +00:00
|
|
|
virtual LIB_DRAW_ITEM* DoGenCopy();
|
2009-10-05 17:52:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide the field draw object specific comparison.
|
|
|
|
*
|
|
|
|
* The sort order for field is as follows:
|
|
|
|
*
|
|
|
|
* - Field ID, REFERENCE, VALUE, etc.
|
|
|
|
* - Field string, case insensitive compare.
|
|
|
|
* - Field horizontal (X) position.
|
|
|
|
* - Field vertical (Y) position.
|
|
|
|
* - Field width.
|
|
|
|
* - Field height.
|
|
|
|
*/
|
2009-10-01 14:17:47 +00:00
|
|
|
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
virtual void DoOffset( const wxPoint& offset );
|
2010-10-25 15:43:42 +00:00
|
|
|
virtual bool DoTestInside( EDA_Rect& rect ) const;
|
2009-09-25 18:49:04 +00:00
|
|
|
virtual void DoMove( const wxPoint& newPosition );
|
2010-10-25 15:43:42 +00:00
|
|
|
virtual wxPoint DoGetPosition( void ) const { return m_Pos; }
|
2009-09-29 18:38:21 +00:00
|
|
|
virtual void DoMirrorHorizontal( const wxPoint& center );
|
2009-10-05 17:52:41 +00:00
|
|
|
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
|
2010-10-20 20:24:26 +00:00
|
|
|
const TRANSFORM& aTransform );
|
2010-10-25 15:43:42 +00:00
|
|
|
virtual int DoGetWidth( void ) const { return m_Width; }
|
2009-10-19 19:00:47 +00:00
|
|
|
virtual void DoSetWidth( int width ) { m_Width = width; }
|
2008-12-31 09:27:19 +00:00
|
|
|
};
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
typedef std::vector< LIB_FIELD > LIB_FIELD_LIST;
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
#endif // CLASS_LIBENTRY_FIELDS_H
|