You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

783 lines
28 KiB

8 years ago
8 years ago
8 years ago
8 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2022 CERN
  7. * Copyright (C) 2004-2022 KiCad Developers, see change_log.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #ifndef CLASS_LIBENTRY_H
  27. #define CLASS_LIBENTRY_H
  28. #include <general.h>
  29. #include <lib_tree_item.h>
  30. #include <lib_item.h>
  31. #include <lib_field.h>
  32. #include <vector>
  33. #include <multivector.h>
  34. class LINE_READER;
  35. class OUTPUTFORMATTER;
  36. class SYMBOL_LIB;
  37. class LIB_SYMBOL;
  38. class LIB_FIELD;
  39. class TEST_LIB_SYMBOL_FIXTURE;
  40. typedef std::shared_ptr<LIB_SYMBOL> LIB_SYMBOL_SPTR; ///< shared pointer to LIB_SYMBOL
  41. typedef std::weak_ptr<LIB_SYMBOL> LIB_SYMBOL_REF; ///< weak pointer to LIB_SYMBOL
  42. typedef MULTIVECTOR<LIB_ITEM, LIB_SHAPE_T, LIB_FIELD_T> LIB_ITEMS_CONTAINER;
  43. typedef LIB_ITEMS_CONTAINER::ITEM_PTR_VECTOR LIB_ITEMS;
  44. /* values for member .m_options */
  45. enum LIBRENTRYOPTIONS
  46. {
  47. ENTRY_NORMAL, // Libentry is a standard symbol (real or alias)
  48. ENTRY_POWER // Libentry is a power symbol
  49. };
  50. extern bool operator<( const LIB_SYMBOL& aItem1, const LIB_SYMBOL& aItem2 );
  51. struct LIB_SYMBOL_OPTIONS
  52. {
  53. TRANSFORM transform; // Coordinate adjustment settings
  54. bool force_draw_pin_text; // Whether or not to force the drawing of pin names and numbers
  55. bool draw_visible_fields; // Whether to draw "visible" fields
  56. bool draw_hidden_fields; // Whether to draw "hidden" fields
  57. bool show_elec_type; // Whether to show the pin electrical type
  58. bool show_connect_point; // Whether to show the pin connect point marker (small circle)
  59. // useful in dialog pin properties
  60. LIB_SYMBOL_OPTIONS()
  61. {
  62. transform = DefaultTransform;
  63. force_draw_pin_text = false;
  64. draw_visible_fields = true;
  65. draw_hidden_fields = true;
  66. show_elec_type = false;
  67. show_connect_point = false;
  68. }
  69. };
  70. struct LIB_SYMBOL_UNIT
  71. {
  72. int m_unit; ///< The unit number.
  73. int m_convert; ///< The alternate body style of the unit.
  74. std::vector<LIB_ITEM*> m_items; ///< The items unique to this unit and alternate body style.
  75. };
  76. /**
  77. * Define a library symbol object.
  78. *
  79. * A library symbol object is typically saved and loaded in a symbol library file (.lib).
  80. * Library symbols are different from schematic symbols.
  81. */
  82. class LIB_SYMBOL : public EDA_ITEM, public LIB_TREE_ITEM
  83. {
  84. public:
  85. LIB_SYMBOL( const wxString& aName, LIB_SYMBOL* aParent = nullptr,
  86. SYMBOL_LIB* aLibrary = nullptr );
  87. LIB_SYMBOL( const LIB_SYMBOL& aSymbol, SYMBOL_LIB* aLibrary = nullptr );
  88. virtual ~LIB_SYMBOL()
  89. {}
  90. ///< http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
  91. LIB_SYMBOL_SPTR SharedPtr() const { return m_me; }
  92. /**
  93. * Create a copy of a LIB_SYMBOL and assigns unique KIIDs to the copy and its children.
  94. */
  95. virtual LIB_SYMBOL* Duplicate() const
  96. {
  97. LIB_SYMBOL* dupe = new LIB_SYMBOL( *this, m_library );
  98. const_cast<KIID&>( dupe->m_Uuid ) = KIID();
  99. for( LIB_ITEM& item : dupe->m_drawings )
  100. const_cast<KIID&>( item.m_Uuid ) = KIID();
  101. return dupe;
  102. }
  103. void SetParent( LIB_SYMBOL* aParent = nullptr );
  104. LIB_SYMBOL_REF& GetParent() { return m_parent; }
  105. const LIB_SYMBOL_REF& GetParent() const { return m_parent; }
  106. void ClearCaches();
  107. virtual wxString GetClass() const override
  108. {
  109. return wxT( "LIB_SYMBOL" );
  110. }
  111. virtual void SetName( const wxString& aName );
  112. wxString GetName() const override { return m_name; }
  113. LIB_ID& LibId() { return m_libId; }
  114. LIB_ID GetLibId() const override { return m_libId; }
  115. void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
  116. wxString GetLibNickname() const override { return GetLibraryName(); }
  117. void SetDescription( const wxString& aDescription ) { m_description = aDescription; }
  118. wxString GetDescription() override
  119. {
  120. if( m_description.IsEmpty() && IsAlias() )
  121. {
  122. if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
  123. return parent->GetDescription();
  124. }
  125. return m_description;
  126. }
  127. void SetKeyWords( const wxString& aKeyWords ) { m_keyWords = aKeyWords; }
  128. wxString GetKeyWords() const
  129. {
  130. if( m_keyWords.IsEmpty() && IsAlias() )
  131. {
  132. if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
  133. return parent->GetKeyWords();
  134. }
  135. return m_keyWords;
  136. }
  137. wxString GetSearchText() override;
  138. wxString GetFootprint() override
  139. {
  140. return GetFootprintField().GetText();
  141. }
  142. void GetChooserFields( std::map<wxString , wxString>& aColumnMap ) override;
  143. /**
  144. * For symbols derived from other symbols, IsRoot() indicates no derivation.
  145. */
  146. bool IsRoot() const override { return m_parent.use_count() == 0; }
  147. bool IsAlias() const { return !m_parent.expired() && m_parent.use_count() > 0; }
  148. const wxString GetLibraryName() const;
  149. SYMBOL_LIB* GetLib() const { return m_library; }
  150. void SetLib( SYMBOL_LIB* aLibrary ) { m_library = aLibrary; }
  151. timestamp_t GetLastModDate() const { return m_lastModDate; }
  152. void SetFPFilters( const wxArrayString& aFilters ) { m_fpFilters = aFilters; }
  153. wxArrayString GetFPFilters() const
  154. {
  155. if( m_fpFilters.IsEmpty() && IsAlias() )
  156. {
  157. if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
  158. return parent->GetFPFilters();
  159. }
  160. return m_fpFilters;
  161. }
  162. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  163. /**
  164. * Get the bounding box for the symbol.
  165. *
  166. * @return the symbol bounding box ( in user coordinates )
  167. * @param aUnit = unit selection = 0, or 1..n
  168. * @param aConvert = 0, 1 or 2
  169. * If aUnit == 0, unit is not used
  170. * if aConvert == 0 Convert is non used
  171. * @param aIgnoreHiddenFields default true, ignores any hidden fields
  172. **/
  173. const BOX2I GetUnitBoundingBox( int aUnit, int aConvert, bool aIgnoreHiddenFields = true ) const;
  174. /**
  175. * Get the symbol bounding box excluding fields.
  176. *
  177. * @return the symbol bounding box ( in user coordinates ) without fields
  178. * @param aUnit = unit selection = 0, or 1..n
  179. * @param aConvert = 0, 1 or 2
  180. * If aUnit == 0, unit is not used
  181. * if aConvert == 0 Convert is non used
  182. * Fields are not taken in account
  183. **/
  184. const BOX2I GetBodyBoundingBox( int aUnit, int aConvert, bool aIncludePins,
  185. bool aIncludePrivateItems ) const;
  186. const BOX2I GetBoundingBox() const override
  187. {
  188. return GetUnitBoundingBox( 0, 0 );
  189. }
  190. bool IsPower() const;
  191. bool IsNormal() const;
  192. void SetPower();
  193. void SetNormal();
  194. /**
  195. * Set interchangeable the property for symbol units.
  196. * @param aLockUnits when true then units are set as not interchangeable.
  197. */
  198. void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
  199. /**
  200. * Check whether symbol units are interchangeable.
  201. * @return False when interchangeable, true otherwise.
  202. */
  203. bool UnitsLocked() const { return m_unitsLocked; }
  204. /**
  205. * Overwrite all the existing fields in this symbol with fields supplied in \a aFieldsList.
  206. *
  207. * @param aFieldsList is a set of fields to import, removing all previous fields.
  208. */
  209. void SetFields( const std::vector<LIB_FIELD>& aFieldsList );
  210. /**
  211. * Return a list of fields within this symbol.
  212. *
  213. * @param aList - List to add fields to
  214. */
  215. void GetFields( std::vector<LIB_FIELD*>& aList );
  216. void GetFields( std::vector<LIB_FIELD>& aList );
  217. /**
  218. * Add a field. Takes ownership of the pointer.
  219. */
  220. void AddField( LIB_FIELD* aField );
  221. void AddField( LIB_FIELD& aField ) { AddField( new LIB_FIELD( aField ) ); }
  222. /**
  223. * Find a field within this symbol matching \a aFieldName and returns it
  224. * or NULL if not found.
  225. */
  226. LIB_FIELD* FindField( const wxString& aFieldName );
  227. const LIB_FIELD* FindField( const wxString& aFieldName ) const;
  228. /**
  229. * Return pointer to the requested field.
  230. *
  231. * @param aId - Id of field to return.
  232. * @return The field if found, otherwise NULL.
  233. */
  234. LIB_FIELD* GetFieldById( int aId ) const;
  235. /** Return reference to the value field. */
  236. LIB_FIELD& GetValueField();
  237. /** Return reference to the reference designator field. */
  238. LIB_FIELD& GetReferenceField();
  239. /** Return reference to the footprint field */
  240. LIB_FIELD& GetFootprintField();
  241. /** Return reference to the datasheet field. */
  242. LIB_FIELD& GetDatasheetField();
  243. wxString GetPrefix();
  244. /**
  245. * Order optional field indices.
  246. *
  247. * It's possible when calling #LIB_SYMBOL::Flatten that there can be gaps and/or duplicate
  248. * optional field indices. This method correctly orders the indices so there are no gaps
  249. * and/or duplicate indices.
  250. */
  251. int UpdateFieldOrdinals();
  252. int GetNextAvailableFieldId() const;
  253. /**
  254. * Print symbol.
  255. *
  256. * @param aOffset - Position of symbol.
  257. * @param aMulti - unit if multiple units per symbol.
  258. * @param aConvert - Symbol conversion (DeMorgan) if available.
  259. * @param aOpts - Drawing options
  260. * @param aDimmed - Reduce brightness of symbol
  261. */
  262. void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, int aMulti, int aConvert,
  263. const LIB_SYMBOL_OPTIONS& aOpts, bool aDimmed );
  264. /**
  265. * Print just the background fills of a symbol
  266. *
  267. * @param aOffset - Position of symbol.
  268. * @param aMulti - unit if multiple units per symbol.
  269. * @param aConvert - Symbol conversion (DeMorgan) if available.
  270. * @param aOpts - Drawing options
  271. * @param aDimmed - Reduce brightness of symbol
  272. */
  273. void PrintBackground( const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, int aMulti,
  274. int aConvert, const LIB_SYMBOL_OPTIONS &aOpts, bool aDimmed );
  275. /**
  276. * Plot lib symbol to plotter.
  277. * Lib Fields not are plotted here, because this plot function
  278. * is used to plot schematic items, which have they own fields
  279. *
  280. * @param aPlotter - Plotter object to plot to.
  281. * @param aUnit - Symbol symbol to plot.
  282. * @param aConvert - Symbol alternate body style to plot.
  283. * @param aBackground - A poor-man's Z-order.
  284. * @param aOffset - Distance to shift the plot coordinates.
  285. * @param aTransform - Symbol plot transform matrix.
  286. * @param aDimmed - Reduce brightness of symbol
  287. */
  288. void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, bool aBackground,
  289. const VECTOR2I& aOffset, const TRANSFORM& aTransform, bool aDimmed ) const;
  290. /**
  291. * Plot Lib Fields only of the symbol to plotter.
  292. * is used to plot the full lib symbol, outside the schematic
  293. *
  294. * @param aPlotter - Plotter object to plot to.
  295. * @param aUnit - Symbol to plot.
  296. * @param aConvert - Symbol alternate body style to plot.
  297. * @param aBackground - A poor-man's Z-order.
  298. * @param aOffset - Distance to shift the plot coordinates.
  299. * @param aTransform - Symbol plot transform matrix.
  300. * @param aDimmed - reduce brightness of fields
  301. */
  302. void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, bool aBackground,
  303. const VECTOR2I& aOffset, const TRANSFORM& aTransform, bool aDimmed );
  304. /**
  305. * Add a new draw \a aItem to the draw object list and sort according to \a aSort.
  306. *
  307. * @param aItem is the new draw object to add to the symbol.
  308. * @param aSort is the flag to determine if the newly added item should be sorted.
  309. */
  310. void AddDrawItem( LIB_ITEM* aItem, bool aSort = true );
  311. /**
  312. * Remove draw \a aItem from list.
  313. *
  314. * @param aItem - Draw item to remove from list.
  315. */
  316. void RemoveDrawItem( LIB_ITEM* aItem );
  317. void RemoveField( LIB_FIELD* aField ) { RemoveDrawItem( aField ); }
  318. /**
  319. * Return the next draw object pointer.
  320. *
  321. * @param aItem - Pointer to the current draw item. Setting item NULL
  322. * with return the first item of type in the list.
  323. * @param aType - type of searched item (filter).
  324. * if TYPE_NOT_INIT search for all items types
  325. * @return - The next drawing object in the list if found, otherwise NULL.
  326. */
  327. LIB_ITEM* GetNextDrawItem( const LIB_ITEM* aItem = nullptr, KICAD_T aType = TYPE_NOT_INIT );
  328. size_t GetPinCount() const { return m_drawings.size( LIB_PIN_T ); }
  329. size_t GetFieldCount() const { return m_drawings.size( LIB_FIELD_T ); }
  330. /**
  331. * Return the next pin object from the draw list.
  332. *
  333. * This is just a pin object specific version of GetNextDrawItem().
  334. *
  335. * @param aItem - Pointer to the previous pin item, or NULL to get the first pin in the draw
  336. * object list.
  337. * @return - The next pin object in the list if found, otherwise NULL.
  338. */
  339. LIB_PIN* GetNextPin( LIB_PIN* aItem = nullptr )
  340. {
  341. return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
  342. }
  343. /**
  344. * Return a list of pin object pointers from the draw item list.
  345. *
  346. * Note pin objects are owned by the draw list of the symbol. Deleting any of the objects
  347. * will leave list in a unstable state and will likely segfault when the list is destroyed.
  348. *
  349. * @param aList - Pin list to place pin object pointers into.
  350. * @param aUnit - Unit number of pins to collect. Set to 0 to get pins from any symbol unit.
  351. * @param aConvert - Convert number of pins to collect. Set to 0 to get pins from any
  352. * DeMorgan variant of symbol.
  353. */
  354. void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 ) const;
  355. /**
  356. * Return a list of pin pointers for all units / converts. Used primarily for SPICE where
  357. * we want to treat all unit as a single part.
  358. */
  359. std::vector<LIB_PIN*> GetAllLibPins() const;
  360. /**
  361. * @return a count of pins for all units / converts.
  362. */
  363. size_t GetFullPinCount() { return GetAllLibPins().size(); }
  364. /**
  365. * Return pin object with the requested pin \a aNumber.
  366. *
  367. * @param aNumber - Number of the pin to find.
  368. * @param aUnit - Unit filter. Set to 0 if a specific unit number is not required.
  369. * @param aConvert - DeMorgan variant filter. Set to 0 if no specific DeMorgan variant is
  370. * required.
  371. * @return The pin object if found. Otherwise NULL.
  372. */
  373. LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 ) const;
  374. /**
  375. * Return true if this symbol's pins do not match another symbol's pins. This is used to
  376. * detect whether the project cache is out of sync with the system libs.
  377. *
  378. * @param aOtherSymbol - The other library symbol to test
  379. * @param aTestNums - Whether two pins at the same point must have the same number.
  380. * @param aTestNames - Whether two pins at the same point must have the same name.
  381. * @param aTestType - Whether two pins at the same point must have the same electrical type.
  382. * @param aTestOrientation - Whether two pins at the same point must have the same orientation.
  383. * @param aTestLength - Whether two pins at the same point must have the same length.
  384. */
  385. bool PinsConflictWith( const LIB_SYMBOL& aOtherSymbol, bool aTestNums, bool aTestNames,
  386. bool aTestType, bool aTestOrientation, bool aTestLength ) const;
  387. /**
  388. * Move the symbol \a aOffset.
  389. *
  390. * @param aOffset - Offset displacement.
  391. */
  392. void SetOffset( const VECTOR2I& aOffset );
  393. /**
  394. * Remove duplicate draw items from list.
  395. */
  396. void RemoveDuplicateDrawItems();
  397. /**
  398. * Test if symbol has more than one body conversion type (DeMorgan).
  399. *
  400. * @return True if symbol has more than one conversion.
  401. */
  402. bool HasConversion() const;
  403. /**
  404. * @return the highest pin number of the symbol's pins.
  405. * If none of the pins has pin number assigned it returns 0.
  406. */
  407. int GetMaxPinNumber() const;
  408. /**
  409. * Clears the status flag all draw objects in this symbol.
  410. */
  411. void ClearTempFlags();
  412. void ClearEditFlags();
  413. /**
  414. * Locate a draw object.
  415. *
  416. * @param aUnit - Unit number of draw item.
  417. * @param aConvert - Body style of draw item.
  418. * @param aType - Draw object type, set to 0 to search for any type.
  419. * @param aPoint - Coordinate for hit testing.
  420. * @return The draw object if found. Otherwise NULL.
  421. */
  422. LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const VECTOR2I& aPoint );
  423. /**
  424. * Locate a draw object (overlaid)
  425. *
  426. * @param aUnit - Unit number of draw item.
  427. * @param aConvert - Body style of draw item.
  428. * @param aType - Draw object type, set to 0 to search for any type.
  429. * @param aPoint - Coordinate for hit testing.
  430. * @param aTransform = the transform matrix
  431. * @return The draw object if found. Otherwise NULL.
  432. */
  433. LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const VECTOR2I& aPoint,
  434. const TRANSFORM& aTransform );
  435. /**
  436. * Return a reference to the draw item list.
  437. *
  438. * @return LIB_ITEMS_CONTAINER& - Reference to the draw item object container.
  439. */
  440. LIB_ITEMS_CONTAINER& GetDrawItems() { return m_drawings; }
  441. const LIB_ITEMS_CONTAINER& GetDrawItems() const { return m_drawings; }
  442. INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
  443. const std::vector<KICAD_T>& aScanTypes ) override;
  444. /**
  445. * Set the units per symbol count.
  446. *
  447. * If the count is greater than the current count, then the all of the
  448. * current draw items are duplicated for each additional symbol. If the
  449. * count is less than the current count, all draw objects for units
  450. * greater that count are removed from the symbol.
  451. *
  452. * @param aCount - Number of units per package.
  453. * @param aDuplicateDrawItems Create duplicate draw items of unit 1 for each additionl unit.
  454. */
  455. void SetUnitCount( int aCount, bool aDuplicateDrawItems = true );
  456. int GetUnitCount() const override;
  457. /**
  458. * Return an identifier for \a aUnit for symbols with units.
  459. */
  460. wxString GetUnitReference( int aUnit ) override;
  461. /**
  462. * Return true if the given unit \a aUnit has a display name defined
  463. */
  464. bool HasUnitDisplayName( int aUnit ) override;
  465. /**
  466. * Return the user-defined display name for \a aUnit for symbols with units.
  467. */
  468. wxString GetUnitDisplayName( int aUnit ) override;
  469. /**
  470. * Copy all unit display names into the given map \a aTarget
  471. */
  472. void CopyUnitDisplayNames( std::map<int, wxString>& aTarget ) const;
  473. /**
  474. * Set the user-defined display name for \a aUnit to \a aName for symbols with units.
  475. */
  476. void SetUnitDisplayName( int aUnit, const wxString& aName );
  477. /**
  478. * @return true if the symbol has multiple units per symbol.
  479. * When true, the reference has a sub reference to identify symbol.
  480. */
  481. bool IsMulti() const { return m_unitCount > 1; }
  482. /**
  483. * @return the sub reference for symbol having multiple units per symbol.
  484. * The sub reference identify the symbol (or unit)
  485. * @param aUnit = the symbol identifier ( 1 to max count)
  486. * @param aAddSeparator = true (default) to prepend the sub ref
  487. * by the separator symbol (if any)
  488. * Note: this is a static function.
  489. */
  490. static wxString SubReference( int aUnit, bool aAddSeparator = true );
  491. // Accessors to sub ref parameters
  492. static int GetSubpartIdSeparator() { return m_subpartIdSeparator; }
  493. /**
  494. * Return a reference to m_subpartIdSeparator, only for read/save setting functions.
  495. */
  496. static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
  497. static int GetSubpartFirstId() { return m_subpartFirstId; }
  498. /**
  499. * Return a reference to m_subpartFirstId, only for read/save setting functions.
  500. */
  501. static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
  502. /**
  503. * Set the separator char between the subpart id and the reference
  504. * 0 (no separator) or '.' , '-' and '_'
  505. * and the ascii char value to calculate the subpart symbol id from the symbol number:
  506. * 'A' or '1' only are allowed. (to print U1.A or U1.1)
  507. * if this is a digit, a number is used as id symbol
  508. * Note also if the subpart symbol is a digit, the separator cannot be null.
  509. * @param aSep = the separator symbol (0 (no separator) or '.' , '-' and '_')
  510. * @param aFirstId = the Id of the first symbol ('A' or '1')
  511. */
  512. static void SetSubpartIdNotation( int aSep, int aFirstId );
  513. /**
  514. * Set or clear the alternate body style (DeMorgan) for the symbol.
  515. *
  516. * If the symbol already has an alternate body style set and a
  517. * asConvert if false, all of the existing draw items for the alternate
  518. * body style are remove. If the alternate body style is not set and
  519. * asConvert is true, than the base draw items are duplicated and
  520. * added to the symbol.
  521. *
  522. * @param aSetConvert - Set or clear the symbol alternate body style.
  523. * @param aDuplicatePins - Duplicate all pins from original body style if true.
  524. */
  525. void SetConversion( bool aSetConvert, bool aDuplicatePins = true );
  526. /**
  527. * Set the offset in mils of the pin name text from the pin symbol.
  528. *
  529. * Set the offset to 0 to draw the pin name above the pin symbol.
  530. *
  531. * @param aOffset - The offset in mils.
  532. */
  533. void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
  534. int GetPinNameOffset() const { return m_pinNameOffset; }
  535. /**
  536. * Set or clear the pin name visibility flag.
  537. *
  538. * @param aShow - True to make the symbol pin names visible.
  539. */
  540. void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
  541. bool ShowPinNames() const { return m_showPinNames; }
  542. /**
  543. * Set or clear the pin number visibility flag.
  544. *
  545. * @param aShow - True to make the symbol pin numbers visible.
  546. */
  547. void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
  548. bool ShowPinNumbers() const { return m_showPinNumbers; }
  549. /**
  550. * Set or clear the include in schematic bill of materials flag.
  551. *
  552. * @param aIncludeInBom true to include symbol in schematic bill of material
  553. */
  554. void SetIncludeInBom( bool aIncludeInBom ) { m_includeInBom = aIncludeInBom; }
  555. bool GetIncludeInBom() const { return m_includeInBom; }
  556. /**
  557. * Set or clear include in board netlist flag.
  558. *
  559. * @param aIncludeOnBoard true to include symbol in the board netlist
  560. */
  561. void SetIncludeOnBoard( bool aIncludeOnBoard ) { m_includeOnBoard = aIncludeOnBoard; }
  562. bool GetIncludeOnBoard() const { return m_includeOnBoard; }
  563. /**
  564. * Comparison test that can be used for operators.
  565. *
  566. * @param aRhs is the right hand side symbol used for comparison.
  567. *
  568. * @return -1 if this symbol is less than \a aRhs
  569. * 1 if this symbol is greater than \a aRhs
  570. * 0 if this symbol is the same as \a aRhs
  571. */
  572. int Compare( const LIB_SYMBOL& aRhs, int aCompareFlags = 0 ) const;
  573. bool operator==( const LIB_SYMBOL* aSymbol ) const { return this == aSymbol; }
  574. bool operator==( const LIB_SYMBOL& aSymbol ) const
  575. {
  576. return Compare( aSymbol, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) == 0;
  577. }
  578. bool operator!=( const LIB_SYMBOL& aSymbol ) const
  579. {
  580. return Compare( aSymbol, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) != 0;
  581. }
  582. const LIB_SYMBOL& operator=( const LIB_SYMBOL& aSymbol );
  583. /**
  584. * Return a flattened symbol inheritance to the caller.
  585. *
  586. * If the symbol does not inherit from another symbol, a copy of the symbol is returned.
  587. *
  588. * @return a flattened symbol on the heap
  589. */
  590. std::unique_ptr< LIB_SYMBOL > Flatten() const;
  591. /**
  592. * Return a list of LIB_ITEM objects separated by unit and convert number.
  593. *
  594. * @note This does not include LIB_FIELD objects since they are not associated with
  595. * unit and/or convert numbers.
  596. */
  597. std::vector<struct LIB_SYMBOL_UNIT> GetUnitDrawItems();
  598. /**
  599. * Return a list of unit numbers that are unique to this symbol.
  600. *
  601. * If the symbol is inherited (alias), the unique units of the parent symbol are returned.
  602. * When comparing pins, the pin number is ignored.
  603. *
  604. * @return a list of unique unit numbers and their associated draw items.
  605. */
  606. std::vector<struct LIB_SYMBOL_UNIT> GetUniqueUnits();
  607. /**
  608. * Return a list of item pointers for \a aUnit and \a aConvert for this symbol.
  609. *
  610. * @note #LIB_FIELD objects are not included.
  611. *
  612. * @param aUnit is the unit number of the item, -1 includes all units.
  613. * @param aConvert is the alternate body styple of the item, -1 includes all body styles.
  614. *
  615. * @return a list of unit items.
  616. */
  617. std::vector<LIB_ITEM*> GetUnitDrawItems( int aUnit, int aConvert );
  618. #if defined(DEBUG)
  619. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  620. #endif
  621. private:
  622. // We create a different set parent function for this class, so we hide the inherited one.
  623. using EDA_ITEM::SetParent;
  624. void deleteAllFields();
  625. private:
  626. LIB_SYMBOL_SPTR m_me;
  627. LIB_SYMBOL_REF m_parent; ///< Use for inherited symbols.
  628. LIB_ID m_libId;
  629. timestamp_t m_lastModDate;
  630. int m_unitCount; ///< Number of units (parts) per package.
  631. bool m_unitsLocked; ///< True if symbol has multiple units and changing one
  632. ///< unit does not automatically change another unit.
  633. int m_pinNameOffset; ///< The offset in mils to draw the pin name. Set to
  634. ///< 0 to draw the pin name above the pin.
  635. bool m_showPinNames;
  636. bool m_showPinNumbers;
  637. bool m_includeInBom;
  638. bool m_includeOnBoard;
  639. LIBRENTRYOPTIONS m_options; ///< Special symbol features such as POWER or NORMAL.)
  640. LIB_ITEMS_CONTAINER m_drawings;
  641. SYMBOL_LIB* m_library;
  642. wxString m_name;
  643. wxString m_description;
  644. wxString m_keyWords; ///< Search keywords
  645. wxArrayString m_fpFilters; ///< List of suitable footprint names for the
  646. ///< symbol (wild card names accepted).
  647. static int m_subpartIdSeparator; ///< the separator char between
  648. ///< the subpart id and the reference like U1A
  649. ///< ( m_subpartIdSeparator = 0 ) or U1.A or U1-A
  650. static int m_subpartFirstId; ///< the ASCII char value to calculate the subpart
  651. ///< symbol id from the symbol number: only 'A', 'a'
  652. ///< or '1' can be used, other values have no sense.
  653. std::map<int, wxString> m_unitDisplayNames;
  654. };
  655. #endif // CLASS_LIBENTRY_H