2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-28 16:56:09 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2022-12-08 23:56:55 +00:00
|
|
|
* Copyright (C) 2022 CERN
|
2023-05-28 19:46:39 +00:00
|
|
|
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-19 20:32:21 +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
|
|
|
|
*/
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
#ifndef CLASS_SCH_FIELD_H
|
|
|
|
#define CLASS_SCH_FIELD_H
|
2008-09-20 17:20:40 +00:00
|
|
|
|
|
|
|
|
2012-04-12 21:31:31 +00:00
|
|
|
#include <eda_text.h>
|
2019-05-10 19:57:24 +00:00
|
|
|
#include <sch_item.h>
|
2019-04-30 13:54:32 +00:00
|
|
|
#include <template_fieldnames.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
2023-08-02 19:11:59 +00:00
|
|
|
#include "scintilla_tricks.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
class SCH_EDIT_FRAME;
|
2009-10-08 13:19:28 +00:00
|
|
|
class LIB_FIELD;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-05 21:41:51 +00:00
|
|
|
* Instances are attached to a symbol or sheet and provide a place for the symbol's value,
|
2021-03-19 20:27:30 +00:00
|
|
|
* reference designator, footprint, , a sheet's name, filename, and user definable name-value
|
|
|
|
* pairs of arbitrary purpose.
|
2010-12-21 15:13:09 +00:00
|
|
|
*
|
2021-03-25 14:07:16 +00:00
|
|
|
* - Field 0 is reserved for the symbol reference.
|
|
|
|
* - Field 1 is reserved for the symbol value.
|
|
|
|
* - Field 2 is reserved for the symbol footprint.
|
|
|
|
* - Field 3 is reserved for the symbol data sheet file.
|
|
|
|
* - Field 4 and higher are user definable.
|
2008-10-06 05:44:29 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
|
2020-04-18 20:04:41 +00:00
|
|
|
const wxString& aName = wxEmptyString );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2024-01-20 23:35:29 +00:00
|
|
|
SCH_FIELD( SCH_ITEM* aParent, int aFieldId = INVALID_FIELD,
|
|
|
|
const wxString& aName = wxEmptyString );
|
2022-12-08 23:56:55 +00:00
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
SCH_FIELD( const SCH_FIELD& aText );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
~SCH_FIELD()
|
|
|
|
{ }
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
SCH_FIELD& operator=( const SCH_FIELD& aField );
|
|
|
|
|
2019-08-29 14:59:36 +00:00
|
|
|
static inline bool ClassOf( const EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
return aItem && SCH_FIELD_T == aItem->Type();
|
|
|
|
}
|
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
wxString GetClass() const override
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
return wxT( "SCH_FIELD" );
|
2011-12-07 18:47:59 +00:00
|
|
|
}
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
|
|
|
if( SCH_ITEM::IsType( aScanTypes ) )
|
|
|
|
return true;
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
for( KICAD_T scanType : aScanTypes )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == SCH_FIELD_LOCATE_REFERENCE_T && m_id == REFERENCE_FIELD )
|
2019-04-30 13:54:32 +00:00
|
|
|
return true;
|
2022-08-20 09:27:35 +00:00
|
|
|
else if ( scanType == SCH_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD )
|
2019-04-30 13:54:32 +00:00
|
|
|
return true;
|
2022-08-20 09:27:35 +00:00
|
|
|
else if ( scanType == SCH_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD )
|
2019-04-30 13:54:32 +00:00
|
|
|
return true;
|
2022-08-20 09:27:35 +00:00
|
|
|
else if ( scanType == SCH_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD )
|
2019-04-30 13:54:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
bool IsHypertext() const override
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2023-07-10 18:31:12 +00:00
|
|
|
return GetCanonicalName() == wxT( "Intersheetrefs" );
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
/**
|
2022-05-12 11:05:06 +00:00
|
|
|
* Return the field name (not translated)..
|
2011-12-07 18:47:59 +00:00
|
|
|
*
|
|
|
|
* @param aUseDefaultName When true return the default field name if the field name is
|
|
|
|
* empty. Otherwise the default field name is returned.
|
2021-03-25 14:07:16 +00:00
|
|
|
* @return the name of the field.
|
2011-03-25 19:16:05 +00:00
|
|
|
*/
|
2011-12-07 18:47:59 +00:00
|
|
|
wxString GetName( bool aUseDefaultName = true ) const;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
/**
|
|
|
|
* Get a non-language-specific name for a field which can be used for storage, variable
|
|
|
|
* look-up, etc.
|
|
|
|
*/
|
|
|
|
wxString GetCanonicalName() const;
|
|
|
|
|
2023-07-12 15:28:23 +00:00
|
|
|
void SetName( const wxString& aName );
|
|
|
|
|
|
|
|
void SetText( const wxString& aText ) override;
|
2011-12-07 18:47:59 +00:00
|
|
|
|
2022-12-11 17:56:14 +00:00
|
|
|
/**
|
|
|
|
* Get the initial name of the field set at creation (or set by SetName()).
|
|
|
|
* This is the raw field name with no translation and no change.
|
|
|
|
*/
|
|
|
|
const wxString& GetInternalName() { return m_name; }
|
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
int GetId() const { return m_id; }
|
|
|
|
|
2020-05-06 14:47:51 +00:00
|
|
|
void SetId( int aId );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2023-07-12 15:28:23 +00:00
|
|
|
/**
|
|
|
|
* Gets the fields name as displayed on the schematic or
|
|
|
|
* in the symbol fields table. This is either the same as GetName() or
|
|
|
|
* if the field has a variable for name, the variable namer with the ${} stripped.
|
|
|
|
*/
|
|
|
|
wxString GetShownName() const;
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
|
|
|
|
int aDepth = 0 ) const;
|
2023-04-25 10:42:58 +00:00
|
|
|
|
2023-05-28 19:46:39 +00:00
|
|
|
wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
|
2011-10-21 18:17:51 +00:00
|
|
|
|
2023-09-12 22:20:25 +00:00
|
|
|
/**
|
|
|
|
* Return true if both the name and value of the field are empty. Whitespace
|
|
|
|
* does not count as non-empty
|
|
|
|
*/
|
|
|
|
bool IsEmpty()
|
|
|
|
{
|
|
|
|
wxString name( m_name );
|
|
|
|
wxString value( GetText() );
|
|
|
|
|
|
|
|
return name.Trim().empty() && value.Trim().empty();
|
|
|
|
}
|
|
|
|
|
2024-02-27 17:48:09 +00:00
|
|
|
int GetSchTextSize() const { return GetTextWidth(); }
|
|
|
|
void SetSchTextSize( int aSize ) { SetTextSize( VECTOR2I( aSize, aSize ) ); }
|
|
|
|
|
2022-09-24 22:50:52 +00:00
|
|
|
COLOR4D GetFieldColor() const;
|
|
|
|
|
|
|
|
void SetLastResolvedState( const SCH_ITEM* aItem ) override
|
|
|
|
{
|
|
|
|
const SCH_FIELD* aField = dynamic_cast<const SCH_FIELD*>( aItem );
|
|
|
|
|
|
|
|
if( aField )
|
|
|
|
m_lastResolvedColor = aField->m_lastResolvedColor;
|
|
|
|
}
|
|
|
|
|
2023-06-01 11:12:48 +00:00
|
|
|
void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
|
|
|
|
2021-11-01 21:05:30 +00:00
|
|
|
/**
|
|
|
|
* Adjusters to allow EDA_TEXT to draw/print/etc. text in absolute coords.
|
|
|
|
*/
|
2022-09-24 22:50:52 +00:00
|
|
|
EDA_ANGLE GetDrawRotation() const override;
|
2021-11-01 21:05:30 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I GetBoundingBox() const override;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
/**
|
2021-03-25 14:07:16 +00:00
|
|
|
* Return whether the field will be rendered with the horizontal justification
|
2015-12-13 16:56:47 +00:00
|
|
|
* inverted due to rotation or mirroring of the parent.
|
|
|
|
*/
|
|
|
|
bool IsHorizJustifyFlipped() const;
|
2021-11-03 18:11:08 +00:00
|
|
|
bool IsVertJustifyFlipped() const;
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const;
|
|
|
|
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const;
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2022-09-03 20:54:05 +00:00
|
|
|
bool IsNameShown() const { return m_showName; }
|
|
|
|
void SetNameShown( bool aShown = true ) { m_showName = aShown; }
|
|
|
|
|
2023-07-12 15:28:23 +00:00
|
|
|
/**
|
|
|
|
* Named variables are fields whose names are variables like ${VAR}.
|
|
|
|
*
|
|
|
|
* The shown name of these fields is VAR and the value is resolved from
|
|
|
|
* ${VAR}
|
|
|
|
*/
|
|
|
|
bool IsNamedVariable() const { return m_isNamedVariable; }
|
|
|
|
|
2022-09-04 16:34:16 +00:00
|
|
|
bool CanAutoplace() const { return m_allowAutoPlace; }
|
|
|
|
void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
|
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
void SwapData( SCH_ITEM* aItem ) override;
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2021-03-25 14:07:16 +00:00
|
|
|
* Copy parameters from a LIB_FIELD source.
|
|
|
|
*
|
|
|
|
* Pointers and specific values (position) are not copied.
|
|
|
|
*
|
|
|
|
* @param aSource is the LIB_FIELD to read.
|
2008-12-31 15:01:29 +00:00
|
|
|
*/
|
2010-09-05 17:01:48 +00:00
|
|
|
void ImportValues( const LIB_FIELD& aSource );
|
2008-12-31 15:01:29 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int GetPenWidth() const override;
|
2009-06-30 17:57:27 +00:00
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
void ClearCaches() override;
|
|
|
|
void ClearRenderCache() override;
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>*
|
|
|
|
GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
|
|
|
|
TEXT_ATTRIBUTES& aAttrs ) const;
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void Move( const VECTOR2I& aMoveVector ) override
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
Offset( aMoveVector );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
/**
|
2021-02-16 20:45:25 +00:00
|
|
|
* @copydoc SCH_ITEM::MirrorVertically()
|
2012-03-15 14:31:16 +00:00
|
|
|
*
|
|
|
|
* This overload does nothing. Fields are never mirrored alone. They are moved
|
2021-03-19 20:27:30 +00:00
|
|
|
* when the parent symbol is mirrored. This function is only needed by the
|
2012-03-26 23:47:08 +00:00
|
|
|
* pure function of the master class.
|
2012-03-15 14:31:16 +00:00
|
|
|
*/
|
2021-02-16 20:45:25 +00:00
|
|
|
void MirrorVertically( int aCenter ) override
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
/**
|
2021-02-16 20:45:25 +00:00
|
|
|
* @copydoc SCH_ITEM::MirrorHorizontally()
|
2012-03-15 14:31:16 +00:00
|
|
|
*
|
|
|
|
* This overload does nothing. Fields are never mirrored alone. They are moved
|
2021-03-19 20:27:30 +00:00
|
|
|
* when the parent symbol is mirrored. This function is only needed by the
|
2012-03-26 23:47:08 +00:00
|
|
|
* pure function of the master class.
|
2009-07-27 14:32:40 +00:00
|
|
|
*/
|
2021-02-16 20:45:25 +00:00
|
|
|
void MirrorHorizontally( int aCenter ) override
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2023-08-02 19:11:59 +00:00
|
|
|
void OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks, wxStyledTextEvent &aEvent ) const;
|
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr ) override;
|
2011-12-13 15:37:33 +00:00
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
|
2021-09-26 23:22:32 +00:00
|
|
|
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS GetMenuImage() const override;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2018-05-17 23:43:03 +00:00
|
|
|
bool IsReplaceable() const override;
|
2011-12-01 16:49:28 +00:00
|
|
|
|
2022-01-04 01:00:40 +00:00
|
|
|
VECTOR2I GetLibPosition() const { return EDA_TEXT::GetTextPos(); }
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I GetPosition() const override;
|
|
|
|
void SetPosition( const VECTOR2I& aPosition ) override;
|
2012-03-15 14:31:16 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I GetParentPosition() const;
|
2020-03-06 12:05:21 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
|
2022-08-31 09:33:46 +00:00
|
|
|
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
|
2012-03-15 14:31:16 +00:00
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
|
|
|
|
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) override;
|
|
|
|
|
|
|
|
void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
|
|
|
|
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
|
2012-03-15 14:31:16 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
EDA_ITEM* Clone() const override;
|
2012-03-17 14:39:27 +00:00
|
|
|
|
2020-01-28 20:33:23 +00:00
|
|
|
bool operator <( const SCH_ITEM& aItem ) const override;
|
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
double Similarity( const SCH_ITEM& aItem ) const override;
|
|
|
|
|
|
|
|
bool operator==( const SCH_ITEM& aItem ) const override;
|
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
#if defined(DEBUG)
|
2016-09-25 17:06:49 +00:00
|
|
|
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
|
2011-12-14 17:25:42 +00:00
|
|
|
#endif
|
2021-03-25 14:07:16 +00:00
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
protected:
|
|
|
|
KIFONT::FONT* getDrawFont() const override;
|
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
|
|
|
|
|
2021-03-25 14:07:16 +00:00
|
|
|
private:
|
|
|
|
int m_id; ///< Field index, @see enum MANDATORY_FIELD_T
|
|
|
|
|
|
|
|
wxString m_name;
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2022-09-03 20:54:05 +00:00
|
|
|
bool m_showName; ///< Render the field name in addition to its value
|
2022-09-04 16:34:16 +00:00
|
|
|
bool m_allowAutoPlace; ///< This field can be autoplaced
|
2023-07-12 15:28:23 +00:00
|
|
|
bool m_isNamedVariable; ///< If the field name is a variable name, e.g. ${DNP}
|
|
|
|
///< then the value field is forced to be the same as the name
|
2022-09-03 20:54:05 +00:00
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
mutable bool m_renderCacheValid;
|
|
|
|
mutable VECTOR2I m_renderCachePos;
|
|
|
|
mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache;
|
2022-09-24 22:50:52 +00:00
|
|
|
|
|
|
|
mutable COLOR4D m_lastResolvedColor;
|
2008-09-20 17:20:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
#endif /* CLASS_SCH_FIELD_H */
|