sch_text.h 11.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * 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_text.h
 * @brief Definitions of the SCH_TEXT class and derivatives for Eeschema.
 */
29 30 31 32

#ifndef CLASS_TEXT_LABEL_H
#define CLASS_TEXT_LABEL_H

33

34
#include <macros.h>
35
#include <eda_text.h>
36
#include <sch_item_struct.h>
37 38 39 40


class LINE_READER;

41

42 43
/* Type of SCH_HIERLABEL and SCH_GLOBALLABEL
 * mainly used to handle the graphic associated shape
44
 */
45 46 47 48 49 50
typedef enum {
    NET_INPUT,
    NET_OUTPUT,
    NET_BIDI,
    NET_TRISTATE,
    NET_UNSPECIFIED,
51
    NET_TMAX        /* Last value */
52 53
} TypeSheetLabel;

54

55
extern const char* SheetLabelType[];    /* names of types of labels */
56

57
class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
58 59
{
protected:
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    int m_shape;

    /// True if not connected to another object if the object derive from SCH_TEXT
    /// supports connections.
    bool m_isDangling;

    /**
     * The orientation of text and any associated drawing elements of derived objects.
     * 0 is the horizontal and left justified.
     * 1 is vertical and top justified.
     * 2 is horizontal and right justified.  It is the equivalent of the mirrored 0 orentation.
     * 3 is veritcal and bottom justifiend. It is the equivalent of the mirrored 1 orentation.
     * This is a duplicattion of m_Orient, m_HJustified, and m_VJustified in #EDA_TEXT but is
     * easier to handle that 3 parameters when editing and reading and saving files.
     */
    int m_schematicOrientation;
76

77
public:
78 79
    SCH_TEXT( const wxPoint& pos = wxPoint( 0, 0 ),
              const wxString& text = wxEmptyString,
80
              KICAD_T aType = SCH_TEXT_T );
81

82 83 84 85 86 87 88
    /**
     * Copy Constructor
     * clones \a aText into a new object.  All members are copied as is except
     * for the #m_isDangling member which is set to false.  This prevents newly
     * copied objects derived from #SCH_TEXT from having their connection state
     * improperly set.
     */
89 90
    SCH_TEXT( const SCH_TEXT& aText );

91
    ~SCH_TEXT() { }
92 93 94

    virtual wxString GetClass() const
    {
95
        return wxT( "SCH_TEXT" );
96 97
    }

98 99 100 101 102
    /**
     * Function IncrementLabel
     * increments the label text.
     */
    void IncrementLabel();
103

104
    /**
105
     * Function SetOrientation
106
     * Set m_schematicOrientation, and initialize
107
     * m_orient,m_HJustified and m_VJustified, according to the value of
108 109
     * m_schematicOrientation (for a text )
     * must be called after changing m_schematicOrientation
110 111 112
     * @param aSchematicOrientation =
     *  0 = normal (horizontal, left justified).
     *  1 = up (vertical)
113
     *  2 = (horizontal, right justified). This can be seen as the mirrored position of 0
114 115
     *  3 = bottom . This can be seen as the mirrored position of up
     */
116
    virtual void SetOrientation( int aSchematicOrientation );
117

118 119 120 121 122
    int GetOrientation() { return m_schematicOrientation; }

    int GetShape() const { return m_shape; }

    void SetShape( int aShape ) { m_shape = aShape; }
123

124 125
    /**
     * Function GetSchematicTextOffset (virtual)
126 127 128 129
     * @return the offset between the SCH_TEXT position and the text itself position
     *
     * This offset depends on the orientation, the type of text, and the area required to
     * draw the associated graphic symbol or to put the text above a wire.
130
     */
131
    virtual wxPoint GetSchematicTextOffset() const;
132

133 134 135
    virtual void Draw( EDA_DRAW_PANEL* panel,
                       wxDC*           DC,
                       const wxPoint&  offset,
136
                       GR_DRAWMODE     draw_mode,
137
                       EDA_COLOR_T     Color = UNSPECIFIED_COLOR );
138

139 140
    /**
     * Function CreateGraphicShape
141
     * Calculates the graphic shape (a polygon) associated to the text
142 143
     * @param aPoints A buffer to fill with polygon corners coordinates
     * @param Pos Position of the shape, for texts and labels: do nothing
144 145
     * Mainly for derived classes (SCH_SHEET_PIN and Hierarchical labels)
     */
146
    virtual void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos )
147
    {
148
        aPoints.clear();
149
    }
150

151
    virtual void SwapData( SCH_ITEM* aItem );
152

153
    virtual EDA_RECT GetBoundingBox() const;
charras's avatar
charras committed
154

155
    virtual bool Save( FILE* aFile ) const;
charras's avatar
charras committed
156

157 158
    virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg );

159
    virtual int GetPenSize() const;
160

161
    // Geometric transforms (used in block operations):
162 163

    virtual void Move( const wxPoint& aMoveVector )
164 165 166 167
    {
        m_Pos += aMoveVector;
    }

168
    virtual void MirrorY( int aYaxis_position );
169

170
    virtual void MirrorX( int aXaxis_position );
171

172
    virtual void Rotate( wxPoint aPosition );
173

174 175
    virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );

176
    virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL )
177 178 179 180 181 182
    {
        return EDA_ITEM::Replace( aSearchData, m_Text );
    }

    virtual bool IsReplaceable() const { return true; }

183 184 185 186
    virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList );

    virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList );

187
    virtual bool IsDangling() const { return m_isDangling; }
188 189 190 191

    virtual bool IsSelectStateChanged( const wxRect& aRect );

    virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const;
192

193 194
    virtual bool CanIncrementLabel() const { return true; }

195 196
    virtual wxString GetSelectMenuText() const;

197
    virtual BITMAP_DEF GetMenuImage() const { return  add_text_xpm; }
198

199 200 201
    virtual void GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
                                 SCH_SHEET_PATH*          aSheetPath );

202 203 204 205 206 207 208 209 210 211 212
    virtual wxPoint GetPosition() const { return m_Pos; }

    virtual void SetPosition( const wxPoint& aPosition ) { m_Pos = aPosition; }

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

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

    virtual void Plot( PLOTTER* aPlotter );

213 214
    virtual EDA_ITEM* Clone() const;

215
    void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
216

217
#if defined(DEBUG)
218
    void Show( int nestLevel, std::ostream& os ) const;     // override
219
#endif
220 221 222
};


223
class SCH_LABEL : public SCH_TEXT
224 225
{
public:
226
    SCH_LABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString );
227

228
    // Do not create a copy constructor.  The one generated by the compiler is adequate.
229

230
    ~SCH_LABEL() { }
231

232 233 234
    void Draw( EDA_DRAW_PANEL* panel,
               wxDC*           DC,
               const wxPoint&  offset,
235
               GR_DRAWMODE     draw_mode,
236
               EDA_COLOR_T     Color = UNSPECIFIED_COLOR );
237

238
    wxString GetClass() const
239
    {
240
        return wxT( "SCH_LABEL" );
241
    }
charras's avatar
charras committed
242

243
    void SetOrientation( int aSchematicOrientation );
244

245
    wxPoint GetSchematicTextOffset() const;
246

247
    void MirrorX( int aXaxis_position );
248

249
    void Rotate( wxPoint aPosition );
250

251
    EDA_RECT GetBoundingBox() const;
252

253
    bool Save( FILE* aFile ) const;
254

255
    bool Load( LINE_READER& aLine, wxString& aErrorMsg );
256

257
    bool IsConnectable() const { return true; }
258

259
    wxString GetSelectMenuText() const;
260

261
    BITMAP_DEF GetMenuImage() const { return  add_line_label_xpm; }
262

263
    bool IsReplaceable() const { return true; }
264

265
    bool HitTest( const wxPoint& aPosition, int aAccuracy ) const;
266

267
    EDA_ITEM* Clone() const;
268

269
private:
270
    bool doIsConnected( const wxPoint& aPosition ) const { return m_Pos == aPosition; }
271 272 273
};


274
class SCH_GLOBALLABEL : public SCH_TEXT
275 276
{
public:
277
    SCH_GLOBALLABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString );
278

279
    // Do not create a copy constructor.  The one generated by the compiler is adequate.
280

281
    ~SCH_GLOBALLABEL() { }
282

283 284 285
    void Draw( EDA_DRAW_PANEL* panel,
               wxDC*           DC,
               const wxPoint&  offset,
286
               GR_DRAWMODE     draw_mode,
287
               EDA_COLOR_T     Color = UNSPECIFIED_COLOR );
288

289
    wxString GetClass() const
290
    {
291
        return wxT( "SCH_GLOBALLABEL" );
292 293
    }

294
    void SetOrientation( int aSchematicOrientation );
295

296
    wxPoint GetSchematicTextOffset() const;
297

298
    bool Save( FILE* aFile ) const;
charras's avatar
charras committed
299

300
    bool Load( LINE_READER& aLine, wxString& aErrorMsg );
301

302
    EDA_RECT GetBoundingBox() const;
303

304
    void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos );
305

306
    void MirrorY( int aYaxis_position );
307

308
    void MirrorX( int aXaxis_position );
309

310
    void Rotate( wxPoint aPosition );
311

312
    bool IsConnectable() const { return true; }
313

314
    wxString GetSelectMenuText() const;
315

316
    BITMAP_DEF GetMenuImage() const { return  add_glabel_xpm; }
317

318
    bool HitTest( const wxPoint& aPosition, int aAccuracy ) const;
319

320
    EDA_ITEM* Clone() const;
321

322
private:
323
    bool doIsConnected( const wxPoint& aPosition ) const { return m_Pos == aPosition; }
324 325 326
};


327
class SCH_HIERLABEL : public SCH_TEXT
328 329
{
public:
330
    SCH_HIERLABEL( const wxPoint& pos = wxPoint( 0, 0 ),
331 332 333
                   const wxString& text = wxEmptyString,
                   KICAD_T aType = SCH_HIERARCHICAL_LABEL_T );

334
    // Do not create a copy constructor.  The one generated by the compiler is adequate.
335

336
    ~SCH_HIERLABEL() { }
337

338 339 340
    void Draw( EDA_DRAW_PANEL* panel,
               wxDC*           DC,
               const wxPoint&  offset,
341
               GR_DRAWMODE     draw_mode,
342
               EDA_COLOR_T     Color = UNSPECIFIED_COLOR );
343

344
    wxString GetClass() const
345
    {
346
        return wxT( "SCH_HIERLABEL" );
347 348
    }

349
    void SetOrientation( int aSchematicOrientation );
350

351
    wxPoint GetSchematicTextOffset() const;
352

353
    void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos );
354

355
    bool Save( FILE* aFile ) const;
charras's avatar
charras committed
356

357
    bool Load( LINE_READER& aLine, wxString& aErrorMsg );
358

359
    EDA_RECT GetBoundingBox() const;
360

361
    void MirrorY( int aYaxis_position );
362

363
    void MirrorX( int aXaxis_position );
364

365
    void Rotate( wxPoint aPosition );
366

367
    bool IsConnectable() const { return true; }
368

369
    wxString GetSelectMenuText() const;
370

371
    BITMAP_DEF GetMenuImage() const { return  add_hierarchical_label_xpm; }
372

373
    bool HitTest( const wxPoint& aPosition, int aAccuracy ) const;
374

375
    EDA_ITEM* Clone() const;
376

377
private:
378
    bool doIsConnected( const wxPoint& aPosition ) const { return m_Pos == aPosition; }
379 380 381
};

#endif /* CLASS_TEXT_LABEL_H */