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

/**
 * @file class_libentry.h
 */
29 30 31 32

#ifndef CLASS_LIBENTRY_H
#define CLASS_LIBENTRY_H

33 34 35
#include <general.h>
#include <lib_draw_item.h>
#include <lib_field.h>
36
#include <boost/shared_ptr.hpp>
37
#include <boost/weak_ptr.hpp>
38

39
class LINE_READER;
40
class OUTPUTFORMATTER;
41
class PART_LIB;
42
class LIB_ALIAS;
43
class LIB_PART;
44
class LIB_FIELD;
45

46

47 48 49
/// Compiler controlled string compare function, either case independent or not:
inline int Cmp_KEEPCASE( const wxString& aString1, const wxString& aString2 )
{
50 51
#ifdef KICAD_KEEPCASE
    // case specificity, the normal behavior:
52 53
    return aString1.Cmp( aString2 );
#else
54
    // case independence (only for guys who want that: not recommended)
55 56 57 58 59
    return aString1.CmpNoCase( aString2 );
#endif
}


60 61 62
typedef std::vector<LIB_ALIAS*>         LIB_ALIASES;
typedef boost::shared_ptr<LIB_PART>     PART_SPTR;      ///< shared pointer to LIB_PART
typedef boost::weak_ptr<LIB_PART>       PART_REF;       ///< weak pointer to LIB_PART
63

64

65
/* values for member .m_options */
66 67
enum  LibrEntryOptions
{
68
    ENTRY_NORMAL,   // Libentry is a standard part (real or alias)
69 70 71 72
    ENTRY_POWER     // Libentry is a power symbol
};


73 74 75 76
/// WXTRACE value to enable schematic library memory deletion debug output.
extern const wxChar traceSchLibMem[];


77
/**
78
 * Part library alias object definition.
79
 *
80
 * Part aliases are not really parts.  An alias uses the part definition
81
 * (graphic, pins...)  but has its own name, keywords and documentation.  Therefore, when
82 83
 * the part is modified, alias of this part are modified.  This is a simple
 * method to create parts that have the same physical layout with different names
84
 * such as 74LS00, 74HC00 ... and many op amps.
85
 */
86
class LIB_ALIAS : public EDA_ITEM
87
{
88
    /**
89
     * Actual LIB_PART referenced by [multiple] aliases.
90
     *
91 92 93
     * @note - Do not delete the shared part. The shared part is shared by
     * all of the aliases associated with it. A shared LIB_PART will
     * be deleted when all LIB_ALIASes pointing to it are deleted.
94
     */
95
    LIB_PART*       shared;
96

97
    friend class LIB_PART;
98

99
protected:
100 101 102 103
    wxString        name;
    wxString        description;    ///< documentation for info
    wxString        keyWords;       ///< keyword list (used for search for parts by keyword)
    wxString        docFileName;    ///< Associate doc file name
104 105

public:
106 107
    LIB_ALIAS( const wxString& aName, LIB_PART* aRootComponent );
    LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_PART* aRootComponent = NULL );
108

109
    virtual ~LIB_ALIAS();
110

111 112
    virtual wxString GetClass() const
    {
113 114 115 116
        return wxT( "LIB_ALIAS" );
    }

    /**
117 118 119 120 121
     * Function GetPart
     * gets the shared LIB_PART.
     *
     * @return LIB_PART* - the LIB_PART shared by
     * this LIB_ALIAS with possibly other LIB_ALIASes.
122
     */
123
    LIB_PART* GetPart() const
124
    {
125
        return shared;
126 127
    }

128
    const wxString GetLibraryName();
129

130 131
    bool IsRoot() const;

132
    PART_LIB* GetLib();
133

134
    const wxString& GetName() const         { return name; }
135

136
    void SetName( const wxString& aName )   { name = aName; }
137 138 139 140 141

    void SetDescription( const wxString& aDescription )
    {
        description = aDescription;
    }
142

Dick Hollenbeck's avatar
Dick Hollenbeck committed
143
    wxString GetDescription() const { return description; }
144 145 146 147 148 149

    void SetKeyWords( const wxString& aKeyWords )
    {
        keyWords = aKeyWords;
    }

Dick Hollenbeck's avatar
Dick Hollenbeck committed
150
    wxString GetKeyWords() const { return keyWords; }
151 152 153 154 155 156

    void SetDocFileName( const wxString& aDocFileName )
    {
        docFileName = aDocFileName;
    }

Dick Hollenbeck's avatar
Dick Hollenbeck committed
157
    wxString GetDocFileName() const { return docFileName; }
158

159
    /**
160
     * Function SaveDocs
161
     * write the entry document information to \a aFormatter in "*.dcm" format.
162
     *
163
     * @param aFormatter The #OUTPUTFORMATTER to write the alias documents to.
164
     * @return True if success writing else false.
165
     */
166
    bool SaveDoc( OUTPUTFORMATTER& aFormatter );
167 168

    /**
169
     * KEEPCASE sensitive comparison of the part entry name.
170
     */
171 172
    bool operator==( const wxChar* aName ) const;
    bool operator!=( const wxChar* aName ) const
173
    {
174
        return !( *this == aName );
175 176
    }

177
    bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; }
178 179 180 181

#if defined(DEBUG)
    void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
#endif
182
};
183

184
extern bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 );
185

186
extern int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 );
187 188


189
/**
190 191
 * Class LIB_PART
 * defines a library part object.
192
 *
193 194
 * A library part object is typically saved and loaded in a part library file (.lib).
 * Library parts are different from schematic components.
195
 */
196
class LIB_PART : public EDA_ITEM
197
{
198
    friend class PART_LIB;
199 200
    friend class LIB_ALIAS;

201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
    PART_SPTR           m_me;               ///< http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
    wxString            m_name;
    int                 m_pinNameOffset;    ///< The offset in mils to draw the pin name.  Set to 0
                                            ///< to draw the pin name above the pin.
    bool                m_unitsLocked;      ///< True if part has multiple units and changing
                                            ///< one unit does not automatically change another unit.
    bool                m_showPinNames;     ///< Determines if part pin names are visible.
    bool                m_showPinNumbers;   ///< Determines if part pin numbers are visible.
    long                m_dateModified;     ///< Date the part was last modified.
    LibrEntryOptions    m_options;          ///< Special part features such as POWER or NORMAL.)
    int                 m_unitCount;        ///< Number of units (parts) per package.
    LIB_ITEMS           drawings;           ///< How to draw this part.
    wxArrayString       m_FootprintList;    /**< List of suitable footprint names for the
                                                 part (wild card names accepted). */
    LIB_ALIASES         m_aliases;          ///< List of alias object pointers associated with the
                                            ///< part.
    PART_LIB*           m_library;          ///< Library the part belongs to if any.

    static int  m_subpartIdSeparator;       ///< the separator char between
                                            ///< the subpart id and the reference
                                            ///< like U1A ( m_subpartIdSeparator = 0 ) or U1.A or U1-A
    static int  m_subpartFirstId;           ///< the ascii char value to calculate the subpart symbol id
                                            ///< from the part number: only 'A', 'a' or '1' can be used,
                                            ///< other values have no sense.
225
private:
226 227
    void deleteAllFields();

228 229
    // LIB_PART()  { }     // not legal

230
public:
231

232 233
    LIB_PART( const wxString& aName, PART_LIB* aLibrary = NULL );
    LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary = NULL );
234

235 236 237
    virtual ~LIB_PART();

    PART_SPTR    SharedPtr()
238
    {
239 240
        // clone a shared pointer
        return m_me;
241 242
    }

243 244 245 246
    virtual wxString GetClass() const
    {
        return wxT( "LIB_PART" );
    }
247

248
    virtual void SetName( const wxString& aName );
249

250
    const wxString& GetName()       { return m_name; }
251

252
    const wxString GetLibraryName();
253

254
    PART_LIB* GetLib()              { return m_library; }
255

256
    wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;
257

258
    size_t GetAliasCount() const    { return m_aliases.size(); }
259

260
    LIB_ALIAS* GetAlias( size_t aIndex );
261

262
    LIB_ALIAS* GetAlias( const wxString& aName );
263

264 265 266
    /**
     * Function AddAlias
     *
267
     * Add an alias \a aName to the part.
268 269
     *
     * Duplicate alias names are not added to the alias list.  Debug builds will raise an
270
     * assertion.  Release builds will fail silently.
271 272 273 274 275
     *
     * @param aName - Name of alias to add.
     */
    void AddAlias( const wxString& aName );

276
    /**
277
     * Test if alias \a aName is in part alias list.
278 279 280 281 282
     *
     * Alias name comparisons are case insensitive.
     *
     * @param aName - Name of alias.
     * @return True if alias name in alias list.
283
     */
284
    bool HasAlias( const wxString& aName ) const;
285

286
    void SetAliases( const wxArrayString& aAliasList );
287

288 289
    void RemoveAlias( const wxString& aName );
    LIB_ALIAS* RemoveAlias( LIB_ALIAS* aAlias );
290

291 292
    void RemoveAllAliases();

293
    wxArrayString& GetFootPrints() { return m_FootprintList; }
294

jean-pierre charras's avatar
jean-pierre charras committed
295 296
    /**
     * Function GetBoundingBox
297
     * @return the part bounding box ( in user coordinates )
jean-pierre charras's avatar
jean-pierre charras committed
298 299 300 301 302 303
     * @param aUnit = unit selection = 0, or 1..n
     * @param aConvert = 0, 1 or 2
     *  If aUnit == 0, unit is not used
     *  if aConvert == 0 Convert is non used
     *  Invisible fields are not taken in account
     **/
304
    const EDA_RECT GetBoundingBox( int aUnit, int aConvert ) const;
305

jean-pierre charras's avatar
jean-pierre charras committed
306 307
    /**
     * Function GetBodyBoundingBox
308
     * @return the part bounding box ( in user coordinates ) without fields
jean-pierre charras's avatar
jean-pierre charras committed
309 310 311 312 313 314
     * @param aUnit = unit selection = 0, or 1..n
     * @param aConvert = 0, 1 or 2
     *  If aUnit == 0, unit is not used
     *  if aConvert == 0 Convert is non used
     *  Fields are not taken in account
     **/
315
    const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
jean-pierre charras's avatar
jean-pierre charras committed
316

317 318
    /**
     * Function SaveDateAndTime
319
     * write the date and time of part to \a aFile in the format:
320 321
     * "Ti yy/mm/jj hh:mm:ss"
     *
322
     * @param aFormatter A reference to an #OUTPUTFORMATTER object containing the
323 324
     *                   output format to write to.
     * @return True if the date and time were successfully written to \a aFormatter.
325
     */
326
    bool SaveDateAndTime( OUTPUTFORMATTER& aFormatter );
327

328
    bool LoadDateAndTime( char* aLine );
329

330
    /**
331
     * Function Save
332
     * writes the data structures out to \a aFormatter in the part library "*.lib"
333
     * format.
334
     *
335
     * @param aFormatter A reference to an OUTPUTFORMATTER to write to.
336
     * @return True if success writing else false.
337
     */
338
    bool Save( OUTPUTFORMATTER& aFormatter );
339 340

    /**
341
     * Load part definition from \a aReader.
342
     *
343
     * @param aReader A LINE_READER object to load file from.
344
     * @param aErrorMsg - Description of error on load failure.
345
     * @return True if the load was successful, false if there was an error.
346
     */
347 348 349
    bool Load( LINE_READER& aReader, wxString& aErrorMsg );
    bool LoadField( LINE_READER& aReader, wxString& aErrorMsg );
    bool LoadDrawEntries( LINE_READER& aReader, wxString& aErrorMsg );
350
    bool LoadAliases( char* aLine, wxString& aErrorMsg );
351
    bool LoadFootprints( LINE_READER& aReader, wxString& aErrorMsg );
352

353 354
    bool IsPower()      { return m_options == ENTRY_POWER; }
    bool IsNormal()     { return m_options == ENTRY_NORMAL; }
355

356 357
    void SetPower()     { m_options = ENTRY_POWER; }
    void SetNormal()    { m_options = ENTRY_NORMAL; }
358

359
    void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
360
    bool UnitsLocked()  { return m_unitsLocked; }
361

362
    /**
363
     * Function SetFields
364
     * overwrites all the existing in this part with fields supplied
365
     * in \a aFieldsList.  The only known caller of this function is the
366
     * library part field editor, and it establishes needed behavior.
367
     *
368
`     * @param aFieldsList is a set of fields to import, removing all previous fields.
369
     */
370
    void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
371

372
    /**
373
     * Function GetFields
374 375
     * returns a list of fields withing this part. The only known caller of
     * this function is the library part field editor, and it establishes
376
     * needed behavior.
377
     *
378
     * @param aList - List to add fields to
379
     */
380
    void GetFields( LIB_FIELDS& aList );
381

382 383
    /**
     * Function FindField
384
     * finds a field within this part matching \a aFieldName and returns
385 386
     * it or NULL if not found.
     */
387
    LIB_FIELD* FindField( const wxString& aFieldName );
388

389 390 391
    /**
     * Return pointer to the requested field.
     *
392
     * @param aId - Id of field to return.
393
     * @return The field if found, otherwise NULL.
394
     */
395
    LIB_FIELD* GetField( int aId );
396 397

    /** Return reference to the value field. */
398
    LIB_FIELD& GetValueField();
399 400

    /** Return reference to the reference designator field. */
401
    LIB_FIELD& GetReferenceField();
402

403
    /**
404
     * Draw part.
405
     *
406
     * @param aPanel - Window to draw on. Can be NULL if not available.
407
     * @param aDc - Device context to draw on.
408 409
     * @param aOffset - Position of part.
     * @param aMulti - unit if multiple units per part.
410 411
     * @param aConvert - Component conversion (DeMorgan) if available.
     * @param aDrawMode - Device context drawing mode, see wxDC.
412
     * @param aColor - Color to draw part.
413
     * @param aTransform - Coordinate adjustment settings.
414 415 416 417
     * @param aShowPinText - Show pin text if true.
     * @param aDrawFields - Draw field text if true otherwise just draw
     *                      body items (useful to draw a body in schematic,
     *                      because fields of schematic components replace
418
     *                      the lib part fields).
419 420 421
     * @param aOnlySelected - Draws only the body items that are selected.
     *                        Used for block move redraws.
     */
422
    void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
423 424
               int aMulti, int aConvert, GR_DRAWMODE aDrawMode,
               EDA_COLOR_T aColor = UNSPECIFIED_COLOR,
425
               const TRANSFORM& aTransform = DefaultTransform,
426 427
               bool aShowPinText = true, bool aDrawFields = true,
               bool aOnlySelected = false );
428

429
    /**
430
     * Plot lib part to plotter.
431 432
     * Lib Fields not are plotted here, because this plot function
     * is used to plot schematic items, which have they own fields
433
     *
434 435 436
     * @param aPlotter - Plotter object to plot to.
     * @param aUnit - Component part to plot.
     * @param aConvert - Component alternate body style to plot.
437
     * @param aOffset - Distance to shift the plot coordinates.
438
     * @param aTransform - Component plot transform matrix.
439
     */
440
    void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
441 442 443
                const TRANSFORM& aTransform );

    /**
444 445
     * Plot Lib Fields only of the part to plotter.
     * is used to plot the full lib part, outside the schematic
446 447 448 449 450 451 452 453 454
     *
     * @param aPlotter - Plotter object to plot to.
     * @param aUnit - Component part to plot.
     * @param aConvert - Component alternate body style to plot.
     * @param aOffset - Distance to shift the plot coordinates.
     * @param aTransform - Component plot transform matrix.
     */
    void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
                        const wxPoint& aOffset, const TRANSFORM& aTransform );
455

456
    /**
457
     * Add a new draw \a aItem to the draw object list.
458
     *
459
     * @param aItem - New draw object to add to part.
460
     */
461
    void AddDrawItem( LIB_ITEM* aItem );
462

463
    /**
464
     * Remove draw \a aItem from list.
465
     *
466 467 468
     * @param aItem - Draw item to remove from list.
     * @param aPanel - Panel to remove part from.
     * @param aDc - Device context to remove part from.
469
     */
470
    void RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel = NULL, wxDC* aDc = NULL );
471

472
    /**
473 474
     * Return the next draw object pointer.
     *
475 476 477 478
     * @param aItem - Pointer to the current draw item.  Setting item NULL
     *                with return the first item of type in the list.
     * @param aType - type of searched item (filter).
     *                if TYPE_NOT_INIT search for all items types
479
     * @return - The next drawing object in the list if found, otherwise NULL.
480
     */
481
    LIB_ITEM* GetNextDrawItem( LIB_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT );
482

483 484 485 486 487
    /**
     * Return the next pin object from the draw list.
     *
     * This is just a pin object specific version of GetNextDrawItem().
     *
488 489
     * @param aItem - Pointer to the previous pin item, or NULL to get the
     *                first pin in the draw object list.
490
     * @return - The next pin object in the list if found, otherwise NULL.
491
     */
492
    LIB_PIN* GetNextPin( LIB_PIN* aItem = NULL )
493
    {
494
        return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
495 496
    }

497 498 499 500

    /**
     * Return a list of pin object pointers from the draw item list.
     *
501
     * Note pin objects are owned by the draw list of the part.
502 503 504
     * Deleting any of the objects will leave list in a unstable state
     * and will likely segfault when the list is destroyed.
     *
505 506
     * @param aList - Pin list to place pin object pointers into.
     * @param aUnit - Unit number of pin to add to list.  Set to 0 to
507
     *                get pins from any part unit.
508
     * @param aConvert - Convert number of pin to add to list.  Set to 0 to
509
     *                   get pins from any convert of part.
510
     */
511
    void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
512

513
    /**
514
     * Return pin object with the requested pin \a aNumber.
515
     *
516
     * @param aNumber - Number of the pin to find.
517
     * @param aUnit - Unit of the part to find.  Set to 0 if a specific
518 519 520
     *                unit number is not required.
     * @param aConvert - Alternate body style filter (DeMorgan).  Set to 0 if
     *                   no alternate body style is required.
521 522
     * @return The pin object if found.  Otherwise NULL.
     */
523
    LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
524

525
    /**
526
     * Move the part \a aOffset.
527
     *
528
     * @param aOffset - Offset displacement.
529
     */
530
    void SetOffset( const wxPoint& aOffset );
531 532 533 534 535 536 537

    /**
     * Remove duplicate draw items from list.
     */
    void RemoveDuplicateDrawItems();

    /**
538
     * Test if part has more than one body conversion type (DeMorgan).
539
     *
540
     * @return True if part has more than one conversion.
541 542 543
     */
    bool HasConversion() const;

544
    /**
545
     * Clears the status flag all draw objects in this part.
546
     */
547
    void ClearStatus();
548

549
    /**
550
     * Checks all draw objects of part to see if they are with block.
551 552 553 554
     *
     * Use this method to mark draw objects as selected during block
     * functions.
     *
555 556 557 558 559
     * @param aRect - The bounding rectangle to test in draw items are inside.
     * @param aUnit - The current unit number to test against.
     * @param aConvert - Are the draw items being selected a conversion.
     * @param aEditPinByPin - Used to ignore pin selections when in edit pin
     *                        by pin mode is enabled.
560 561
     * @return The number of draw objects found inside the block select
     *         rectangle.
562
     */
563
    int SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool aEditPinByPin );
564 565 566 567

    /**
     * Clears all the draw items marked by a block select.
     */
568
    void ClearSelectedItems();
569 570 571 572 573

    /**
     * Deletes the select draw items marked by a block select.
     *
     * The name and reference field will not be deleted.  They are the
574
     * minimum drawing items required for any part.  Their properties
575 576
     * can be changed but the cannot be removed.
     */
577
    void DeleteSelectedItems();
578 579 580 581

    /**
     * Move the selected draw items marked by a block select.
     */
582
    void MoveSelectedItems( const wxPoint& aOffset );
583 584 585 586

    /**
     * Make a copy of the selected draw items marked by a block select.
     *
587
     * Fields are not copied.  Only part body items are copied.
588 589 590
     * Copying fields would result in duplicate fields which does not
     * make sense in this context.
     */
591
    void CopySelectedItems( const wxPoint& aOffset );
592 593 594 595

    /**
     * Horizontally (X axis) mirror selected draw items about a point.
     *
596
     * @param aCenter - Center point to mirror around.
597
     */
598
    void MirrorSelectedItemsH( const wxPoint& aCenter );
599

600 601 602 603 604 605 606 607 608 609 610 611 612 613
    /**
     * Vertically (Y axis) mirror selected draw items about a point.
     *
     * @param aCenter - Center point to mirror around.
     */
    void MirrorSelectedItemsV( const wxPoint& aCenter );

    /**
     * Rotate CCW selected draw items about a point.
     *
     * @param aCenter - Center point to mirror around.
     */
    void RotateSelectedItems( const wxPoint& aCenter );

614 615 616
    /**
     * Locate a draw object.
     *
617 618 619 620
     * @param aUnit - Unit number of draw item.
     * @param aConvert - Body style of draw item.
     * @param aType - Draw object type, set to 0 to search for any type.
     * @param aPoint - Coordinate for hit testing.
621
     * @return The draw object if found.  Otherwise NULL.
622
     */
623
    LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
624

charras's avatar
charras committed
625 626 627
    /**
     * Locate a draw object (overlaid)
     *
628 629 630 631 632
     * @param aUnit - Unit number of draw item.
     * @param aConvert - Body style of draw item.
     * @param aType - Draw object type, set to 0 to search for any type.
     * @param aPoint - Coordinate for hit testing.
     * @param aTransform = the transform matrix
633
     * @return The draw object if found.  Otherwise NULL.
charras's avatar
charras committed
634
     */
635 636
    LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
                              const wxPoint& aPoint, const TRANSFORM& aTransform );
charras's avatar
charras committed
637

638 639 640
    /**
     * Return a reference to the draw item list.
     *
641
     * @return LIB_ITEMS& - Reference to the draw item object list.
642
     */
643
    LIB_ITEMS& GetDrawItemList() { return drawings; }
644 645

    /**
646
     * Set the units per part count.
647 648 649
     *
     * If the count is greater than the current count, then the all of the
     * current draw items are duplicated for each additional part.  If the
650 651
     * count is less than the current count, all draw objects for units
     * greater that count are removed from the part.
652
     *
653
     * @param count - Number of units per package.
654
     */
655
    void SetUnitCount( int count );
656

657
    int GetUnitCount() const { return m_unitCount; }
658

659 660
    /**
     * Function IsMulti
661
     * @return true if the part has multiple units per part.
662 663
     * When happens, the reference has a sub reference ti identify part
     */
664
    bool IsMulti() const { return m_unitCount > 1; }
665

666
    /**
667
     * Function SubReference
668
     * @return the sub reference for part having multiple units per part.
669 670
     * The sub reference identify the part (or unit)
     * @param aUnit = the part identifier ( 1 to max count)
671 672
     * @param aAddSeparator = true (default) to prpebd the sub ref
     *    by the separator symbol (if any)
673 674
     * Note: this is a static function.
     */
675
    static wxString SubReference( int aUnit, bool aAddSeparator = true );
676 677 678

    // Accessors to sub ref parameters
    static int GetSubpartIdSeparator() { return m_subpartIdSeparator; }
679 680 681 682 683 684

    /** return a reference to m_subpartIdSeparator,
     * only for read/save setting functions
     */
    static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }

685
    static int GetSubpartFirstId() { return m_subpartFirstId; }
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700

    /** return a reference to m_subpartFirstId, only for read/save setting functions
     */
    static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }

    /** Set the separator char between the subpart id and the reference
     * 0 (no separator) or '.' , '-' and '_'
     * and the ascii char value to calculate the subpart symbol id from the part number:
     * 'A' or '1' only are allowed. (to print U1.A or U1.1)
     * if this is a digit, a number is used as id symbol
     * Note also if the subpart symbol is a digit, the separator cannot be null.
     * @param aSep = the separator symbol (0 (no separator) or '.' , '-' and '_')
     * @param aFirstId = the Id of the first part ('A' or '1')
     */
    static void SetSubpartIdNotation( int aSep, int aFirstId );
701

702
    /**
703
     * Set or clear the alternate body style (DeMorgan) for the part.
704
     *
705
     * If the part already has an alternate body style set and a
706 707 708
     * asConvert if false, all of the existing draw items for the alternate
     * body style are remove.  If the alternate body style is not set and
     * asConvert is true, than the base draw items are duplicated and
709
     * added to the part.
710
     *
711
     * @param aSetConvert - Set or clear the part alternate body style.
712
     */
713
    void SetConversion( bool aSetConvert );
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728

    /**
     * Set the offset in mils of the pin name text from the pin symbol.
     *
     * Set the offset to 0 to draw the pin name above the pin symbol.
     *
     * @param aOffset - The offset in mils.
     */
    void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }

    int GetPinNameOffset() { return m_pinNameOffset; }

    /**
     * Set or clear the pin name visibility flag.
     *
729
     * @param aShow - True to make the part pin names visible.
730 731 732 733 734 735 736 737
     */
    void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }

    bool ShowPinNames() { return m_showPinNames; }

    /**
     * Set or clear the pin number visibility flag.
     *
738
     * @param aShow - True to make the part pin numbers visible.
739 740 741 742
     */
    void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }

    bool ShowPinNumbers() { return m_showPinNumbers; }
743

744
    bool operator==( const LIB_PART*  aPart ) const { return this == aPart; }
745

746 747 748 749
#if defined(DEBUG)
    void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
#endif
};
750 751

#endif  //  CLASS_LIBENTRY_H