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-2015 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 
30 #ifndef CLASS_SCH_FIELD_H
31 #define CLASS_SCH_FIELD_H
32 
33 
34 #include <eda_text.h>
35 #include <sch_item_struct.h>
36 #include <general.h>
37 
38 
39 class SCH_EDIT_FRAME;
40 class SCH_COMPONENT;
41 class LIB_FIELD;
42 
43 
56 class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
57 {
58  int m_id;
59 
60  wxString m_name;
61 
62 public:
63  SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent,
64  wxString aName = wxEmptyString );
65 
66  // Do not create a copy constructor. The one generated by the compiler is adequate.
67 
68  ~SCH_FIELD();
69 
70  wxString GetClass() const override
71  {
72  return wxT( "SCH_FIELD" );
73  }
74 
83  wxString GetName( bool aUseDefaultName = true ) const;
84 
85  void SetName( const wxString& aName ) { m_name = aName; }
86 
87  int GetId() const { return m_id; }
88 
89  void SetId( int aId ) { m_id = aId; }
90 
99  const wxString GetFullyQualifiedText() const;
100 
101  void Place( SCH_EDIT_FRAME* frame, wxDC* DC );
102 
103  const EDA_RECT GetBoundingBox() const override;
104 
110  bool IsHorizJustifyFlipped() const;
111 
116  bool IsVoid() const
117  {
118  size_t len = m_Text.Len();
119 
120  return len == 0 || ( len == 1 && m_Text[0] == wxChar( '~' ) );
121  }
122 
123  void SwapData( SCH_ITEM* aItem ) override;
124 
131  void ImportValues( const LIB_FIELD& aSource );
132 
139  void ExportValues(LIB_FIELD& aDest ) const;
140 
141  int GetPenSize() const override;
142 
143  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
144  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
145 
146  bool Save( FILE* aFile ) const override;
147 
148  // Geometric transforms (used in block operations):
149 
150  void Move( const wxPoint& aMoveVector ) override
151  {
152  Offset( aMoveVector );
153  }
154 
155  void Rotate( wxPoint aPosition ) override;
156 
164  void MirrorX( int aXaxis_position ) override
165  {
166  }
167 
175  void MirrorY( int aYaxis_position ) override
176  {
177  }
178 
179  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
180 
181  bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) override;
182 
183  wxString GetSelectMenuText() const override;
184 
185  BITMAP_DEF GetMenuImage() const override;
186 
187  bool IsReplaceable() const override { return true; }
188 
190 
191  wxPoint GetPosition() const override;
192 
193  void SetPosition( const wxPoint& aPosition ) override;
194 
195  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
196 
197  bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const override;
198 
199  void Plot( PLOTTER* aPlotter ) override;
200 
201  EDA_ITEM* Clone() const override;
202 
203 #if defined(DEBUG)
204  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
205 #endif
206 };
207 
208 
209 #endif /* CLASS_SCH_FIELD_H */
void Move(const wxPoint &aMoveVector) override
Function Move moves the item by aMoveVector to a new position.
Definition: sch_field.h:150
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:229
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_field.cpp:100
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Definition: sch_field.h:164
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:473
wxString m_Text
Definition: eda_text.h:348
PNG memory record (file in memory).
Definition: bitmap_types.h:38
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
Base schematic object class definition.
int GetId() const
Definition: sch_field.h:87
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:221
const wxString GetFullyQualifiedText() const
Function GetFullyQualifiedText returns the fully qualified field text by allowing for the part suffix...
Definition: sch_field.cpp:79
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_field.cpp:596
Class LIB_FIELD is used in symbol libraries.
Definition: lib_field.h:60
void Place(SCH_EDIT_FRAME *frame, wxDC *DC)
Definition: sch_field.cpp:362
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
Definition: sch_field.cpp:118
wxPoint GetLibPosition() const
Definition: sch_field.h:189
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.h:116
bool Save(FILE *aFile) const override
Function Save writes the data structures for this object out to a FILE in "*.sch" format...
Definition: sch_field.cpp:314
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
wxString m_name
Definition: sch_field.h:60
Definition of base KiCad text object.
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:114
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
Definition: sch_field.cpp:499
SCH_FIELD(const wxPoint &aPos, int aFieldId, SCH_COMPONENT *aParent, wxString aName=wxEmptyString)
Definition: sch_field.cpp:55
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
void ExportValues(LIB_FIELD &aDest) const
Function ImportValues copy parameters into a LIB_FIELD destination.
Definition: sch_field.cpp:227
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_field.cpp:484
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
Definition: sch_field.h:175
Base plotter engine class.
Definition: plot_common.h:86
void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
Definition: sch_field.cpp:530
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:419
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: sch_field.cpp:251
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:237
Class EDA_RECT handles the component boundary box.
void SetName(const wxString &aName)
Definition: sch_field.h:85
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_field.h:70
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_field.cpp:464
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: sch_field.cpp:378
bool IsHorizJustifyFlipped() const
Function IsHorizJustifyFlipped Returns whether the field will be rendered with the horizontal justifi...
Definition: sch_field.cpp:297
bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_field.h:187
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_field.cpp:456
void SetId(int aId)
Definition: sch_field.h:89
int m_id
Field index,.
Definition: sch_field.h:58
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_field.cpp:581
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39