sch_field.h 5.94 KB
Newer Older
1 2 3
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
4 5
 * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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
 */

25 26 27 28
/**
 * @file sch_field.h
 * @brief Definition of the SCH_FIELD class for Eeschema.
 */
charras's avatar
charras committed
29

30 31
#ifndef CLASS_SCH_FIELD_H
#define CLASS_SCH_FIELD_H
charras's avatar
charras committed
32 33


34
#include <eda_text.h>
35 36
#include <sch_item_struct.h>
#include <general.h>
37 38


39
class SCH_EDIT_FRAME;
40
class SCH_COMPONENT;
41
class LIB_FIELD;
42 43 44


/**
45
 * Class SCH_FIELD
46 47 48 49 50 51 52
 * instances are attached to a component and provide a place for the component's value,
 * reference designator, footprint, and user definable name-value pairs of arbitrary purpose.
 *
 * <ul> <li>Field 0 is reserved for the component reference.</li>
 * <li>Field 1 is reserved for the component value.</li>
 * <li>Field 2 is reserved for the component footprint.</li>
 * <li>Field 3 is reserved for the component data sheet file.</li>
53
 * <li>Field 4 and higher are user defineable.</li></ul>
54
 */
55

56
class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
charras's avatar
charras committed
57
{
58
    int      m_id;         ///< Field index, @see enum NumFieldType
59

60
    wxString m_name;
61

charras's avatar
charras committed
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();
charras's avatar
charras committed
69

70
    wxString GetClass() const
charras's avatar
charras committed
71
    {
72
        return wxT( "SCH_FIELD" );
73
    }
charras's avatar
charras committed
74

75 76
    /**
     * Function GetName
77 78 79 80 81
     * returns the field name.
     *
     * @param aUseDefaultName When true return the default field name if the field name is
     *                        empty.  Otherwise the default field name is returned.
     * @return A wxString object containing the name of the field.
82
     */
83
    wxString GetName( bool aUseDefaultName = true ) const;
84

85 86 87 88 89
    void SetName( const wxString& aName ) { m_name = aName; }

    int GetId() const { return m_id; }

    void SetId( int aId ) { m_id = aId; }
90

91
    /**
92 93 94 95
     * Function GetFullyQualifiedText
     * returns the fully qualified field text by allowing for the part suffix to be added
     * to the reference designator field if the component has multiple parts.  For all other
     * fields this is the equivalent of EDA_TEXT::GetText().
96
     *
97
     * @return a const wxString object containing the field's string.
98
     */
99
    const wxString GetFullyQualifiedText() const;
100

101
    void Place( SCH_EDIT_FRAME* frame, wxDC* DC );
102

103
    const EDA_RECT GetBoundingBox() const;    // Virtual
Dick Hollenbeck's avatar
Dick Hollenbeck committed
104 105 106 107 108

    /**
     * Function IsVoid
     * returns true if the field is either empty or holds "~".
     */
109
    bool IsVoid() const
Dick Hollenbeck's avatar
Dick Hollenbeck committed
110 111
    {
        size_t len = m_Text.Len();
112

Dick Hollenbeck's avatar
Dick Hollenbeck committed
113 114 115
        return len == 0 || ( len == 1 && m_Text[0] == wxChar( '~' ) );
    }

116
    void SwapData( SCH_ITEM* aItem );
charras's avatar
charras committed
117

118 119
    /**
     * Function ImportValues
120 121
     * copy parameters from a source.
     * Pointers and specific values (position) are not copied
122
     * @param aSource = the LIB_FIELD to read
123
     */
124
    void ImportValues( const LIB_FIELD& aSource );
125

126
    int GetPenSize() const;
127

128 129
    /**
     * Function IsVisible
130 131
     * @return true is this field is visible, false if flagged invisible
     */
132
    bool IsVisible() const
133 134 135 136
    {
        return (m_Attributs & TEXT_NO_VISIBLE) == 0 ? true : false;
    }

137 138 139
    void Draw( EDA_DRAW_PANEL* aPanel,
               wxDC*           aDC,
               const wxPoint&  aOffset,
140
               GR_DRAWMODE     aDrawMode,
141
               EDA_COLOR_T     aColor = UNSPECIFIED_COLOR );
charras's avatar
charras committed
142 143

    bool Save( FILE* aFile ) const;
144 145

    // Geometric transforms (used in block operations):
146

147
    void Move( const wxPoint& aMoveVector )
148 149 150 151
    {
        m_Pos += aMoveVector;
    }

152

153
    void Rotate( wxPoint aPosition );
154

155 156 157 158 159
    /**
     * @copydoc SCH_ITEM::MirrorX()
     *
     * This overload does nothing.  Fields are never mirrored alone.  They are moved
     * when the parent component is mirrored.  This function is only needed by the
160
     * pure function of the master class.
161
     */
162
    void MirrorX( int aXaxis_position )
163 164 165
    {
    }

166 167 168 169 170
    /**
     * @copydoc SCH_ITEM::MirrorY()
     *
     * This overload does nothing.  Fields are never mirrored alone.  They are moved
     * when the parent component is mirrored.  This function is only needed by the
171
     * pure function of the master class.
172
     */
173
    void MirrorY( int aYaxis_position )
174 175
    {
    }
176

177
    bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
178

179
    bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL );
180

181
    wxString GetSelectMenuText() const;
182

183
    BITMAP_DEF GetMenuImage() const;
184

185
    bool IsReplaceable() const { return true; }
186

187
    wxPoint GetPosition() const;
188

189
    void SetPosition( const wxPoint& aPosition );
190

191
    bool HitTest( const wxPoint& aPosition, int aAccuracy ) const;
192

193
    bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const;
194

195
    void Plot( PLOTTER* aPlotter );
196

197
    EDA_ITEM* Clone() const;
198

199 200 201
#if defined(DEBUG)
    void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
#endif
charras's avatar
charras committed
202 203 204
};


205
#endif /* CLASS_SCH_FIELD_H */