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.

685 lines
25 KiB

Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
18 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  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) 2014 Dick Hollenbeck, dick@softplc.com
  6. * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.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 COMPONENT_CLASS_H
  27. #define COMPONENT_CLASS_H
  28. #include <eda_item.h>
  29. #include <core/typeinfo.h>
  30. #include <layers_id_colors_and_visibility.h>
  31. #include <lib_id.h>
  32. #include <widgets/msgpanel.h>
  33. #include <memory>
  34. #include <string>
  35. #include <unordered_map>
  36. #include <vector>
  37. #include <wx/arrstr.h>
  38. #include <wx/chartype.h>
  39. #include <wx/fdrepdlg.h>
  40. #include <wx/gdicmn.h>
  41. #include <wx/string.h>
  42. #include <bitmaps.h>
  43. #include <sch_field.h>
  44. #include <sch_item.h>
  45. #include <sch_pin.h>
  46. #include <sch_sheet_path.h> // COMPONENT_INSTANCE_REFERENCE
  47. #include <symbol_lib_table.h>
  48. #include <transform.h>
  49. struct PICKED_SYMBOL;
  50. class SCH_SCREEN;
  51. class LIB_ITEM;
  52. class LIB_PIN;
  53. class LIB_PART;
  54. class NETLIST_OBJECT_LIST;
  55. class PART_LIB;
  56. class PART_LIBS;
  57. class EE_COLLECTOR;
  58. class SCH_SCREEN;
  59. class SYMBOL_LIB_TABLE;
  60. /// A container for several SCH_FIELD items
  61. typedef std::vector<SCH_FIELD> SCH_FIELDS;
  62. typedef std::weak_ptr<LIB_PART> PART_REF;
  63. extern std::string toUTFTildaText( const wxString& txt );
  64. /**
  65. * Schematic symbol object.
  66. */
  67. class SCH_COMPONENT : public SCH_ITEM
  68. {
  69. private:
  70. wxPoint m_Pos;
  71. LIB_ID m_lib_id; ///< Name and library the symbol was loaded from, i.e. 74xx:74LS00.
  72. int m_unit; ///< The unit for multiple part per package components.
  73. int m_convert; ///< The alternate body style for components that have more than
  74. ///< one body style defined. Primarily used for components that
  75. ///< have a De Morgan conversion.
  76. wxString m_prefix; ///< C, R, U, Q etc - the first character which typically indicates
  77. ///< what the component is. Determined, upon placement, from the
  78. ///< library component. Created upon file load, by the first
  79. ///< non-digits in the reference fields.
  80. /**
  81. * The name used to look up a symbol in the symbol library embedded in a schematic.
  82. *
  83. * By default this is the same as #LIB_ID::GetLibItemName(). However, schematics allow for
  84. * multiple variants of the same library symbol. Set this member in order to preserve the
  85. * link to the original symbol library. If empty, #LIB_ID::GetLibItemName() should be used.
  86. */
  87. wxString m_schLibSymbolName;
  88. TRANSFORM m_transform; ///< The rotation/mirror transformation matrix.
  89. SCH_FIELDS m_Fields; ///< Variable length list of fields.
  90. std::unique_ptr< LIB_PART > m_part; // a flattened copy of the LIB_PART from
  91. // the PROJECT's libraries.
  92. std::vector<std::unique_ptr<SCH_PIN>> m_pins; // a SCH_PIN for every LIB_PIN (all units)
  93. std::unordered_map<LIB_PIN*, unsigned> m_pinMap; // library pin pointer to SCH_PIN's index
  94. bool m_isInNetlist; ///< True if the component should appear in the netlist
  95. bool m_inBom; ///< True to include in bill of materials export.
  96. bool m_onBoard; ///< True to include in netlist when updating board.
  97. // Defines the hierarchical path and reference of the component. This allows support
  98. // for multiple references to a single sub-sheet.
  99. std::vector<SYMBOL_INSTANCE_REFERENCE> m_instanceReferences;
  100. void Init( const wxPoint& pos = wxPoint( 0, 0 ) );
  101. public:
  102. SCH_COMPONENT( const wxPoint& pos = wxPoint( 0, 0 ), SCH_ITEM* aParent = NULL );
  103. /**
  104. * Create schematic component from library component object.
  105. *
  106. * @param aPart - library part to create schematic component from.
  107. * @param aLibId - libId of alias to create.
  108. * @param aSheet - Schematic sheet the component is place into.
  109. * @param unit - Part for components that have multiple parts per
  110. * package.
  111. * @param convert - Use the alternate body style for the schematic
  112. * component.
  113. * @param pos - Position to place new component.
  114. * @param setNewItemFlag - Set the component IS_NEW and IS_MOVED flags.
  115. */
  116. SCH_COMPONENT( LIB_PART& aPart, LIB_ID aLibId, SCH_SHEET_PATH* aSheet,
  117. int unit = 0, int convert = 0,
  118. const wxPoint& pos = wxPoint( 0, 0 ) );
  119. SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* aSheet, PICKED_SYMBOL& aSel,
  120. const wxPoint& pos = wxPoint( 0, 0 ) );
  121. /**
  122. * Clones \a aComponent into a new schematic symbol object.
  123. *
  124. * All fields are copied as is except for the linked list management pointers
  125. * which are set to NULL, and the SCH_FIELD's m_Parent pointers which are set
  126. * to the new object.
  127. *
  128. * @param aComponent is the schematic symbol to clone.
  129. */
  130. SCH_COMPONENT( const SCH_COMPONENT& aComponent );
  131. ~SCH_COMPONENT() { }
  132. static inline bool ClassOf( const EDA_ITEM* aItem )
  133. {
  134. return aItem && SCH_COMPONENT_T == aItem->Type();
  135. }
  136. wxString GetClass() const override
  137. {
  138. return wxT( "SCH_COMPONENT" );
  139. }
  140. const std::vector<SYMBOL_INSTANCE_REFERENCE>& GetInstanceReferences()
  141. {
  142. return m_instanceReferences;
  143. }
  144. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  145. /**
  146. * Return true for items which are moved with the anchor point at mouse cursor
  147. * and false for items moved with no reference to anchor.
  148. *
  149. * Usually return true for small items (labels, junctions) and false for items which can
  150. * be large (hierarchical sheets, components).
  151. *
  152. * Note: we used to try and be smart about this and return false for components in case
  153. * they are big. However, this annoyed some users and we now have a preference which
  154. * controls warping on move in general, so this was switched to true for components.
  155. *
  156. * @return true for a component
  157. */
  158. bool IsMovableFromAnchorPoint() override { return true; }
  159. void SetLibId( const LIB_ID& aName );
  160. const LIB_ID& GetLibId() const { return m_lib_id; }
  161. /**
  162. * The name of the symbol in the schematic library symbol list.
  163. *
  164. * @note See #SCH_SCREEN::m_libSymbols
  165. *
  166. * The name of the schematic symbol list entry can vary from the item name in the #LIB_ID
  167. * object because the library symbol may have changed so a new name has to be generated
  168. * but the original symbol library link has to be preserved in order to update it from
  169. * the library at some point in the future. If this name is empty, then the library item
  170. * name from #LIB_ID is used.
  171. */
  172. void SetSchSymbolLibraryName( const wxString& aName ) { m_schLibSymbolName = aName; }
  173. wxString GetSchSymbolLibraryName() const;
  174. bool UseLibIdLookup() const { return m_schLibSymbolName.IsEmpty(); }
  175. std::unique_ptr< LIB_PART >& GetPartRef() { return m_part; }
  176. /**
  177. * Set this schematic symbol library symbol reference to \a aLibSymbol
  178. *
  179. * The schematic symbol object owns \a aLibSymbol and the pin list will be updated
  180. * accordingly. The #LIB_PART object can be null to clear the library symbol link
  181. * as well as the pin map. If the #LIB_PART object is not null, it must be a root
  182. * symbol. Otherwise an assertion will be raised in debug builds and the library
  183. * symbol will be cleared. The new file format will no longer require a cache
  184. * library so all library symbols must be valid.
  185. *
  186. * @note This is the only way to publicly set the library symbol for a schematic
  187. * symbol except for the ctors that take a LIB_PART reference. All previous
  188. * public resolvers have been deprecated.
  189. *
  190. * @param aLibSymbol is the library symbol to associate with this schematic symbol.
  191. */
  192. void SetLibSymbol( LIB_PART* aLibSymbol );
  193. /**
  194. * Return information about the aliased parts
  195. */
  196. wxString GetDescription() const;
  197. /**
  198. * Return the documentation text for the given part alias
  199. */
  200. wxString GetDatasheet() const;
  201. int GetUnit() const { return m_unit; }
  202. /**
  203. * Updates the cache of SCH_PIN objects for each pin
  204. */
  205. void UpdatePins();
  206. /**
  207. * Change the unit number to \a aUnit
  208. *
  209. * This has meaning only for symbols made up of multiple units per package.
  210. *
  211. * @note This also set the modified flag bit
  212. *
  213. * @param aUnit is the new unit to select.
  214. */
  215. void SetUnit( int aUnit );
  216. /**
  217. * Change the unit number to \a aUnit without setting any internal flags.
  218. * This has meaning only for symbols made up of multiple units per package.
  219. *
  220. * @note This also set the modified flag bit
  221. *
  222. * @param aUnit is the new unit to select.
  223. */
  224. void UpdateUnit( int aUnit );
  225. int GetConvert() const { return m_convert; }
  226. void SetConvert( int aConvert );
  227. wxString GetPrefix() const { return m_prefix; }
  228. void SetPrefix( const wxString& aPrefix ) { m_prefix = aPrefix; }
  229. TRANSFORM& GetTransform() const { return const_cast< TRANSFORM& >( m_transform ); }
  230. void SetTransform( const TRANSFORM& aTransform );
  231. /**
  232. * Return the number of units per package of the symbol.
  233. *
  234. * @return the number of units per package or zero if the library entry cannot be found.
  235. */
  236. int GetUnitCount() const;
  237. /**
  238. * Compute the new transform matrix based on \a aOrientation for the symbol which is
  239. * applied to the current transform.
  240. *
  241. * @param aOrientation is the orientation to apply to the transform.
  242. */
  243. void SetOrientation( int aOrientation );
  244. /**
  245. * Get the display symbol orientation.
  246. *
  247. * Because there are different ways to have a given orientation/mirror,
  248. * the orientation/mirror is not necessary what the user does. For example:
  249. * a mirrorX then a mirrorY returns no mirror but a rotate. This function finds
  250. * a rotation and a mirror value #CMP_MIRROR_X because this is the first mirror
  251. * option tested. This can differs from the orientation made by an user. A
  252. * #CMP_MIRROR_Y is returned as a #CMP_MIRROR_X with an orientation 180 because
  253. * they are equivalent.
  254. *
  255. * @sa COMPONENT_ORIENTATION_T
  256. *
  257. * @return the orientation and mirror of the symbol.
  258. */
  259. int GetOrientation();
  260. /**
  261. * Return the list of system text vars & fields for this symbol.
  262. */
  263. void GetContextualTextVars( wxArrayString* aVars ) const;
  264. /**
  265. * Resolve any references to system tokens supported by the component.
  266. * @param aDepth a counter to limit recursion and circular references.
  267. */
  268. bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
  269. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  270. /**
  271. * Clear exiting component annotation.
  272. *
  273. * For example, IC23 would be changed to IC? and unit number would be reset.
  274. *
  275. * @param aSheetPath is the hierarchical path of the symbol to clear or remove all
  276. * annotations for this symbol if NULL.
  277. */
  278. void ClearAnnotation( const SCH_SHEET_PATH* aSheetPath );
  279. /**
  280. * Add an instance to the alternate references list (m_instanceReferences), if this entry
  281. * does not already exist.
  282. * Do nothing if already exists.
  283. * In component lists shared by more than one sheet path, an entry for each
  284. * sheet path must exist to manage references
  285. * @param aSheetPath is the candidate sheet path
  286. * this sheet path is the sheet path of the sheet containing the component,
  287. * not the full component sheet path
  288. * @return false if the alternate reference was existing, true if added.
  289. */
  290. bool AddSheetPathReferenceEntryIfMissing( const KIID_PATH& aSheetPath );
  291. /**
  292. * Replace \a aOldSheetPath with \a aNewSheetPath in the instance list.
  293. *
  294. * @param aOldSheetPath is a #KIID_PATH object of an existing path in the instance list.
  295. * @param aNewSheetPath is a #KIID_PATH object of the path to replace the existing path.
  296. *
  297. * @return true if \a aOldSheetPath was found and replaced or false if \a aOldSheetPath was
  298. * not found in the instance list.
  299. */
  300. bool ReplaceInstanceSheetPath( const KIID_PATH& aOldSheetPath, const KIID_PATH& aNewSheetPath );
  301. const EDA_RECT GetBoundingBox() const override;
  302. const EDA_RECT GetBoundingBox( bool aIncludeInvisibleText ) const;
  303. /**
  304. * Return a bounding box for the symbol body but not the fields.
  305. */
  306. EDA_RECT GetBodyBoundingBox() const;
  307. //-----<Fields>-----------------------------------------------------------
  308. /**
  309. * Returns a field in this symbol.
  310. *
  311. * @param aFieldNdx is the index into the array of fields, not a field id.
  312. *
  313. * @return is the field at \a aFieldNdx or NULL if the field does not exist.
  314. */
  315. SCH_FIELD* GetField( int aFieldNdx );
  316. const SCH_FIELD* GetField( int aFieldNdx ) const;
  317. /**
  318. * Search for a field named \a aFieldName and returns text associated with this field.
  319. *
  320. * @param aFieldName is the name of the field
  321. */
  322. wxString GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame ) const;
  323. /**
  324. * Populates a std::vector with SCH_FIELDs.
  325. *
  326. * @param aVector is the vector to populate.
  327. * @param aVisibleOnly is used to add only the fields that are visible and contain text.
  328. */
  329. void GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly );
  330. /**
  331. * Returns a vector of fields from the component
  332. */
  333. std::vector<SCH_FIELD>& GetFields() { return m_Fields; }
  334. /**
  335. * Add a field to the symbol.
  336. *
  337. * @param aField is the field to add to this symbol.
  338. *
  339. * @return the newly inserted field.
  340. */
  341. SCH_FIELD* AddField( const SCH_FIELD& aField );
  342. /**
  343. * Removes a user field from the symbol.
  344. * @param aFieldName is the user fieldName to remove. Attempts to remove a mandatory
  345. * field or a non-existant field are silently ignored.
  346. */
  347. void RemoveField( const wxString& aFieldName );
  348. /**
  349. * Search for a #SCH_FIELD with \a aFieldName
  350. *
  351. * @param aFieldName is the name of the field to find.
  352. * @param aIncludeDefaultFields searches the library symbol default fields if true.
  353. *
  354. * @return the field if found or NULL if the field was not found.
  355. */
  356. SCH_FIELD* FindField( const wxString& aFieldName, bool aIncludeDefaultFields = true );
  357. /**
  358. * Set multiple schematic fields.
  359. *
  360. * @param aFields are the fields to set in this symbol.
  361. */
  362. void SetFields( const SCH_FIELDS& aFields )
  363. {
  364. m_Fields = aFields; // vector copying, length is changed possibly
  365. }
  366. /**
  367. * Restores fields to the original library values.
  368. * @param aResetStyle selects whether fields should reset the position and text attribute.
  369. * @param aResetRef selects whether the reference field should be restored.
  370. */
  371. void UpdateFields( bool aResetStyle, bool aResetRef = false );
  372. /**
  373. * Return the number of fields in this symbol.
  374. */
  375. int GetFieldCount() const { return (int)m_Fields.size(); }
  376. /**
  377. * Automatically orient all the fields in the component.
  378. *
  379. * @param aScreen is the SCH_SCREEN associated with the current instance of the
  380. * component. This can be NULL when aManual is false.
  381. * @param aManual should be true if the autoplace was manually initiated (e.g. by a hotkey
  382. * or a menu item). Some more 'intelligent' routines will be used that would be
  383. * annoying if done automatically during moves.
  384. */
  385. void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
  386. //-----</Fields>----------------------------------------------------------
  387. /**
  388. * Find a symbol pin by number.
  389. *
  390. * @param number is the number of the pin to find.
  391. *
  392. * @return Pin object if found, otherwise NULL.
  393. */
  394. SCH_PIN* GetPin( const wxString& number );
  395. /**
  396. * Populate a vector with all the pins from the library object.
  397. *
  398. * @param aPinsList is the list to populate with all of the pins.
  399. */
  400. void GetLibPins( std::vector<LIB_PIN*>& aPinsList );
  401. SCH_PIN* GetPin( LIB_PIN* aLibPin );
  402. /**
  403. * Retrieves a list of the SCH_PINs for the given sheet path.
  404. * Since a component can have a different unit on a different instance of a sheet,
  405. * this list returns the subset of pins that exist on a given sheet.
  406. * @return a vector of pointers (non-owning) to SCH_PINs
  407. */
  408. std::vector<SCH_PIN*> GetPins( const SCH_SHEET_PATH* aSheet = nullptr ) const;
  409. std::vector<std::unique_ptr<SCH_PIN>>& GetRawPins() { return m_pins; }
  410. /**
  411. * Print a component
  412. *
  413. * @param aDC is the device context (can be null)
  414. * @param aOffset is the drawing offset (usually wxPoint(0,0),
  415. * but can be different when moving an object)
  416. */
  417. void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
  418. void SwapData( SCH_ITEM* aItem ) override;
  419. /**
  420. * Tests for an acceptable reference string.
  421. *
  422. * An acceptable reference string must support unannotation i.e starts by letter
  423. *
  424. * @param aReferenceString is the reference string to validate
  425. *
  426. * @return true if reference string is valid.
  427. */
  428. static bool IsReferenceStringValid( const wxString& aReferenceString );
  429. /**
  430. * Return the reference for the given sheet path.
  431. *
  432. * @return the reference for the sheet.
  433. */
  434. const wxString GetRef( const SCH_SHEET_PATH* aSheet, bool aIncludeUnit = false ) const;
  435. /**
  436. * Set the reference for the given sheet path for this symbol.
  437. *
  438. * @param aSheet is the hierarchical path of the reference.
  439. * @param aReference is the new reference for the symbol.
  440. */
  441. void SetRef( const SCH_SHEET_PATH* aSheet, const wxString& aReference );
  442. /**
  443. * Checks if the component has a valid annotation (reference) for the given sheet path
  444. * @param aSheet is the sheet path to test
  445. * @return true if the component exists on that sheet and has a valid reference
  446. */
  447. bool IsAnnotated( const SCH_SHEET_PATH* aSheet );
  448. /**
  449. * Add a full hierarchical reference to this symbol.
  450. *
  451. * @param aPath is the hierarchical path (/&ltsheet timestamp&gt/&ltcomponent
  452. * timestamp&gt like /05678E50/A23EF560)
  453. * @param aRef is the local reference like C45, R56
  454. * @param aUnit is the unit selection used for symbols with multiple units per package.
  455. * @param aValue is the value used for this instance
  456. * @param aFootprint is the footprint used for this instance (which might have different
  457. * hole spacing or other board-specific changes from other intances)
  458. */
  459. void AddHierarchicalReference( const KIID_PATH& aPath,
  460. const wxString& aRef,
  461. int aUnit,
  462. const wxString& aValue = wxEmptyString,
  463. const wxString& aFootprint = wxEmptyString );
  464. // Returns the instance-specific unit selection for the given sheet path.
  465. int GetUnitSelection( const SCH_SHEET_PATH* aSheet ) const;
  466. void SetUnitSelection( const SCH_SHEET_PATH* aSheet, int aUnitSelection );
  467. // Returns the instance-specific value for the given sheet path.
  468. const wxString GetValue( const SCH_SHEET_PATH* sheet ) const;
  469. void SetValue( const SCH_SHEET_PATH* sheet, const wxString& aValue );
  470. // Set the value for all instances (the default GUI behaviour)
  471. void SetValue( const wxString& aValue )
  472. {
  473. SetValue( nullptr, aValue );
  474. }
  475. // Returns the instance-specific footprint assignment for the given sheet path.
  476. const wxString GetFootprint( const SCH_SHEET_PATH* sheet ) const;
  477. void SetFootprint( const SCH_SHEET_PATH* sheet, const wxString& aFootprint );
  478. // Set the value for all instances (the default GUI behaviour)
  479. void SetFootprint( const wxString& aFootprint )
  480. {
  481. SetFootprint( nullptr, aFootprint );
  482. }
  483. // Geometric transforms (used in block operations):
  484. void Move( const wxPoint& aMoveVector ) override
  485. {
  486. if( aMoveVector == wxPoint( 0, 0 ) )
  487. return;
  488. m_Pos += aMoveVector;
  489. for( SCH_FIELD& field : m_Fields )
  490. field.Move( aMoveVector );
  491. SetModified();
  492. }
  493. void MirrorY( int aYaxis_position ) override;
  494. void MirrorX( int aXaxis_position ) override;
  495. void Rotate( wxPoint aPosition ) override;
  496. bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override;
  497. void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
  498. /**
  499. * Test if the component's dangling state has changed for all pins.
  500. *
  501. * As a side effect, actually update the dangling status for all pins.
  502. *
  503. * @note This does not test for short circuits.
  504. *
  505. * @param aItemList is list of all #DANGLING_END_ITEM items to be tested.
  506. *
  507. * @return true if any pin's state has changed.
  508. */
  509. bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
  510. const SCH_SHEET_PATH* aPath = nullptr ) override;
  511. wxPoint GetPinPhysicalPosition( const LIB_PIN* Pin ) const;
  512. bool IsConnectable() const override { return true; }
  513. bool CanConnect( const SCH_ITEM* aItem ) const override
  514. {
  515. return ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_WIRE ) ||
  516. ( aItem->Type() == SCH_NO_CONNECT_T ) ||
  517. ( aItem->Type() == SCH_JUNCTION_T ) ||
  518. ( aItem->Type() == SCH_COMPONENT_T ) ;
  519. }
  520. /**
  521. * @return true if the component is in netlist
  522. * which means this is not a power component, or something
  523. * like a component reference starting by #
  524. */
  525. bool IsInNetlist() const;
  526. std::vector<wxPoint> GetConnectionPoints() const override;
  527. SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
  528. /**
  529. * Return the component library item at \a aPosition that is part of this component.
  530. *
  531. * @param aPosition is the schematic position of the component library object.
  532. * @param aType is the type of symbol library object to find or any if set to TYPE_NOT_INIT.
  533. *
  534. * @return is the symbol library object if found otherwise NULL.
  535. */
  536. LIB_ITEM* GetDrawItem( const wxPoint& aPosition, KICAD_T aType = TYPE_NOT_INIT );
  537. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  538. BITMAP_DEF GetMenuImage() const override;
  539. bool operator <( const SCH_ITEM& aItem ) const override;
  540. bool operator==( const SCH_COMPONENT& aComponent) const;
  541. bool operator!=( const SCH_COMPONENT& aComponent) const;
  542. SCH_COMPONENT& operator=( const SCH_ITEM& aItem );
  543. bool IsReplaceable() const override { return true; }
  544. wxPoint GetPosition() const override { return m_Pos; }
  545. void SetPosition( const wxPoint& aPosition ) override { Move( aPosition - m_Pos ); }
  546. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  547. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  548. void Plot( PLOTTER* aPlotter ) override;
  549. EDA_ITEM* Clone() const override;
  550. #if defined(DEBUG)
  551. void Show( int nestLevel, std::ostream& os ) const override;
  552. #endif
  553. void ClearBrightenedPins();
  554. bool HasBrightenedPins();
  555. bool GetIncludeInBom() const { return m_inBom; }
  556. void SetIncludeInBom( bool aIncludeInBom ) { m_inBom = aIncludeInBom; }
  557. bool GetIncludeOnBoard() const { return m_onBoard; }
  558. void SetIncludeOnBoard( bool aIncludeOnBoard ) { m_onBoard = aIncludeOnBoard; }
  559. private:
  560. bool doIsConnected( const wxPoint& aPosition ) const override;
  561. };
  562. #endif /* COMPONENT_CLASS_H */