2010-12-14 15:56:30 +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-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
|
|
|
*/
|
2011-04-27 19:44:32 +00:00
|
|
|
class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2010-12-07 16:10:42 +00:00
|
|
|
int m_id; ///< @see enum NumFieldType
|
|
|
|
wxString m_name; ///< Name (not the field text value itself, that is .m_Text)
|
|
|
|
|
|
|
|
wxString m_savedText; ///< Temporary storage for the string when edition.
|
|
|
|
bool m_rotate; ///< Flag to indicate a rotation occurred while editing.
|
|
|
|
bool m_updateText; ///< Flag to indicate text change occurred while editing.
|
2010-10-20 20:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the field.
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
|
2010-10-20 20:24:26 +00:00
|
|
|
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:
|
|
|
|
|
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
|
2010-12-07 16:10:42 +00:00
|
|
|
* when the m_name member is empty.
|
2010-10-22 12:11:52 +00:00
|
|
|
*
|
2011-02-08 12:01:14 +00:00
|
|
|
* @param aTranslate = true to return translated field name (default)
|
|
|
|
* false to return the english name
|
|
|
|
* (usefull when the name is used as keyword in netlists ...)
|
2010-10-22 12:11:52 +00:00
|
|
|
* @return Name of the field.
|
|
|
|
*/
|
2011-02-08 12:01:14 +00:00
|
|
|
wxString GetName(bool aTranslate = true) const;
|
2010-12-07 16:10:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetName
|
|
|
|
*
|
|
|
|
* Sets a user definable field name to \a aName.
|
|
|
|
*
|
|
|
|
* Reserved fields such as value and reference are not renamed. If the field name is
|
|
|
|
* changed, the field modified flag is set. If the field is the child of a component,
|
|
|
|
* the parent component's modified flag is also set.
|
|
|
|
*
|
|
|
|
* @param aName - User defined field name.
|
|
|
|
*/
|
|
|
|
void SetName( const wxString& aName );
|
|
|
|
|
|
|
|
int GetId() { return m_id; }
|
|
|
|
|
|
|
|
void SetId( int aId ) { m_id = aId; }
|
2010-10-22 12:11:52 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2011-04-18 20:22:17 +00:00
|
|
|
* Function GetPenSize virtual
|
2009-06-30 17:57:27 +00:00
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2011-04-18 20:22:17 +00:00
|
|
|
virtual int GetPenSize( ) const;
|
2009-06-30 17:57:27 +00:00
|
|
|
|
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-12-20 19:18:20 +00:00
|
|
|
/**
|
|
|
|
* Function IsVoid
|
|
|
|
* @return true if the field value is void (no text in this field)
|
|
|
|
*/
|
|
|
|
bool IsVoid()
|
|
|
|
{
|
|
|
|
return m_Text.IsEmpty();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
virtual EDA_RECT GetBoundingBox() const;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2010-11-17 18:41:20 +00:00
|
|
|
/**
|
|
|
|
* Displays info (type, part convert filed name and value)
|
|
|
|
* in msg panel
|
|
|
|
* @param aFrame = main frame where the message manel info is.
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
|
2010-11-17 18:41:20 +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.
|
|
|
|
*
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aPosition A point to test in field coordinate system
|
2009-10-30 19:26:25 +00:00
|
|
|
* @return True if a hit, else false
|
2008-12-31 09:27:19 +00:00
|
|
|
*/
|
2010-12-14 15:56:30 +00:00
|
|
|
bool HitTest( const wxPoint& aPosition );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
/**
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aPosition = a wxPoint to test
|
2009-10-30 19:26:25 +00:00
|
|
|
* @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
|
2010-12-14 15:56:30 +00:00
|
|
|
* @return True if the point \a aPosition is near this object
|
2009-10-30 19:26:25 +00:00
|
|
|
*/
|
2010-12-14 15:56:30 +00:00
|
|
|
virtual bool HitTest( wxPoint aPosition, 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
|
|
|
{
|
2010-12-07 16:10:42 +00:00
|
|
|
m_id = field.m_id;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_Text = field.m_Text;
|
2010-12-07 16:10:42 +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;
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = field.m_Thickness;
|
2009-04-05 20:49:15 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
/**
|
2011-04-27 19:44:32 +00:00
|
|
|
* See LIB_ITEM::BeginEdit().
|
2010-10-20 20:24:26 +00:00
|
|
|
*/
|
|
|
|
void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) );
|
|
|
|
|
|
|
|
/**
|
2011-04-27 19:44:32 +00:00
|
|
|
* See LIB_ITEM::ContinueEdit().
|
2010-10-20 20:24:26 +00:00
|
|
|
*/
|
|
|
|
bool ContinueEdit( const wxPoint aNextPoint );
|
|
|
|
|
|
|
|
/**
|
2011-04-27 19:44:32 +00:00
|
|
|
* See LIB_ITEM::AbortEdit().
|
2010-10-20 20:24:26 +00:00
|
|
|
*/
|
|
|
|
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 );
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
virtual wxString GetSelectMenuText() const;
|
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
virtual BITMAP_DEF GetMenuImage() const { return move_field_xpm; }
|
2011-04-27 19:44:32 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
protected:
|
2011-04-27 19:44:32 +00:00
|
|
|
virtual EDA_ITEM* doClone() const;
|
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.
|
|
|
|
*/
|
2011-04-27 19:44:32 +00:00
|
|
|
virtual int DoCompare( const LIB_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 );
|
2011-03-29 19:33:07 +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 );
|
2011-05-20 18:29:35 +00:00
|
|
|
virtual void DoMirrorVertical( const wxPoint& aCenter );
|
2011-05-22 19:08:34 +00:00
|
|
|
virtual void DoRotate( const wxPoint& aCenter, bool aRotateCCW = true );
|
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-11-27 13:09:18 +00:00
|
|
|
virtual int DoGetWidth( void ) const { return m_Thickness; }
|
|
|
|
virtual void DoSetWidth( int width ) { m_Thickness = width; }
|
2008-12-31 09:27:19 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
typedef std::vector< LIB_FIELD > LIB_FIELDS;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
#endif // CLASS_LIBENTRY_FIELDS_H
|