2011-10-31 20:49:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-01-24 17:23:57 +00:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2022-12-08 23:56:55 +00:00
|
|
|
* Copyright (C) 2022 CERN
|
|
|
|
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-31 20:49:48 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2019-08-15 07:09:52 +00:00
|
|
|
#include <lib_item.h>
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
class SCH_LEGACY_PLUGIN_CACHE;
|
|
|
|
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
/**
|
2021-05-05 21:41:51 +00:00
|
|
|
* Field object used in symbol libraries. At least MANDATORY_FIELDS are always present in a
|
|
|
|
* RAM-resident library symbol. All constructors must ensure this because the symbol property
|
|
|
|
* editor assumes it.
|
2011-10-31 20:49:48 +00:00
|
|
|
* <p>
|
2021-05-05 21:41:51 +00:00
|
|
|
* A field is a string linked to a symbol. Unlike purely graphical text, fields can be used in
|
|
|
|
* netlist generation and other tools (BOM).
|
2011-10-31 20:49:48 +00:00
|
|
|
*
|
|
|
|
* The first 4 fields have a special meaning:
|
|
|
|
*
|
2020-11-12 21:31:41 +00:00
|
|
|
* 0 = REFERENCE_FIELD
|
|
|
|
* 1 = VALUE_FIELD
|
|
|
|
* 2 = FOOTPRINT_FIELD (default Footprint)
|
|
|
|
* 3 = DATASHEET_FIELD (user doc link)
|
2011-10-31 20:49:48 +00:00
|
|
|
*
|
|
|
|
* others = free fields
|
|
|
|
* </p>
|
|
|
|
*
|
2021-02-28 13:28:23 +00:00
|
|
|
* @see enum MANDATORY_FIELD_T
|
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
|
|
|
{
|
|
|
|
public:
|
2021-12-12 22:01:13 +00:00
|
|
|
LIB_FIELD( int aId = 2 );
|
2012-01-09 20:26:55 +00:00
|
|
|
|
2021-12-12 22:01:13 +00:00
|
|
|
LIB_FIELD( int aId, const wxString& aName );
|
2019-01-10 05:42:14 +00:00
|
|
|
|
2022-12-08 23:56:55 +00:00
|
|
|
LIB_FIELD( LIB_SYMBOL* aParent, int aId = 2, const wxString& aName = wxEmptyString );
|
2012-01-09 20:26:55 +00:00
|
|
|
|
|
|
|
// Do not create a copy constructor. The one generated by the compiler is adequate.
|
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
wxString GetClass() const override
|
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
|
|
|
}
|
|
|
|
|
2020-10-27 11:03:35 +00:00
|
|
|
wxString GetTypeName() const override
|
2018-01-25 23:49:04 +00:00
|
|
|
{
|
|
|
|
return _( "Field" );
|
|
|
|
}
|
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
/**
|
|
|
|
* Object constructor initialization helper.
|
|
|
|
*/
|
2021-12-12 22:01:13 +00:00
|
|
|
void Init( int aId );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2010-10-22 12:11:52 +00:00
|
|
|
/**
|
2022-05-12 11:05:06 +00:00
|
|
|
* Return the field name (not translated).
|
2010-10-22 12:11:52 +00:00
|
|
|
*
|
|
|
|
* The first four field IDs are reserved and therefore always return their respective
|
2020-03-26 11:02:59 +00:00
|
|
|
* names.
|
2010-10-22 12:11:52 +00:00
|
|
|
*
|
2020-03-26 11:02:59 +00:00
|
|
|
* The user definable fields will return FieldN where N is the ID of the field when the
|
2021-12-12 22:01:13 +00:00
|
|
|
* m_name member is empty unless false is passed to \a aUseDefaultName.
|
2010-10-22 12:11:52 +00:00
|
|
|
*/
|
2020-03-26 11:02:59 +00:00
|
|
|
wxString GetName( bool aUseDefaultName = true ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a non-language-specific name for a field which can be used for storage, variable
|
|
|
|
* look-up, etc.
|
|
|
|
*/
|
|
|
|
wxString GetCanonicalName() const;
|
2010-12-07 16:10:42 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Set a user definable field name to \a aName.
|
2010-12-07 16:10:42 +00:00
|
|
|
*
|
|
|
|
* Reserved fields such as value and reference are not renamed. If the field name is
|
2021-05-05 21:41:51 +00:00
|
|
|
* changed, the field modified flag is set. If the field is the child of a symbol, the
|
|
|
|
* parent symbol's modified flag is also set.
|
2010-12-07 16:10:42 +00:00
|
|
|
*
|
|
|
|
* @param aName - User defined field name.
|
|
|
|
*/
|
|
|
|
void SetName( const wxString& aName );
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
int GetId() const { return m_id; }
|
2021-12-12 22:01:13 +00:00
|
|
|
void SetId( int aId );
|
2010-10-22 12:11:52 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int GetPenWidth() const override;
|
2009-06-30 17:57:27 +00:00
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* getDrawFont() const override;
|
2022-01-07 00:47:23 +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
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I GetBoundingBox() const override;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
|
2010-11-17 18:41:20 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
|
2009-06-13 17:06:07 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
LIB_FIELD& operator=( const LIB_FIELD& field );
|
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
|
|
|
*/
|
2017-02-05 19:18:29 +00:00
|
|
|
wxString GetFullText( int unit = 1 ) const;
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2022-10-22 10:50:26 +00:00
|
|
|
wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
|
2022-09-03 20:54:05 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
SCH_LAYER_ID GetDefaultLayer() const;
|
2020-03-06 03:00:30 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void BeginEdit( const VECTOR2I& aStartPoint ) override;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void Offset( const VECTOR2I& aOffset ) override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void MoveTo( const VECTOR2I& aPosition ) override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void MirrorHorizontal( const VECTOR2I& aCenter ) override;
|
|
|
|
void MirrorVertical( const VECTOR2I& aCenter ) override;
|
|
|
|
void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
|
2022-09-16 16:20:36 +00:00
|
|
|
const TRANSFORM& aTransform, bool aDimmed ) const override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
wxString GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const override;
|
2011-04-27 19:44:32 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS GetMenuImage() const override;
|
2011-04-27 19:44:32 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
EDA_ITEM* Clone() const override;
|
2012-03-17 14:39:27 +00:00
|
|
|
|
2020-02-13 13:39:52 +00:00
|
|
|
bool IsMandatory() const;
|
|
|
|
|
2022-05-29 19:29:32 +00:00
|
|
|
bool IsAutoAdded() const { return m_autoAdded; }
|
|
|
|
void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; }
|
|
|
|
|
2022-09-03 20:54:05 +00:00
|
|
|
bool IsNameShown() const { return m_showName; }
|
|
|
|
void SetNameShown( bool aShown = true ) { m_showName = aShown; }
|
|
|
|
|
2022-09-04 16:34:16 +00:00
|
|
|
bool CanAutoplace() const { return m_allowAutoPlace; }
|
|
|
|
void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
|
|
|
|
|
2022-08-28 23:02:12 +00:00
|
|
|
bool ShowInChooser() const { return m_showInChooser; }
|
|
|
|
void SetShowInChooser( bool aShow = true ) { m_showInChooser = aShow; }
|
|
|
|
|
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.
|
|
|
|
*/
|
2022-03-03 12:20:30 +00:00
|
|
|
int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
|
2021-06-10 18:51:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Print the field.
|
|
|
|
*
|
|
|
|
* If \a aData not NULL, \a aData must point a wxString which is used instead of
|
|
|
|
* the m_Text
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
|
2022-09-16 16:20:36 +00:00
|
|
|
const TRANSFORM& aTransform, bool aDimmed ) override;
|
2021-06-10 18:51:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the new circle at \a aPosition when editing.
|
|
|
|
*
|
|
|
|
* @param aPosition - The position to edit the circle in drawing coordinates.
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
void CalcEdit( const VECTOR2I& aPosition ) override;
|
2021-06-10 18:51:46 +00:00
|
|
|
|
|
|
|
friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
|
|
|
|
|
2021-12-12 22:01:13 +00:00
|
|
|
int m_id; ///< @see enum MANDATORY_FIELD_T
|
|
|
|
wxString m_name; ///< Name (not the field text value itself, that is #EDA_TEXT::m_Text)
|
2022-05-29 19:29:32 +00:00
|
|
|
bool m_autoAdded; ///< Was this field automatically added to a LIB_SYMBOL?
|
2022-09-03 20:54:05 +00:00
|
|
|
bool m_showName; ///< Render the field's name in addition to its value
|
2022-09-04 16:34:16 +00:00
|
|
|
bool m_allowAutoPlace; ///< This field can be autoplaced when converted to a SCH_FIELD
|
2022-08-28 23:02:12 +00:00
|
|
|
bool m_showInChooser; ///< This field is available as a data column for the chooser
|
2008-12-31 09:27:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CLASS_LIBENTRY_FIELDS_H
|