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-2019 KiCad Developers, see change_log.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 SCH_COMPONENT;
36 class LIB_FIELD;
37 
38 
51 class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
52 {
53  int m_id;
54 
55  wxString m_name;
56 
57 public:
58  SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_ITEM* aParent,
59  const wxString& aName = wxEmptyString );
60 
61  // Do not create a copy constructor. The one generated by the compiler is adequate.
62 
63  ~SCH_FIELD();
64 
65  static inline bool ClassOf( const EDA_ITEM* aItem )
66  {
67  return aItem && SCH_FIELD_T == aItem->Type();
68  }
69 
70  wxString GetClass() const override
71  {
72  return wxT( "SCH_FIELD" );
73  }
74 
75  bool IsType( const KICAD_T aScanTypes[] ) const override
76  {
77  if( SCH_ITEM::IsType( aScanTypes ) )
78  return true;
79 
80  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
81  {
83  return true;
84  else if ( *p == SCH_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD )
85  return true;
86  else if ( *p == SCH_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD )
87  return true;
88  else if ( *p == SCH_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD )
89  return true;
90  }
91 
92  return false;
93  }
94 
95  bool IsHypertext() const override
96  {
97  return m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T;
98  }
99 
100  void DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) override;
101 
110  wxString GetName( bool aUseDefaultName = true ) const;
111 
116  wxString GetCanonicalName() const;
117 
118  void SetName( const wxString& aName ) { m_name = aName; }
119 
120  int GetId() const { return m_id; }
121 
122  void SetId( int aId );
123 
124  wxString GetShownText( int aDepth = 0 ) const override;
125 
126  const EDA_RECT GetBoundingBox() const override;
127 
133  bool IsHorizJustifyFlipped() const;
134 
139  bool IsVoid() const;
140 
141  void SwapData( SCH_ITEM* aItem ) override;
142 
149  void ImportValues( const LIB_FIELD& aSource );
150 
151  int GetPenWidth() const override;
152 
153  void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
154 
155  void Move( const wxPoint& aMoveVector ) override
156  {
157  Offset( aMoveVector );
158  }
159 
160  void Rotate( wxPoint aPosition ) override;
161 
169  void MirrorX( int aXaxis_position ) override
170  {
171  }
172 
180  void MirrorY( int aYaxis_position ) override
181  {
182  }
183 
184  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override;
185 
186  bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) override;
187 
188  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
189 
190  BITMAP_DEF GetMenuImage() const override;
191 
192  bool IsReplaceable() const override;
193 
194  wxPoint GetLibPosition() const { return EDA_TEXT::GetTextPos(); }
195 
196  wxPoint GetPosition() const override;
197  void SetPosition( const wxPoint& aPosition ) override;
198 
199  wxPoint GetParentPosition() const;
200 
201  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
202  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
203 
204  void Plot( PLOTTER* aPlotter ) override;
205 
206  EDA_ITEM* Clone() const override;
207 
208  bool operator <( const SCH_ITEM& aItem ) const override;
209 
210 #if defined(DEBUG)
211  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
212 #endif
213 };
214 
215 
216 #endif /* CLASS_SCH_FIELD_H */
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_field.h:155
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:51
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:259
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:162
void MirrorX(int aXaxis_position) override
Mirror item relative to the X axis about aXaxis_position.
Definition: sch_field.h:169
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_field.h:65
PNG memory record (file in memory).
Definition: bitmap_def.h:29
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:73
void ImportValues(const LIB_FIELD &aSource)
Function ImportValues copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:243
wxPoint GetPosition() const override
Definition: sch_field.cpp:673
Field object used in symbol libraries.
Definition: lib_field.h:59
bool IsHypertext() const override
Allows items to support hypertext actions when hovered/clicked.
Definition: sch_field.h:95
int GetId() const
Definition: sch_field.h:120
Schematic editor (Eeschema) main window.
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_field.cpp:448
The base class for create windows for drawing purpose.
void DoHypertextMenu(EDA_DRAW_FRAME *aFrame) override
Definition: sch_field.cpp:456
wxString m_name
Definition: sch_field.h:55
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:104
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.cpp:321
name of datasheet
Field Value of part, i.e. "3.3K".
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:695
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:525
#define NULL
bool IsType(const KICAD_T aScanTypes[]) const override
Function IsType Checks whether the item is one of the listed types.
Definition: sch_field.h:75
SCH_FIELD(const wxPoint &aPos, int aFieldId, SCH_ITEM *aParent, const wxString &aName=wxEmptyString)
Definition: sch_field.cpp:55
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_field.cpp:571
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: eda_item.h:250
wxPoint GetLibPosition() const
Definition: sch_field.h:194
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_field.cpp:554
void MirrorY(int aYaxis_position) override
Mirror item relative to the Y axis about aYaxis_position.
Definition: sch_field.h:180
Field Name Module PCB, i.e. "16DIP300".
EDA_UNITS
Definition: eda_units.h:38
Base plotter engine class.
Definition: plotter.h:131
void Plot(PLOTTER *aPlotter) override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:602
bool Replace(wxFindReplaceData &aSearchData, void *aAuxData=NULL) override
Function Replace performs a text replace using the find and replace criteria in aSearchData on items ...
Definition: sch_field.cpp:396
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_field.cpp:262
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: sch_field.cpp:327
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:198
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:249
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:507
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetName(const wxString &aName)
Definition: sch_field.h:118
Schematic symbol object.
Definition: sch_component.h:79
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_field.h:70
bool IsHorizJustifyFlipped() const
Function IsHorizJustifyFlipped Returns whether the field will be rendered with the horizontal justifi...
Definition: sch_field.cpp:304
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_field.cpp:367
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_field.cpp:440
void SetId(int aId)
Definition: sch_field.cpp:79
wxPoint GetParentPosition() const
Definition: sch_field.cpp:689
int m_id
Field index,.
Definition: sch_field.h:53
Field Reference of part, i.e. "IC21".
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:652
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
int GetPenWidth() const override
Definition: sch_field.cpp:192
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181