2011-10-31 20:49:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file lib_field.h
|
|
|
|
*/
|
2008-12-31 09:27:19 +00:00
|
|
|
|
|
|
|
#ifndef CLASS_LIBENTRY_FIELDS_H
|
|
|
|
#define CLASS_LIBENTRY_FIELDS_H
|
|
|
|
|
2012-04-12 21:31:31 +00:00
|
|
|
#include <eda_text.h>
|
2012-01-23 04:33:36 +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.
|
2011-10-31 20:49:48 +00:00
|
|
|
* <p>
|
|
|
|
* A field is a string linked to a component. Unlike purely graphical text, fields can
|
|
|
|
* be used in netlist generation and other tools (BOM).
|
|
|
|
*
|
|
|
|
* The first 4 fields have a special meaning:
|
|
|
|
*
|
|
|
|
* 0 = REFERENCE
|
|
|
|
* 1 = VALUE
|
|
|
|
* 2 = FOOTPRINT (default Footprint)
|
|
|
|
* 3 = DOCUMENTATION (user doc link)
|
|
|
|
*
|
|
|
|
* others = free fields
|
|
|
|
* </p>
|
|
|
|
*
|
2010-06-17 16:30:10 +00:00
|
|
|
* @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-10-31 20:49:48 +00:00
|
|
|
* <p>
|
|
|
|
* If \a aData not NULL, \a aData must point a wxString which is used instead of
|
|
|
|
* the m_Text
|
|
|
|
* </p>
|
2010-10-20 20:24:26 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, void* aData,
|
2012-09-01 13:38:27 +00:00
|
|
|
const TRANSFORM& aTransform );
|
2010-10-20 20:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 );
|
2012-01-09 20:26:55 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD( LIB_COMPONENT * aParent, int idfield = 2 );
|
2012-01-09 20:26:55 +00:00
|
|
|
|
|
|
|
// Do not create a copy constructor. The one generated by the compiler is adequate.
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
~LIB_FIELD();
|
2009-10-20 19:36:58 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
wxString GetClass() const
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
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
|
|
|
*
|
2012-03-26 23:47:08 +00:00
|
|
|
* @param aTranslate True to return translated field name (default). False to return
|
|
|
|
* the english name (useful when the name is used as keyword in
|
|
|
|
* netlists ...)
|
2010-10-22 12:11:52 +00:00
|
|
|
* @return Name of the field.
|
|
|
|
*/
|
2012-03-26 23:47:08 +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
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
int GetPenSize( ) const;
|
2009-06-30 17:57:27 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
bool Save( OUTPUTFORMATTER& aFormatter );
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
bool Load( LINE_READER& aLineReader, 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.
|
|
|
|
*
|
2012-03-26 23:47:08 +00:00
|
|
|
* @param aTarget Target field to copy values to.
|
2008-12-31 09:27:19 +00:00
|
|
|
*/
|
2011-10-31 20:49:48 +00:00
|
|
|
void Copy( LIB_FIELD* aTarget ) const;
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2011-10-31 20:49:48 +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;
|
|
|
|
}
|
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
EDA_RECT GetBoundingBox() const;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
|
2010-11-17 18:41:20 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
bool HitTest( const wxPoint& aPosition );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
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.
|
|
|
|
*
|
2011-10-31 20:49:48 +00:00
|
|
|
* @todo This should be handled by the field object.
|
|
|
|
*
|
2009-09-25 18:49:04 +00:00
|
|
|
* @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
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T GetDefaultColor();
|
2010-10-20 20:24:26 +00:00
|
|
|
|
|
|
|
void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) );
|
|
|
|
|
|
|
|
bool ContinueEdit( const wxPoint aNextPoint );
|
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2011-10-31 20:49:48 +00:00
|
|
|
* This method does more than just set the set the field text. There are special
|
2010-10-22 12:11:52 +00:00
|
|
|
* 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 );
|
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
void SetOffset( const wxPoint& aOffset );
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
bool Inside( EDA_RECT& aRect ) const;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
void Move( const wxPoint& aPosition );
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
wxPoint GetPosition() const { return m_Pos; }
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
void MirrorHorizontal( const wxPoint& aCenter );
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
void MirrorVertical( const wxPoint& aCenter );
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
void Rotate( const wxPoint& aCenter, bool aRotateCCW = true );
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
|
|
|
|
const TRANSFORM& aTransform );
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
int GetWidth() const { return m_Thickness; }
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
void SetWidth( int aWidth ) { m_Thickness = aWidth; }
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
wxString GetSelectMenuText() const;
|
2011-04-27 19:44:32 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
BITMAP_DEF GetMenuImage() const { return move_field_xpm; }
|
2011-04-27 19:44:32 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
EDA_ITEM* Clone() const;
|
2012-03-17 14:39:27 +00:00
|
|
|
|
2012-02-27 23:02:08 +00:00
|
|
|
private:
|
2009-10-05 17:52:41 +00:00
|
|
|
|
|
|
|
/**
|
2012-03-26 23:47:08 +00:00
|
|
|
* @copydoc LIB_ITEM::compare()
|
2009-10-05 17:52:41 +00:00
|
|
|
*
|
2012-03-26 23:47:08 +00:00
|
|
|
* The field specific sort order is as follows:
|
2009-10-05 17:52:41 +00:00
|
|
|
*
|
|
|
|
* - Field ID, REFERENCE, VALUE, etc.
|
|
|
|
* - Field string, case insensitive compare.
|
|
|
|
* - Field horizontal (X) position.
|
|
|
|
* - Field vertical (Y) position.
|
|
|
|
* - Field width.
|
|
|
|
* - Field height.
|
|
|
|
*/
|
2012-03-26 23:47:08 +00:00
|
|
|
int compare( const LIB_ITEM& aOther ) const;
|
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
|