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
|
|
|
|
* Copyright (C) 2004-2019 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>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <lib_draw_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
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Field object used in symbol libraries. At least MANDATORY_FIELDS are always present
|
2010-06-17 16:30:10 +00:00
|
|
|
* 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)
|
2013-05-24 23:58:29 +00:00
|
|
|
* 3 = DATASHEET (user doc link)
|
2011-10-31 20:49:48 +00:00
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
|
2018-06-22 13:05:11 +00:00
|
|
|
wxString m_savedText; ///< Temporary storage for the string when editing.
|
2010-12-07 16:10:42 +00:00
|
|
|
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
|
|
|
*/
|
2019-04-04 22:49:49 +00:00
|
|
|
void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData,
|
2016-09-25 17:06:49 +00:00
|
|
|
const TRANSFORM& aTransform ) override;
|
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.
|
|
|
|
*/
|
2018-08-03 12:18:26 +00:00
|
|
|
void CalcEdit( const wxPoint& aPosition ) override;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
|
|
|
|
|
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
|
|
|
|
2019-01-10 05:42:14 +00:00
|
|
|
LIB_FIELD( int aID, wxString& aName );
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_FIELD( LIB_PART * 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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-25 23:49:04 +00:00
|
|
|
wxString GetTypeName() override
|
|
|
|
{
|
|
|
|
return _( "Field" );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
* 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 );
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
int GetId() const { return m_id; }
|
2010-12-07 16:10:42 +00:00
|
|
|
|
|
|
|
void SetId( int aId ) { m_id = aId; }
|
2010-10-22 12:11:52 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
int GetPenSize( ) const override;
|
2009-06-30 17:57:27 +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
|
|
|
|
2010-12-20 19:18:20 +00:00
|
|
|
/**
|
|
|
|
* @return true if the field value is void (no text in this field)
|
|
|
|
*/
|
2014-05-04 17:08:36 +00:00
|
|
|
bool IsVoid() const
|
2010-12-20 19:18:20 +00:00
|
|
|
{
|
|
|
|
return m_Text.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
/**
|
2009-12-30 18:06:12 +00:00
|
|
|
* @return true is this field is visible, false if flagged invisible
|
|
|
|
*/
|
2017-01-23 20:30:11 +00:00
|
|
|
bool IsVisible() const { return EDA_TEXT::IsVisible(); } // why needed?
|
2009-12-30 18:06:12 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
const EDA_RECT GetBoundingBox() const override;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
|
2010-11-17 18:41:20 +00:00
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
|
2009-06-13 17:06:07 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
void 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.
|
|
|
|
*
|
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
|
|
|
*/
|
2017-02-05 19:18:29 +00:00
|
|
|
wxString GetFullText( int unit = 1 ) const;
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D GetDefaultColor() override;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2019-05-07 23:51:37 +00:00
|
|
|
void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint ) override;
|
|
|
|
void EndEdit( const wxPoint& aPosition ) override;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
void Rotate() override;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
void SetText( const wxString& aText ) override;
|
2010-10-22 12:11:52 +00:00
|
|
|
|
2019-05-09 07:57:07 +00:00
|
|
|
void Offset( const wxPoint& aOffset ) override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
bool Inside( EDA_RECT& aRect ) const override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2019-05-09 07:57:07 +00:00
|
|
|
void MoveTo( const wxPoint& aPosition ) override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
void MirrorHorizontal( const wxPoint& aCenter ) override;
|
|
|
|
void MirrorVertical( const wxPoint& aCenter ) override;
|
|
|
|
void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
|
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,
|
2016-09-25 17:06:49 +00:00
|
|
|
const TRANSFORM& aTransform ) override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
int GetWidth() const override { return GetThickness(); }
|
|
|
|
void SetWidth( int aWidth ) override { SetThickness( aWidth ); }
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
|
2011-04-27 19:44:32 +00:00
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF 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
|
|
|
|
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.
|
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
int compare( const LIB_ITEM& aOther ) const override;
|
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
|