KiCad PCB EDA Suite
sch_field.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef CLASS_SCH_FIELD_H
26 #define CLASS_SCH_FIELD_H
27 
28 
29 #include <eda_text.h>
30 #include <sch_item.h>
31 #include <template_fieldnames.h>
32 #include <general.h>
33 
34 class SCH_EDIT_FRAME;
35 class LIB_FIELD;
36 
37 
49 class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
50 {
51 public:
52  SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_ITEM* aParent,
53  const wxString& aName = wxEmptyString );
54 
55  // Do not create a copy constructor. The one generated by the compiler is adequate.
56 
57  ~SCH_FIELD();
58 
59  static inline bool ClassOf( const EDA_ITEM* aItem )
60  {
61  return aItem && SCH_FIELD_T == aItem->Type();
62  }
63 
64  wxString GetClass() const override
65  {
66  return wxT( "SCH_FIELD" );
67  }
68 
69  bool IsType( const KICAD_T aScanTypes[] ) const override
70  {
71  if( SCH_ITEM::IsType( aScanTypes ) )
72  return true;
73 
74  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
75  {
77  return true;
78  else if ( *p == SCH_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD )
79  return true;
80  else if ( *p == SCH_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD )
81  return true;
82  else if ( *p == SCH_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD )
83  return true;
84  }
85 
86  return false;
87  }
88 
89  bool IsHypertext() const override
90  {
91  return m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T;
92  }
93 
94  void DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) override;
95 
103  wxString GetName( bool aUseDefaultName = true ) const;
104 
109  wxString GetCanonicalName() const;
110 
111  void SetName( const wxString& aName ) { m_name = aName; }
112 
113  int GetId() const { return m_id; }
114 
115  void SetId( int aId );
116 
117  wxString GetShownText( int aDepth = 0 ) const override;
118 
122  double GetDrawRotation() const override;
123  wxPoint GetDrawPos() const override;
124  EDA_TEXT_HJUSTIFY_T GetDrawHorizJustify() const override;
125  EDA_TEXT_VJUSTIFY_T GetDrawVertJustify() const override;
126 
127  const EDA_RECT GetBoundingBox() const override;
128 
133  bool IsHorizJustifyFlipped() const;
134  bool IsVertJustifyFlipped() const;
135 
138 
142  bool IsVoid() const;
143 
144  void SwapData( SCH_ITEM* aItem ) override;
145 
153  void ImportValues( const LIB_FIELD& aSource );
154 
155  int GetPenWidth() const override;
156 
157  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
158 
159  void Move( const wxPoint& aMoveVector ) override
160  {
161  Offset( aMoveVector );
162  }
163 
164  void Rotate( const wxPoint& aCenter ) override;
165 
173  void MirrorVertically( int aCenter ) override
174  {
175  }
176 
184  void MirrorHorizontally( int aCenter ) override
185  {
186  }
187 
188  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
189 
190  bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData = nullptr ) override;
191 
192  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
193  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
194 
195  BITMAPS GetMenuImage() const override;
196 
197  bool IsReplaceable() const override;
198 
199  wxPoint GetLibPosition() const { return EDA_TEXT::GetTextPos(); }
200 
201  wxPoint GetPosition() const override;
202  void SetPosition( const wxPoint& aPosition ) override;
203 
204  wxPoint GetParentPosition() const;
205 
206  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
207  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
208 
209  void Plot( PLOTTER* aPlotter ) const override;
210 
211  EDA_ITEM* Clone() const override;
212 
213  bool operator <( const SCH_ITEM& aItem ) const override;
214 
215 #if defined(DEBUG)
216  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
217 #endif
218 
219 private:
220  int m_id;
221 
222  wxString m_name;
223 };
224 
225 
226 #endif /* CLASS_SCH_FIELD_H */
Field Reference of part, i.e. "IC21".
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_field.h:159
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:273
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:478
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:82
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_field.h:59
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:74
void ImportValues(const LIB_FIELD &aSource)
Copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:246
wxPoint GetPosition() const override
Definition: sch_field.cpp:842
Field object used in symbol libraries.
Definition: lib_field.h:59
wxPoint GetDrawPos() const override
Definition: sch_field.cpp:287
bool IsVertJustifyFlipped() const
Definition: sch_field.cpp:384
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_field.h:89
int GetId() const
Definition: sch_field.h:113
Schematic editor (Eeschema) main window.
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_field.cpp:570
The base class for create windows for drawing purpose.
void DoHypertextMenu(EDA_DRAW_FRAME *aFrame) override
Definition: sch_field.cpp:612
wxString m_name
Definition: sch_field.h:222
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:105
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
bool IsVoid() const
Definition: sch_field.cpp:421
name of datasheet
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:140
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:864
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:696
EDA_TEXT_VJUSTIFY_T GetEffectiveVertJustify() const
Definition: sch_field.cpp:407
EDA_TEXT_VJUSTIFY_T GetDrawVertJustify() const override
Definition: sch_field.cpp:299
Field Value of part, i.e. "3.3K".
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_field.cpp:725
bool IsType(const KICAD_T aScanTypes[]) const override
Check whether the item is one of the listed types.
Definition: sch_field.h:69
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_field.h:173
SCH_FIELD(const wxPoint &aPos, int aFieldId, SCH_ITEM *aParent, const wxString &aName=wxEmptyString)
Definition: sch_field.cpp:56
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_field.cpp:742
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:182
wxPoint GetLibPosition() const
Definition: sch_field.h:199
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_field.cpp:562
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: sch_field.cpp:576
EDA_TEXT_HJUSTIFY_T GetEffectiveHorizJustify() const
Definition: sch_field.cpp:370
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:89
double GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
Definition: sch_field.cpp:265
EDA_UNITS
Definition: eda_units.h:38
Base plotter engine class.
Definition: plotter.h:121
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:305
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:252
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
Definition: sch_field.cpp:678
Handle the component boundary box.
Definition: eda_rect.h:42
void SetName(const wxString &aName)
Definition: sch_field.h:111
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
wxString GetClass() const override
Return the class name.
Definition: sch_field.h:64
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:347
const wxPoint & GetTextPos() const
Definition: eda_text.h:268
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_field.cpp:467
void SetId(int aId)
Definition: sch_field.cpp:80
wxPoint GetParentPosition() const
Definition: sch_field.cpp:858
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:202
bool Replace(const wxFindReplaceData &aSearchData, void *aAuxData=nullptr) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_field.cpp:494
int m_id
Field index,.
Definition: sch_field.h:220
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:822
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_field.h:184
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_field.cpp:427
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:773
int GetPenWidth() const override
Definition: sch_field.cpp:196
EDA_TEXT_HJUSTIFY_T GetDrawHorizJustify() const override
Definition: sch_field.cpp:293
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
Field Name Module PCB, i.e. "16DIP300".