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.

3010 lines
89 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
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
2 years ago
2 years ago
18 years ago
18 years ago
18 years ago
18 years ago
6 years ago
6 years ago
2 years ago
2 years ago
2 years ago
6 months ago
18 years ago
18 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
18 years ago
18 years ago
2 years ago
2 years ago
1 year 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 The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <sch_collectors.h>
  25. #include <sch_commit.h>
  26. #include <sch_edit_frame.h>
  27. #include <widgets/msgpanel.h>
  28. #include <bitmaps.h>
  29. #include <core/mirror.h>
  30. #include <sch_shape.h>
  31. #include <pgm_base.h>
  32. #include <sim/sim_model.h>
  33. #include <sim/spice_generator.h>
  34. #include <sim/sim_lib_mgr.h>
  35. #include <trace_helpers.h>
  36. #include <trigo.h>
  37. #include <refdes_utils.h>
  38. #include <wx/log.h>
  39. #include <settings/settings_manager.h>
  40. #include <sch_plotter.h>
  41. #include <string_utils.h>
  42. #include <sch_rule_area.h>
  43. #include <utility>
  44. #include <validators.h>
  45. std::unordered_map<TRANSFORM, int> SCH_SYMBOL::s_transformToOrientationCache;
  46. /**
  47. * Convert a wxString to UTF8 and replace any control characters with a ~, where a control
  48. * character is one of the first ASCII values up to ' ' 32d.
  49. */
  50. std::string toUTFTildaText( const wxString& txt )
  51. {
  52. std::string ret = TO_UTF8( txt );
  53. for( char& c : ret )
  54. {
  55. if( (unsigned char) c <= ' ' )
  56. c = '~';
  57. }
  58. return ret;
  59. }
  60. SCH_SYMBOL::SCH_SYMBOL() :
  61. SYMBOL( nullptr, SCH_SYMBOL_T )
  62. {
  63. Init( VECTOR2I( 0, 0 ) );
  64. }
  65. SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId,
  66. const SCH_SHEET_PATH* aSheet, int aUnit, int aBodyStyle,
  67. const VECTOR2I& aPosition, EDA_ITEM* aParent ) :
  68. SYMBOL( aParent, SCH_SYMBOL_T )
  69. {
  70. Init( aPosition );
  71. m_unit = aUnit;
  72. m_bodyStyle = aBodyStyle;
  73. m_lib_id = aLibId;
  74. std::unique_ptr< LIB_SYMBOL > part;
  75. part = aSymbol.Flatten();
  76. part->SetParent();
  77. SetLibSymbol( part.release() );
  78. // Copy fields from the library symbol
  79. UpdateFields( aSheet,
  80. true, /* update style */
  81. false, /* update ref */
  82. false, /* update other fields */
  83. true, /* reset ref */
  84. true /* reset other fields */ );
  85. m_prefix = UTIL::GetRefDesPrefix( m_part->GetReferenceField().GetText() );
  86. if( aSheet )
  87. SetRef( aSheet, UTIL::GetRefDesUnannotated( m_prefix ) );
  88. // Inherit the include in bill of materials and board netlist settings from flattened
  89. // library symbol.
  90. m_excludedFromSim = m_part->GetExcludedFromSim();
  91. m_excludedFromBOM = m_part->GetExcludedFromBOM();
  92. m_excludedFromBoard = m_part->GetExcludedFromBoard();
  93. }
  94. SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const SCH_SHEET_PATH* aSheet,
  95. const PICKED_SYMBOL& aSel, const VECTOR2I& aPosition, EDA_ITEM* aParent ) :
  96. SCH_SYMBOL( aSymbol, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, aPosition, aParent )
  97. {
  98. // Set any fields that were modified as part of the symbol selection
  99. for( const auto& [fieldId, fieldValue] : aSel.Fields )
  100. {
  101. if( fieldId == FIELD_T::REFERENCE )
  102. SetRef( aSheet, fieldValue );
  103. else if( SCH_FIELD* field = GetField( fieldId ) )
  104. field->SetText( fieldValue );
  105. }
  106. }
  107. SCH_SYMBOL::SCH_SYMBOL( const SCH_SYMBOL& aSymbol ) :
  108. SYMBOL( aSymbol )
  109. {
  110. m_parent = aSymbol.m_parent;
  111. m_pos = aSymbol.m_pos;
  112. m_unit = aSymbol.m_unit;
  113. m_bodyStyle = aSymbol.m_bodyStyle;
  114. m_lib_id = aSymbol.m_lib_id;
  115. m_isInNetlist = aSymbol.m_isInNetlist;
  116. m_DNP = aSymbol.m_DNP;
  117. const_cast<KIID&>( m_Uuid ) = aSymbol.m_Uuid;
  118. m_transform = aSymbol.m_transform;
  119. m_prefix = aSymbol.m_prefix;
  120. m_instanceReferences = aSymbol.m_instanceReferences;
  121. m_fields = aSymbol.m_fields;
  122. // Re-parent the fields, which before this had aSymbol as parent
  123. for( SCH_FIELD& field : m_fields )
  124. field.SetParent( this );
  125. m_pins.clear();
  126. // Copy (and re-parent) the pins
  127. for( const std::unique_ptr<SCH_PIN>& pin : aSymbol.m_pins )
  128. {
  129. m_pins.emplace_back( std::make_unique<SCH_PIN>( *pin ) );
  130. m_pins.back()->SetParent( this );
  131. }
  132. if( aSymbol.m_part )
  133. SetLibSymbol( new LIB_SYMBOL( *aSymbol.m_part ) );
  134. m_fieldsAutoplaced = aSymbol.m_fieldsAutoplaced;
  135. m_schLibSymbolName = aSymbol.m_schLibSymbolName;
  136. }
  137. SCH_SYMBOL::~SCH_SYMBOL()
  138. {
  139. }
  140. void SCH_SYMBOL::Init( const VECTOR2I& pos )
  141. {
  142. m_layer = LAYER_DEVICE;
  143. m_pos = pos;
  144. m_unit = 1; // In multi unit chip - which unit to draw.
  145. m_bodyStyle = BODY_STYLE::BASE; // De Morgan Handling
  146. // The rotation/mirror transformation matrix. pos normal
  147. m_transform = TRANSFORM();
  148. auto addField =
  149. [&]( FIELD_T id, SCH_LAYER_ID layer )
  150. {
  151. m_fields.emplace_back( this, id, GetCanonicalFieldName( id ) );
  152. m_fields.back().SetTextPos( pos );
  153. m_fields.back().SetLayer( layer );
  154. };
  155. // construct only the mandatory fields
  156. addField( FIELD_T::REFERENCE, LAYER_REFERENCEPART );
  157. addField( FIELD_T::VALUE, LAYER_VALUEPART );
  158. addField( FIELD_T::FOOTPRINT, LAYER_FIELDS );
  159. addField( FIELD_T::DATASHEET, LAYER_FIELDS );
  160. addField( FIELD_T::DESCRIPTION, LAYER_FIELDS );
  161. m_prefix = wxString( wxT( "U" ) );
  162. m_isInNetlist = true;
  163. }
  164. EDA_ITEM* SCH_SYMBOL::Clone() const
  165. {
  166. return new SCH_SYMBOL( *this );
  167. }
  168. bool SCH_SYMBOL::IsMissingLibSymbol() const
  169. {
  170. return m_part == nullptr;
  171. }
  172. bool SCH_SYMBOL::IsMovableFromAnchorPoint() const
  173. {
  174. // If a symbol's anchor is not grid-aligned to its pins then moving from the anchor is
  175. // going to end up moving the symbol's pins off-grid.
  176. // The minimal grid size allowed to place a pin is 25 mils
  177. const int min_grid_size = schIUScale.MilsToIU( 25 );
  178. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  179. {
  180. if( ( ( pin->GetPosition().x - m_pos.x ) % min_grid_size ) != 0 )
  181. return false;
  182. if( ( ( pin->GetPosition().y - m_pos.y ) % min_grid_size ) != 0 )
  183. return false;
  184. }
  185. return true;
  186. }
  187. void SCH_SYMBOL::SetLibId( const LIB_ID& aLibId )
  188. {
  189. m_lib_id = aLibId;
  190. }
  191. wxString SCH_SYMBOL::GetSchSymbolLibraryName() const
  192. {
  193. if( !m_schLibSymbolName.IsEmpty() )
  194. return m_schLibSymbolName;
  195. else
  196. return m_lib_id.Format();
  197. }
  198. void SCH_SYMBOL::SetLibSymbol( LIB_SYMBOL* aLibSymbol )
  199. {
  200. wxCHECK2( !aLibSymbol || aLibSymbol->IsRoot(), aLibSymbol = nullptr );
  201. m_part.reset( aLibSymbol );
  202. UpdatePins();
  203. }
  204. wxString SCH_SYMBOL::GetDescription() const
  205. {
  206. if( m_part )
  207. return m_part->GetDescription();
  208. return wxEmptyString;
  209. }
  210. wxString SCH_SYMBOL::GetKeyWords() const
  211. {
  212. if( m_part )
  213. return m_part->GetKeyWords();
  214. return wxEmptyString;
  215. }
  216. wxString SCH_SYMBOL::GetDatasheet() const
  217. {
  218. if( m_part )
  219. return m_part->GetDatasheetField().GetText();
  220. return wxEmptyString;
  221. }
  222. void SCH_SYMBOL::UpdatePins()
  223. {
  224. std::map<wxString, wxString> altPinMap;
  225. std::map<wxString, std::set<SCH_PIN*>> pinUuidMap;
  226. std::set<SCH_PIN*> unassignedSchPins;
  227. std::set<SCH_PIN*> unassignedLibPins;
  228. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  229. {
  230. pinUuidMap[ pin->GetNumber() ].insert( pin.get() );
  231. unassignedSchPins.insert( pin.get() );
  232. if( !pin->GetAlt().IsEmpty() )
  233. altPinMap[ pin->GetNumber() ] = pin->GetAlt();
  234. pin->SetLibPin( nullptr );
  235. }
  236. m_pinMap.clear();
  237. if( !m_part )
  238. return;
  239. for( SCH_PIN* libPin : m_part->GetPins() )
  240. {
  241. // NW: Don't filter by unit: this data-structure is used for all instances,
  242. // some of which might have different units.
  243. if( libPin->GetBodyStyle() && m_bodyStyle && m_bodyStyle != libPin->GetBodyStyle() )
  244. continue;
  245. SCH_PIN* pin = nullptr;
  246. auto ii = pinUuidMap.find( libPin->GetNumber() );
  247. if( ii == pinUuidMap.end() || ii->second.empty() )
  248. {
  249. unassignedLibPins.insert( libPin );
  250. continue;
  251. }
  252. auto it = ii->second.begin();
  253. pin = *it;
  254. ii->second.erase( it );
  255. pin->SetLibPin( libPin );
  256. pin->SetPosition( libPin->GetPosition() );
  257. unassignedSchPins.erase( pin );
  258. auto iii = altPinMap.find( libPin->GetNumber() );
  259. if( iii != altPinMap.end() )
  260. pin->SetAlt( iii->second );
  261. m_pinMap[ libPin ] = pin;
  262. }
  263. // Add any pins that were not found in the symbol
  264. for( SCH_PIN* libPin : unassignedLibPins )
  265. {
  266. SCH_PIN* pin = nullptr;
  267. // First try to re-use an existing pin
  268. if( !unassignedSchPins.empty() )
  269. {
  270. auto it = unassignedSchPins.begin();
  271. pin = *it;
  272. unassignedSchPins.erase( it );
  273. }
  274. else
  275. {
  276. // This is a pin that was not found in the symbol, so create a new one.
  277. pin = m_pins.emplace_back( std::make_unique<SCH_PIN>( SCH_PIN( this, libPin ) ) ).get();
  278. }
  279. m_pinMap[ libPin ] = pin;
  280. pin->SetLibPin( libPin );
  281. pin->SetPosition( libPin->GetPosition() );
  282. pin->SetNumber( libPin->GetNumber() );
  283. auto iii = altPinMap.find( libPin->GetNumber() );
  284. if( iii != altPinMap.end() )
  285. pin->SetAlt( iii->second );
  286. }
  287. // If we have any pins left in the symbol that were not found in the library, remove them.
  288. for( auto it1 = m_pins.begin(); it1 != m_pins.end() && !unassignedSchPins.empty(); )
  289. {
  290. auto it2 = unassignedSchPins.find( it1->get() );
  291. if( it2 != unassignedSchPins.end() )
  292. {
  293. it1 = m_pins.erase( it1 );
  294. unassignedSchPins.erase( it2 );
  295. }
  296. else
  297. {
  298. ++it1;
  299. }
  300. }
  301. // If the symbol is selected, then its pins are selected.
  302. if( IsSelected() )
  303. {
  304. for( std::unique_ptr<SCH_PIN>& pin : m_pins )
  305. pin->SetSelected();
  306. }
  307. }
  308. void SCH_SYMBOL::SetBodyStyleUnconditional( int aBodyStyle )
  309. {
  310. if( m_bodyStyle != aBodyStyle )
  311. {
  312. m_bodyStyle = ( m_bodyStyle == BODY_STYLE::BASE ) ? BODY_STYLE::DEMORGAN
  313. : BODY_STYLE::BASE;
  314. // The body style may have a different pin layout so the update the pin map.
  315. UpdatePins();
  316. }
  317. }
  318. void SCH_SYMBOL::SetBodyStyle( int aBodyStyle )
  319. {
  320. if( HasAlternateBodyStyle() && m_bodyStyle != aBodyStyle )
  321. {
  322. m_bodyStyle = ( m_bodyStyle == BODY_STYLE::BASE ) ? BODY_STYLE::DEMORGAN
  323. : BODY_STYLE::BASE;
  324. // The body style may have a different pin layout so the update the pin map.
  325. UpdatePins();
  326. }
  327. }
  328. bool SCH_SYMBOL::HasAlternateBodyStyle() const
  329. {
  330. if( m_part )
  331. return m_part->HasAlternateBodyStyle();
  332. return false;
  333. }
  334. int SCH_SYMBOL::GetUnitCount() const
  335. {
  336. if( m_part )
  337. return m_part->GetUnitCount();
  338. return 0;
  339. }
  340. wxString SCH_SYMBOL::GetUnitDisplayName( int aUnit ) const
  341. {
  342. wxCHECK( m_part, ( wxString::Format( _( "Unit %s" ), SubReference( aUnit ) ) ) );
  343. return m_part->GetUnitDisplayName( aUnit );
  344. }
  345. bool SCH_SYMBOL::HasUnitDisplayName( int aUnit ) const
  346. {
  347. wxCHECK( m_part, false );
  348. return m_part->HasUnitDisplayName( aUnit );
  349. }
  350. bool SCH_SYMBOL::GetInstance( SCH_SYMBOL_INSTANCE& aInstance,
  351. const KIID_PATH& aSheetPath, bool aTestFromEnd ) const
  352. {
  353. for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  354. {
  355. if( !aTestFromEnd )
  356. {
  357. if( instance.m_Path == aSheetPath )
  358. {
  359. aInstance = instance;
  360. return true;
  361. }
  362. }
  363. else if( instance.m_Path.EndsWith( aSheetPath ) )
  364. {
  365. aInstance = instance;
  366. return true;
  367. }
  368. }
  369. return false;
  370. }
  371. void SCH_SYMBOL::RemoveInstance( const SCH_SHEET_PATH& aInstancePath )
  372. {
  373. RemoveInstance( aInstancePath.Path() );
  374. }
  375. void SCH_SYMBOL::RemoveInstance( const KIID_PATH& aInstancePath )
  376. {
  377. // Search for an existing path and remove it if found (should not occur)
  378. for( unsigned ii = 0; ii < m_instanceReferences.size(); ii++ )
  379. {
  380. if( m_instanceReferences[ii].m_Path == aInstancePath )
  381. {
  382. wxLogTrace( traceSchSheetPaths, wxS( "Removing symbol instance:\n"
  383. " sheet path %s\n"
  384. " reference %s, unit %d from symbol %s." ),
  385. aInstancePath.AsString(),
  386. m_instanceReferences[ii].m_Reference,
  387. m_instanceReferences[ii].m_Unit,
  388. m_Uuid.AsString() );
  389. m_instanceReferences.erase( m_instanceReferences.begin() + ii );
  390. ii--;
  391. }
  392. }
  393. }
  394. void SCH_SYMBOL::AddHierarchicalReference( const KIID_PATH& aPath, const wxString& aRef, int aUnit )
  395. {
  396. // Search for an existing path and remove it if found (should not occur)
  397. for( unsigned ii = 0; ii < m_instanceReferences.size(); ii++ )
  398. {
  399. if( m_instanceReferences[ii].m_Path == aPath )
  400. {
  401. wxLogTrace( traceSchSheetPaths, wxS( "Removing symbol instance:\n"
  402. " sheet path %s\n"
  403. " reference %s, unit %d from symbol %s." ),
  404. aPath.AsString(),
  405. m_instanceReferences[ii].m_Reference,
  406. m_instanceReferences[ii].m_Unit,
  407. m_Uuid.AsString() );
  408. m_instanceReferences.erase( m_instanceReferences.begin() + ii );
  409. ii--;
  410. }
  411. }
  412. SCH_SYMBOL_INSTANCE instance;
  413. instance.m_Path = aPath;
  414. instance.m_Reference = aRef;
  415. instance.m_Unit = aUnit;
  416. wxLogTrace( traceSchSheetPaths, wxS( "Adding symbol '%s' instance:\n"
  417. " sheet path '%s'\n"
  418. " reference '%s'\n"
  419. " unit %d\n" ),
  420. m_Uuid.AsString(),
  421. aPath.AsString(),
  422. aRef,
  423. aUnit );
  424. m_instanceReferences.push_back( instance );
  425. // This should set the default instance to the first saved instance data for each symbol
  426. // when importing sheets.
  427. if( m_instanceReferences.size() == 1 )
  428. {
  429. GetField( FIELD_T::REFERENCE )->SetText( aRef );
  430. m_unit = aUnit;
  431. }
  432. }
  433. void SCH_SYMBOL::AddHierarchicalReference( const SCH_SYMBOL_INSTANCE& aInstance )
  434. {
  435. KIID_PATH searchPath( aInstance.m_Path );
  436. std::vector<SCH_SYMBOL_INSTANCE>::iterator resultIt;
  437. do
  438. {
  439. resultIt = std::find_if( m_instanceReferences.begin(), m_instanceReferences.end(),
  440. [searchPath]( const auto& it )
  441. {
  442. return it.m_Path == searchPath;
  443. } );
  444. if( resultIt != m_instanceReferences.end() )
  445. {
  446. wxLogTrace( traceSchSheetPaths, wxS( "Removing symbol instance:\n"
  447. " sheet path %s\n"
  448. " reference %s, unit %d from symbol %s." ),
  449. aInstance.m_Path.AsString(),
  450. resultIt->m_Reference,
  451. resultIt->m_Unit,
  452. m_Uuid.AsString() );
  453. // Instance data should be unique by path. Double check just in case there was
  454. // some buggy code in the past.
  455. resultIt = m_instanceReferences.erase( resultIt );
  456. }
  457. }
  458. while( resultIt != m_instanceReferences.end() );
  459. SCH_SYMBOL_INSTANCE instance = aInstance;
  460. wxLogTrace( traceSchSheetPaths, wxS( "Adding symbol '%s' instance:\n"
  461. " sheet path '%s'\n"
  462. " reference '%s'\n"
  463. " unit %d\n" ),
  464. m_Uuid.AsString(),
  465. instance.m_Path.AsString(),
  466. instance.m_Reference,
  467. instance.m_Unit );
  468. m_instanceReferences.push_back( instance );
  469. // This should set the default instance to the first saved instance data for each symbol
  470. // when importing sheets.
  471. if( m_instanceReferences.size() == 1 )
  472. {
  473. GetField( FIELD_T::REFERENCE )->SetText( instance.m_Reference );
  474. m_unit = instance.m_Unit;
  475. }
  476. }
  477. const wxString SCH_SYMBOL::GetRef( const SCH_SHEET_PATH* sheet, bool aIncludeUnit ) const
  478. {
  479. KIID_PATH path = sheet->Path();
  480. wxString ref;
  481. wxString subRef;
  482. for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  483. {
  484. if( instance.m_Path == path )
  485. {
  486. ref = instance.m_Reference;
  487. subRef = SubReference( instance.m_Unit );
  488. break;
  489. }
  490. }
  491. // If it was not found in m_Paths array, then see if it is in m_Field[REFERENCE] -- if so,
  492. // use this as a default for this path. This will happen if we load a version 1 schematic
  493. // file. It will also mean that multiple instances of the same sheet by default all have
  494. // the same symbol references, but perhaps this is best.
  495. if( ref.IsEmpty() && !GetField( FIELD_T::REFERENCE )->GetText().IsEmpty() )
  496. ref = GetField( FIELD_T::REFERENCE )->GetText();
  497. if( ref.IsEmpty() )
  498. ref = UTIL::GetRefDesUnannotated( m_prefix );
  499. if( aIncludeUnit && GetUnitCount() > 1 )
  500. ref += subRef;
  501. return ref;
  502. }
  503. void SCH_SYMBOL::SetRefProp( const wxString& aRef )
  504. {
  505. FIELD_VALIDATOR validator( FIELD_T::REFERENCE );
  506. if( validator.DoValidate( aRef, nullptr ) )
  507. SetRef( &Schematic()->CurrentSheet(), aRef );
  508. }
  509. void SCH_SYMBOL::SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref )
  510. {
  511. KIID_PATH path = sheet->Path();
  512. bool found = false;
  513. // check to see if it is already there before inserting it
  514. for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  515. {
  516. if( instance.m_Path == path )
  517. {
  518. found = true;
  519. instance.m_Reference = ref;
  520. break;
  521. }
  522. }
  523. if( !found )
  524. AddHierarchicalReference( path, ref, m_unit );
  525. for( std::unique_ptr<SCH_PIN>& pin : m_pins )
  526. pin->ClearDefaultNetName( sheet );
  527. if( Schematic() && *sheet == Schematic()->CurrentSheet() )
  528. GetField( FIELD_T::REFERENCE )->SetText( ref );
  529. // Reinit the m_prefix member if needed
  530. m_prefix = UTIL::GetRefDesPrefix( ref );
  531. if( m_prefix.IsEmpty() )
  532. m_prefix = wxT( "U" );
  533. // Power symbols have references starting with # and are not included in netlists
  534. m_isInNetlist = ! ref.StartsWith( wxT( "#" ) );
  535. }
  536. bool SCH_SYMBOL::IsAnnotated( const SCH_SHEET_PATH* aSheet ) const
  537. {
  538. KIID_PATH path = aSheet->Path();
  539. for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  540. {
  541. if( instance.m_Path == path )
  542. return instance.m_Reference.Last() != '?';
  543. }
  544. return false;
  545. }
  546. void SCH_SYMBOL::UpdatePrefix()
  547. {
  548. wxString refDesignator = GetField( FIELD_T::REFERENCE )->GetText();
  549. refDesignator.Replace( "~", " " );
  550. wxString prefix = refDesignator;
  551. while( prefix.Length() )
  552. {
  553. wxUniCharRef last = prefix.Last();
  554. if( ( last >= '0' && last <= '9' ) || last == '?' || last == '*' )
  555. prefix.RemoveLast();
  556. else
  557. break;
  558. }
  559. // Avoid a prefix containing trailing/leading spaces
  560. prefix.Trim( true );
  561. prefix.Trim( false );
  562. if( !prefix.IsEmpty() )
  563. SetPrefix( prefix );
  564. }
  565. wxString SCH_SYMBOL::SubReference( int aUnit, bool aAddSeparator ) const
  566. {
  567. if( SCHEMATIC* schematic = Schematic() )
  568. return schematic->Settings().SubReference( aUnit, aAddSeparator );
  569. return LIB_SYMBOL::LetterSubReference( aUnit, 'A' );
  570. }
  571. int SCH_SYMBOL::GetUnitSelection( const SCH_SHEET_PATH* aSheet ) const
  572. {
  573. KIID_PATH path = aSheet->Path();
  574. for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  575. {
  576. if( instance.m_Path == path )
  577. return instance.m_Unit;
  578. }
  579. // If it was not found in m_Paths array, then use m_unit. This will happen if we load a
  580. // version 1 schematic file.
  581. return m_unit;
  582. }
  583. void SCH_SYMBOL::SetUnitSelection( const SCH_SHEET_PATH* aSheet, int aUnitSelection )
  584. {
  585. KIID_PATH path = aSheet->Path();
  586. // check to see if it is already there before inserting it
  587. for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  588. {
  589. if( instance.m_Path == path )
  590. {
  591. instance.m_Unit = aUnitSelection;
  592. return;
  593. }
  594. }
  595. // didn't find it; better add it
  596. AddHierarchicalReference( path, UTIL::GetRefDesUnannotated( m_prefix ), aUnitSelection );
  597. }
  598. void SCH_SYMBOL::SetUnitSelection( int aUnitSelection )
  599. {
  600. for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  601. instance.m_Unit = aUnitSelection;
  602. }
  603. const wxString SCH_SYMBOL::GetValue( bool aResolve, const SCH_SHEET_PATH* aPath,
  604. bool aAllowExtraText ) const
  605. {
  606. if( aResolve )
  607. return GetField( FIELD_T::VALUE )->GetShownText( aPath, aAllowExtraText );
  608. return GetField( FIELD_T::VALUE )->GetText();
  609. }
  610. void SCH_SYMBOL::SetValueFieldText( const wxString& aValue )
  611. {
  612. GetField( FIELD_T::VALUE )->SetText( aValue );
  613. }
  614. const wxString SCH_SYMBOL::GetFootprintFieldText( bool aResolve, const SCH_SHEET_PATH* aPath,
  615. bool aAllowExtraText ) const
  616. {
  617. if( aResolve )
  618. return GetField( FIELD_T::FOOTPRINT )->GetShownText( aPath, aAllowExtraText );
  619. return GetField( FIELD_T::FOOTPRINT )->GetText();
  620. }
  621. void SCH_SYMBOL::SetFootprintFieldText( const wxString& aFootprint )
  622. {
  623. GetField( FIELD_T::FOOTPRINT )->SetText( aFootprint );
  624. }
  625. SCH_FIELD* SCH_SYMBOL::GetField( FIELD_T aFieldType )
  626. {
  627. if( SCH_FIELD* field = FindField( m_fields, aFieldType ) )
  628. return field;
  629. m_fields.emplace_back( this, aFieldType );
  630. return &m_fields.back();
  631. }
  632. const SCH_FIELD* SCH_SYMBOL::GetField( FIELD_T aFieldType ) const
  633. {
  634. return FindField( m_fields, aFieldType );
  635. }
  636. SCH_FIELD* SCH_SYMBOL::GetField( const wxString& aFieldName )
  637. {
  638. return FindField( m_fields, aFieldName );
  639. }
  640. const SCH_FIELD* SCH_SYMBOL::GetField( const wxString& aFieldName ) const
  641. {
  642. return FindField( m_fields, aFieldName );
  643. }
  644. void SCH_SYMBOL::GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly ) const
  645. {
  646. for( const SCH_FIELD& field : m_fields )
  647. {
  648. if( aVisibleOnly )
  649. {
  650. if( !field.IsVisible() || field.GetText().IsEmpty() )
  651. continue;
  652. }
  653. aVector.push_back( const_cast<SCH_FIELD*>( &field ) );
  654. }
  655. std::sort( aVector.begin(), aVector.end(),
  656. []( SCH_FIELD* lhs, SCH_FIELD* rhs )
  657. {
  658. return lhs->GetOrdinal() < rhs->GetOrdinal();
  659. } );
  660. }
  661. int SCH_SYMBOL::GetNextFieldOrdinal() const
  662. {
  663. return NextFieldOrdinal( m_fields );
  664. }
  665. SCH_FIELD* SCH_SYMBOL::AddField( const SCH_FIELD& aField )
  666. {
  667. m_fields.push_back( aField );
  668. return &m_fields.back();
  669. }
  670. void SCH_SYMBOL::RemoveField( const wxString& aFieldName )
  671. {
  672. for( unsigned ii = 0; ii < m_fields.size(); ++ii )
  673. {
  674. if( m_fields[ii].IsMandatory() )
  675. continue;
  676. if( aFieldName == m_fields[ii].GetName( false ) )
  677. {
  678. m_fields.erase( m_fields.begin() + ii );
  679. return;
  680. }
  681. }
  682. }
  683. SCH_FIELD* SCH_SYMBOL::FindFieldCaseInsensitive( const wxString& aFieldName )
  684. {
  685. for( SCH_FIELD& field : m_fields )
  686. {
  687. if( field.GetName().IsSameAs( aFieldName, false ) )
  688. return &field;
  689. }
  690. return nullptr;
  691. }
  692. void SCH_SYMBOL::UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, bool aUpdateRef,
  693. bool aUpdateOtherFields, bool aResetRef, bool aResetOtherFields )
  694. {
  695. if( m_part )
  696. {
  697. std::vector<SCH_FIELD*> fields;
  698. m_part->GetFields( fields );
  699. for( const SCH_FIELD* libField : fields )
  700. {
  701. SCH_FIELD* schField;
  702. FIELD_T fieldType = FIELD_T::USER;
  703. if( libField->IsMandatory() )
  704. {
  705. fieldType = libField->GetId();
  706. schField = GetField( fieldType );
  707. }
  708. else
  709. {
  710. schField = GetField( libField->GetCanonicalName() );
  711. if( !schField )
  712. {
  713. schField = AddField( SCH_FIELD( this, FIELD_T::USER, libField->GetCanonicalName() ) );
  714. schField->ImportValues( *libField );
  715. schField->SetTextPos( m_pos + libField->GetTextPos() );
  716. }
  717. }
  718. schField->SetPrivate( libField->IsPrivate() );
  719. if( aUpdateStyle )
  720. {
  721. schField->ImportValues( *libField );
  722. schField->SetTextPos( m_pos + libField->GetTextPos() );
  723. }
  724. if( fieldType == FIELD_T::REFERENCE && aPath )
  725. {
  726. if( aResetRef )
  727. SetRef( aPath, m_part->GetField( FIELD_T::REFERENCE )->GetText() );
  728. else if( aUpdateRef )
  729. SetRef( aPath, libField->GetText() );
  730. }
  731. else if( fieldType == FIELD_T::VALUE )
  732. {
  733. SetValueFieldText( UnescapeString( libField->GetText() ) );
  734. }
  735. else if( fieldType == FIELD_T::DATASHEET )
  736. {
  737. if( aResetOtherFields )
  738. schField->SetText( GetDatasheet() ); // alias-specific value
  739. else if( aUpdateOtherFields )
  740. schField->SetText( libField->GetText() );
  741. }
  742. else
  743. {
  744. if( aResetOtherFields || aUpdateOtherFields )
  745. schField->SetText( libField->GetText() );
  746. }
  747. }
  748. }
  749. }
  750. void SCH_SYMBOL::SyncOtherUnits( const SCH_SHEET_PATH& aSourceSheet, SCH_COMMIT& aCommit,
  751. PROPERTY_BASE* aProperty )
  752. {
  753. bool updateValue = true;
  754. bool updateExclFromBOM = true;
  755. bool updateExclFromBoard = true;
  756. bool updateDNP = true;
  757. bool updateOtherFields = true;
  758. bool updatePins = true;
  759. if( aProperty )
  760. {
  761. updateValue = aProperty->Name() == _HKI( "Value" );
  762. updateExclFromBoard = aProperty->Name() == _HKI( "Exclude From Board" );
  763. updateExclFromBOM = aProperty->Name() == _HKI( "Exclude From Bill of Materials" );
  764. updateDNP = aProperty->Name() == _HKI( "Do not Populate" );
  765. updateOtherFields = false;
  766. updatePins = false;
  767. }
  768. if( !updateValue
  769. && !updateExclFromBOM
  770. && !updateExclFromBoard
  771. && !updateDNP
  772. && !updateOtherFields
  773. && !updatePins )
  774. {
  775. return;
  776. }
  777. // Keep fields other than the reference, include/exclude flags, and alternate pin assignments
  778. // in sync in multi-unit parts.
  779. if( GetUnitCount() > 1 && IsAnnotated( &aSourceSheet ) )
  780. {
  781. wxString ref = GetRef( &aSourceSheet );
  782. for( SCH_SHEET_PATH& sheet : Schematic()->Hierarchy() )
  783. {
  784. SCH_SCREEN* screen = sheet.LastScreen();
  785. std::vector<SCH_SYMBOL*> otherUnits;
  786. CollectOtherUnits( ref, m_unit, m_lib_id, sheet, &otherUnits );
  787. for( SCH_SYMBOL* otherUnit : otherUnits )
  788. {
  789. aCommit.Modify( otherUnit, screen );
  790. if( updateValue )
  791. otherUnit->SetValueFieldText( GetField( FIELD_T::VALUE )->GetText() );
  792. if( updateOtherFields )
  793. {
  794. for( SCH_FIELD& field : m_fields )
  795. {
  796. if( field.GetId() == FIELD_T::REFERENCE || field.GetId() == FIELD_T::VALUE )
  797. {
  798. // already handled
  799. continue;
  800. }
  801. SCH_FIELD* otherField;
  802. if( field.IsMandatory() )
  803. otherField = otherUnit->GetField( field.GetId() );
  804. else
  805. otherField = otherUnit->GetField( field.GetName() );
  806. if( otherField )
  807. {
  808. otherField->SetText( field.GetText() );
  809. }
  810. else
  811. {
  812. SCH_FIELD newField( field );
  813. const_cast<KIID&>( newField.m_Uuid ) = KIID();
  814. newField.Offset( -GetPosition() );
  815. newField.Offset( otherUnit->GetPosition() );
  816. newField.SetParent( otherUnit );
  817. otherUnit->AddField( newField );
  818. }
  819. }
  820. for( int ii = (int) otherUnit->GetFields().size() - 1; ii >= 0; ii-- )
  821. {
  822. SCH_FIELD& otherField = otherUnit->GetFields()[ii];
  823. if( !otherField.IsMandatory() && !GetField( otherField.GetName() ) )
  824. otherUnit->GetFields().erase( otherUnit->GetFields().begin() + ii );
  825. }
  826. }
  827. if( updateExclFromBOM )
  828. otherUnit->SetExcludedFromBOM( m_excludedFromBOM );
  829. if( updateExclFromBoard )
  830. otherUnit->SetExcludedFromBoard( m_excludedFromBoard );
  831. if( updateDNP )
  832. otherUnit->SetDNP( m_DNP );
  833. if( updatePins )
  834. {
  835. for( const std::unique_ptr<SCH_PIN>& model_pin : m_pins )
  836. {
  837. SCH_PIN* src_pin = otherUnit->GetPin( model_pin->GetNumber() );
  838. if( src_pin )
  839. src_pin->SetAlt( model_pin->GetAlt() );
  840. }
  841. }
  842. }
  843. }
  844. }
  845. }
  846. void SCH_SYMBOL::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction, RECURSE_MODE aMode )
  847. {
  848. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  849. aFunction( pin.get() );
  850. for( SCH_FIELD& field : m_fields )
  851. aFunction( &field );
  852. }
  853. SCH_PIN* SCH_SYMBOL::GetPin( const wxString& aNumber ) const
  854. {
  855. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  856. {
  857. if( pin->GetNumber() == aNumber )
  858. return pin.get();
  859. }
  860. return nullptr;
  861. }
  862. const SCH_PIN* SCH_SYMBOL::GetPin( const VECTOR2I& aPos ) const
  863. {
  864. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  865. {
  866. int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
  867. : GetUnit();
  868. int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
  869. : GetBodyStyle();
  870. if( pin_unit > 0 && pin_unit != GetUnit() )
  871. continue;
  872. if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
  873. continue;
  874. if( pin->GetPosition() == aPos )
  875. return pin.get();
  876. }
  877. return nullptr;
  878. }
  879. std::vector<SCH_PIN*> SCH_SYMBOL::GetLibPins() const
  880. {
  881. if( m_part )
  882. return m_part->GetPins( m_unit, m_bodyStyle );
  883. return std::vector<SCH_PIN*>();
  884. }
  885. std::vector<SCH_PIN*> SCH_SYMBOL::GetAllLibPins() const
  886. {
  887. if( m_part )
  888. return m_part->GetPins();
  889. return std::vector<SCH_PIN*>();
  890. }
  891. size_t SCH_SYMBOL::GetFullPinCount() const
  892. {
  893. return m_part ? m_part->GetPinCount() : 0;
  894. }
  895. SCH_PIN* SCH_SYMBOL::GetPin( SCH_PIN* aLibPin ) const
  896. {
  897. auto it = m_pinMap.find( aLibPin );
  898. if( it != m_pinMap.end() )
  899. return it->second;
  900. wxFAIL_MSG_AT( "Pin not found", __FILE__, __LINE__, __FUNCTION__ );
  901. return nullptr;
  902. }
  903. std::vector<SCH_PIN*> SCH_SYMBOL::GetPins( const SCH_SHEET_PATH* aSheet ) const
  904. {
  905. std::vector<SCH_PIN*> pins;
  906. if( aSheet == nullptr )
  907. {
  908. wxCHECK_MSG( Schematic(), pins, "Can't call GetPins on a symbol with no schematic" );
  909. aSheet = &Schematic()->CurrentSheet();
  910. }
  911. int unit = GetUnitSelection( aSheet );
  912. for( const std::unique_ptr<SCH_PIN>& p : m_pins )
  913. {
  914. if( unit && p->GetLibPin() && p->GetLibPin()->GetUnit()
  915. && ( p->GetLibPin()->GetUnit() != unit ) )
  916. {
  917. continue;
  918. }
  919. pins.push_back( p.get() );
  920. }
  921. return pins;
  922. }
  923. std::vector<SCH_PIN*> SCH_SYMBOL::GetPins() const
  924. {
  925. return GetPins( nullptr );
  926. }
  927. void SCH_SYMBOL::swapData( SCH_ITEM* aItem )
  928. {
  929. wxCHECK_RET( aItem != nullptr && aItem->Type() == SCH_SYMBOL_T,
  930. wxT( "Cannot swap data with invalid symbol." ) );
  931. SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( aItem );
  932. std::swap( m_lib_id, symbol->m_lib_id );
  933. m_pins.swap( symbol->m_pins ); // std::vector's swap()
  934. for( std::unique_ptr<SCH_PIN>& pin : symbol->m_pins )
  935. pin->SetParent( symbol );
  936. for( std::unique_ptr<SCH_PIN>& pin : m_pins )
  937. pin->SetParent( this );
  938. LIB_SYMBOL* libSymbol = symbol->m_part.release();
  939. symbol->m_part = std::move( m_part );
  940. symbol->UpdatePins();
  941. m_part.reset( libSymbol );
  942. UpdatePins();
  943. std::swap( m_pos, symbol->m_pos );
  944. std::swap( m_unit, symbol->m_unit );
  945. std::swap( m_bodyStyle, symbol->m_bodyStyle );
  946. m_fields.swap( symbol->m_fields ); // std::vector's swap()
  947. for( SCH_FIELD& field : symbol->m_fields )
  948. field.SetParent( symbol );
  949. for( SCH_FIELD& field : m_fields )
  950. field.SetParent( this );
  951. TRANSFORM tmp = m_transform;
  952. m_transform = symbol->m_transform;
  953. symbol->m_transform = tmp;
  954. std::swap( m_excludedFromSim, symbol->m_excludedFromSim );
  955. std::swap( m_excludedFromBOM, symbol->m_excludedFromBOM );
  956. std::swap( m_DNP, symbol->m_DNP );
  957. std::swap( m_excludedFromBoard, symbol->m_excludedFromBoard );
  958. std::swap( m_instanceReferences, symbol->m_instanceReferences );
  959. std::swap( m_schLibSymbolName, symbol->m_schLibSymbolName );
  960. }
  961. void SCH_SYMBOL::GetContextualTextVars( wxArrayString* aVars ) const
  962. {
  963. for( const SCH_FIELD& field : m_fields )
  964. {
  965. if( field.IsPrivate() )
  966. continue;
  967. if( field.IsMandatory() )
  968. aVars->push_back( field.GetCanonicalName().Upper() );
  969. else
  970. aVars->push_back( field.GetName() );
  971. }
  972. aVars->push_back( wxT( "OP" ) );
  973. aVars->push_back( wxT( "FOOTPRINT_LIBRARY" ) );
  974. aVars->push_back( wxT( "FOOTPRINT_NAME" ) );
  975. aVars->push_back( wxT( "UNIT" ) );
  976. aVars->push_back( wxT( "SHORT_REFERENCE" ) );
  977. aVars->push_back( wxT( "SYMBOL_LIBRARY" ) );
  978. aVars->push_back( wxT( "SYMBOL_NAME" ) );
  979. aVars->push_back( wxT( "SYMBOL_DESCRIPTION" ) );
  980. aVars->push_back( wxT( "SYMBOL_KEYWORDS" ) );
  981. aVars->push_back( wxT( "EXCLUDE_FROM_BOM" ) );
  982. aVars->push_back( wxT( "EXCLUDE_FROM_BOARD" ) );
  983. aVars->push_back( wxT( "EXCLUDE_FROM_SIM" ) );
  984. aVars->push_back( wxT( "DNP" ) );
  985. aVars->push_back( wxT( "SHORT_NET_NAME(<pin_number>)" ) );
  986. aVars->push_back( wxT( "NET_NAME(<pin_number>)" ) );
  987. aVars->push_back( wxT( "NET_CLASS(<pin_number>)" ) );
  988. aVars->push_back( wxT( "PIN_NAME(<pin_number>)" ) );
  989. }
  990. bool SCH_SYMBOL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const
  991. {
  992. static wxRegEx operatingPoint( wxT( "^"
  993. "OP"
  994. "(:[^.]*)?" // pin
  995. "(.([0-9])?" // precisionStr
  996. "([a-zA-Z]*))?" // rangeStr
  997. "$" ) );
  998. wxCHECK( aPath, false );
  999. SCHEMATIC* schematic = Schematic();
  1000. if( !schematic )
  1001. return false;
  1002. if( operatingPoint.Matches( *token ) )
  1003. {
  1004. wxString pin( operatingPoint.GetMatch( *token, 1 ).Lower() );
  1005. wxString precisionStr( operatingPoint.GetMatch( *token, 3 ) );
  1006. wxString rangeStr( operatingPoint.GetMatch( *token, 4 ) );
  1007. int precision = precisionStr.IsEmpty() ? 3 : precisionStr[0] - '0';
  1008. wxString range = rangeStr.IsEmpty() ? wxString( wxS( "~A" ) ) : rangeStr;
  1009. SIM_LIB_MGR simLibMgr( &schematic->Prj() );
  1010. std::vector<EMBEDDED_FILES*> embeddedFilesStack;
  1011. embeddedFilesStack.push_back( schematic->GetEmbeddedFiles() );
  1012. if( m_part )
  1013. embeddedFilesStack.push_back( m_part->GetEmbeddedFiles() );
  1014. simLibMgr.SetFilesStack( std::move( embeddedFilesStack ) );
  1015. NULL_REPORTER devnull;
  1016. SIM_MODEL& model = simLibMgr.CreateModel( aPath, const_cast<SCH_SYMBOL&>( *this ),
  1017. true, aDepth + 1, devnull ).model;
  1018. SPICE_ITEM spiceItem;
  1019. spiceItem.refName = GetRef( aPath );
  1020. wxString spiceRef = model.SpiceGenerator().ItemName( spiceItem );
  1021. spiceRef = spiceRef.Lower();
  1022. if( pin.IsEmpty() )
  1023. {
  1024. *token = schematic->GetOperatingPoint( spiceRef, precision, range );
  1025. return true;
  1026. }
  1027. else if( pin == wxS( ":power" ) )
  1028. {
  1029. if( rangeStr.IsEmpty() )
  1030. range = wxS( "~W" );
  1031. *token = schematic->GetOperatingPoint( spiceRef + wxS( ":power" ), precision, range );
  1032. return true;
  1033. }
  1034. else
  1035. {
  1036. pin = pin.SubString( 1, -1 ); // Strip ':' from front
  1037. for( const std::reference_wrapper<const SIM_MODEL_PIN>& modelPin : model.GetPins() )
  1038. {
  1039. SCH_PIN* symbolPin = GetPin( modelPin.get().symbolPinNumber );
  1040. if( pin == symbolPin->GetName().Lower() || pin == symbolPin->GetNumber().Lower() )
  1041. {
  1042. if( model.GetPins().size() == 2 )
  1043. {
  1044. *token = schematic->GetOperatingPoint( spiceRef, precision, range );
  1045. }
  1046. else
  1047. {
  1048. wxString signalName = spiceRef + wxS( ":" ) + modelPin.get().modelPinName;
  1049. *token = schematic->GetOperatingPoint( signalName, precision, range );
  1050. }
  1051. return true;
  1052. }
  1053. }
  1054. }
  1055. *token = wxS( "?" );
  1056. return true;
  1057. }
  1058. if( token->Contains( ':' ) )
  1059. {
  1060. if( schematic->ResolveCrossReference( token, aDepth + 1 ) )
  1061. return true;
  1062. }
  1063. wxString upperToken = token->Upper();
  1064. for( const SCH_FIELD& field : m_fields )
  1065. {
  1066. wxString fieldName = field.IsMandatory() ? field.GetCanonicalName()
  1067. : field.GetName();
  1068. wxString textToken = field.GetText();
  1069. textToken.Replace( " ", wxEmptyString );
  1070. wxString tokenString = "${" + fieldName + "}";
  1071. // If the field data is just a reference to the field, don't resolve
  1072. if( textToken.IsSameAs( tokenString, false ) )
  1073. return true;
  1074. if( token->IsSameAs( fieldName, false ) )
  1075. {
  1076. if( field.GetId() == FIELD_T::REFERENCE )
  1077. *token = GetRef( aPath, true );
  1078. else
  1079. *token = field.GetShownText( aPath, false, aDepth + 1 );
  1080. return true;
  1081. }
  1082. }
  1083. // Consider missing simulation fields as empty, not un-resolved
  1084. if( token->IsSameAs( wxT( "SIM.DEVICE" ) )
  1085. || token->IsSameAs( wxT( "SIM.TYPE" ) )
  1086. || token->IsSameAs( wxT( "SIM.PINS" ) )
  1087. || token->IsSameAs( wxT( "SIM.PARAMS" ) )
  1088. || token->IsSameAs( wxT( "SIM.LIBRARY" ) )
  1089. || token->IsSameAs( wxT( "SIM.NAME" ) ) )
  1090. {
  1091. *token = wxEmptyString;
  1092. return true;
  1093. }
  1094. for( const TEMPLATE_FIELDNAME& templateFieldname :
  1095. schematic->Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
  1096. {
  1097. if( token->IsSameAs( templateFieldname.m_Name )
  1098. || token->IsSameAs( templateFieldname.m_Name.Upper() ) )
  1099. {
  1100. // If we didn't find it in the fields list then it isn't set on this symbol.
  1101. // Just return an empty string.
  1102. *token = wxEmptyString;
  1103. return true;
  1104. }
  1105. }
  1106. if( token->IsSameAs( wxT( "FOOTPRINT_LIBRARY" ) ) )
  1107. {
  1108. wxString footprint = GetFootprintFieldText( true, aPath, false );
  1109. wxArrayString parts = wxSplit( footprint, ':' );
  1110. if( parts.Count() > 0 )
  1111. *token = parts[ 0 ];
  1112. else
  1113. *token = wxEmptyString;
  1114. return true;
  1115. }
  1116. else if( token->IsSameAs( wxT( "FOOTPRINT_NAME" ) ) )
  1117. {
  1118. wxString footprint = GetFootprintFieldText( true, aPath, false );
  1119. wxArrayString parts = wxSplit( footprint, ':' );
  1120. if( parts.Count() > 1 )
  1121. *token = parts[ std::min( 1, (int) parts.size() - 1 ) ];
  1122. else
  1123. *token = wxEmptyString;
  1124. return true;
  1125. }
  1126. else if( token->IsSameAs( wxT( "UNIT" ) ) )
  1127. {
  1128. *token = SubReference( GetUnitSelection( aPath ) );
  1129. return true;
  1130. }
  1131. else if( token->IsSameAs( wxT( "SHORT_REFERENCE" ) ) )
  1132. {
  1133. *token = GetRef( aPath, false );
  1134. return true;
  1135. }
  1136. else if( token->IsSameAs( wxT( "SYMBOL_LIBRARY" ) ) )
  1137. {
  1138. *token = m_lib_id.GetUniStringLibNickname();
  1139. return true;
  1140. }
  1141. else if( token->IsSameAs( wxT( "SYMBOL_NAME" ) ) )
  1142. {
  1143. *token = m_lib_id.GetUniStringLibItemName();
  1144. return true;
  1145. }
  1146. else if( token->IsSameAs( wxT( "SYMBOL_DESCRIPTION" ) ) )
  1147. {
  1148. *token = GetDescription();
  1149. return true;
  1150. }
  1151. else if( token->IsSameAs( wxT( "SYMBOL_KEYWORDS" ) ) )
  1152. {
  1153. *token = GetKeyWords();
  1154. return true;
  1155. }
  1156. else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOM" ) ) )
  1157. {
  1158. *token = wxEmptyString;
  1159. if( aPath->GetExcludedFromBOM() || this->GetExcludedFromBOM() )
  1160. *token = _( "Excluded from BOM" );
  1161. return true;
  1162. }
  1163. else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOARD" ) ) )
  1164. {
  1165. *token = wxEmptyString;
  1166. if( aPath->GetExcludedFromBoard() || this->GetExcludedFromBoard() )
  1167. *token = _( "Excluded from board" );
  1168. return true;
  1169. }
  1170. else if( token->IsSameAs( wxT( "EXCLUDE_FROM_SIM" ) ) )
  1171. {
  1172. *token = wxEmptyString;
  1173. if( aPath->GetExcludedFromSim() || this->GetExcludedFromSim() )
  1174. *token = _( "Excluded from simulation" );
  1175. return true;
  1176. }
  1177. else if( token->IsSameAs( wxT( "DNP" ) ) )
  1178. {
  1179. *token = wxEmptyString;
  1180. if( aPath->GetDNP() || this->GetDNP() )
  1181. *token = _( "DNP" );
  1182. return true;
  1183. }
  1184. else if( token->StartsWith( wxT( "SHORT_NET_NAME(" ) )
  1185. || token->StartsWith( wxT( "NET_NAME(" ) )
  1186. || token->StartsWith( wxT( "NET_CLASS(" ) )
  1187. || token->StartsWith( wxT( "PIN_NAME(" ) ) )
  1188. {
  1189. wxString pinNumber = token->AfterFirst( '(' );
  1190. pinNumber = pinNumber.BeforeLast( ')' );
  1191. for( SCH_PIN* pin : GetPins( aPath ) )
  1192. {
  1193. if( pin->GetNumber() == pinNumber )
  1194. {
  1195. if( token->StartsWith( wxT( "PIN_NAME" ) ) )
  1196. {
  1197. *token = pin->GetAlt().IsEmpty() ? pin->GetName() : pin->GetAlt();
  1198. return true;
  1199. }
  1200. SCH_CONNECTION* conn = pin->Connection( aPath );
  1201. if( !conn )
  1202. *token = wxEmptyString;
  1203. else if( token->StartsWith( wxT( "SHORT_NET_NAME" ) ) )
  1204. *token = conn->LocalName();
  1205. else if( token->StartsWith( wxT( "NET_NAME" ) ) )
  1206. *token = conn->Name();
  1207. else if( token->StartsWith( wxT( "NET_CLASS" ) ) )
  1208. *token = pin->GetEffectiveNetClass( aPath )->GetName();
  1209. return true;
  1210. }
  1211. }
  1212. }
  1213. // See if parent can resolve it (this will recurse to ancestors)
  1214. if( aPath->Last() && aPath->Last()->ResolveTextVar( aPath, token, aDepth + 1 ) )
  1215. return true;
  1216. return false;
  1217. }
  1218. void SCH_SYMBOL::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath, bool aResetPrefix )
  1219. {
  1220. if( aSheetPath )
  1221. {
  1222. KIID_PATH path = aSheetPath->Path();
  1223. for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  1224. {
  1225. if( instance.m_Path == path )
  1226. {
  1227. if( instance.m_Reference.IsEmpty() || aResetPrefix )
  1228. instance.m_Reference = UTIL::GetRefDesUnannotated( m_prefix );
  1229. else
  1230. instance.m_Reference = UTIL::GetRefDesUnannotated( instance.m_Reference );
  1231. }
  1232. }
  1233. }
  1234. else
  1235. {
  1236. for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  1237. {
  1238. if( instance.m_Reference.IsEmpty() || aResetPrefix)
  1239. instance.m_Reference = UTIL::GetRefDesUnannotated( m_prefix );
  1240. else
  1241. instance.m_Reference = UTIL::GetRefDesUnannotated( instance.m_Reference );
  1242. }
  1243. }
  1244. for( std::unique_ptr<SCH_PIN>& pin : m_pins )
  1245. pin->ClearDefaultNetName( aSheetPath );
  1246. // These 2 changes do not work in complex hierarchy.
  1247. // When a clear annotation is made, the calling function must call a
  1248. // UpdateAllScreenReferences for the active sheet.
  1249. // But this call cannot made here.
  1250. wxString currentReference = GetField( FIELD_T::REFERENCE )->GetText();
  1251. if( currentReference.IsEmpty() || aResetPrefix )
  1252. GetField( FIELD_T::REFERENCE )->SetText( UTIL::GetRefDesUnannotated( m_prefix ) );
  1253. else
  1254. GetField( FIELD_T::REFERENCE )->SetText( UTIL::GetRefDesUnannotated( currentReference ) );
  1255. }
  1256. bool SCH_SYMBOL::AddSheetPathReferenceEntryIfMissing( const KIID_PATH& aSheetPath )
  1257. {
  1258. // An empty sheet path is illegal, at a minimum the root sheet UUID must be present.
  1259. wxCHECK( aSheetPath.size() > 0, false );
  1260. for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
  1261. {
  1262. // if aSheetPath is found, nothing to do:
  1263. if( instance.m_Path == aSheetPath )
  1264. return false;
  1265. }
  1266. // This entry does not exist: add it, with its last-used reference
  1267. AddHierarchicalReference( aSheetPath, GetField( FIELD_T::REFERENCE )->GetText(), m_unit );
  1268. return true;
  1269. }
  1270. void SCH_SYMBOL::SetOrientation( int aOrientation )
  1271. {
  1272. TRANSFORM temp = TRANSFORM();
  1273. bool transform = false;
  1274. switch( aOrientation )
  1275. {
  1276. case SYM_ORIENT_0:
  1277. case SYM_NORMAL: // default transform matrix
  1278. m_transform = TRANSFORM();
  1279. break;
  1280. case SYM_ROTATE_COUNTERCLOCKWISE: // Rotate + (incremental rotation)
  1281. temp.x1 = 0;
  1282. temp.y1 = 1;
  1283. temp.x2 = -1;
  1284. temp.y2 = 0;
  1285. transform = true;
  1286. break;
  1287. case SYM_ROTATE_CLOCKWISE: // Rotate - (incremental rotation)
  1288. temp.x1 = 0;
  1289. temp.y1 = -1;
  1290. temp.x2 = 1;
  1291. temp.y2 = 0;
  1292. transform = true;
  1293. break;
  1294. case SYM_MIRROR_Y: // Mirror Y (incremental transform)
  1295. temp.x1 = -1;
  1296. temp.y1 = 0;
  1297. temp.x2 = 0;
  1298. temp.y2 = 1;
  1299. transform = true;
  1300. break;
  1301. case SYM_MIRROR_X: // Mirror X (incremental transform)
  1302. temp.x1 = 1;
  1303. temp.y1 = 0;
  1304. temp.x2 = 0;
  1305. temp.y2 = -1;
  1306. transform = true;
  1307. break;
  1308. case SYM_ORIENT_90:
  1309. SetOrientation( SYM_ORIENT_0 );
  1310. SetOrientation( SYM_ROTATE_COUNTERCLOCKWISE );
  1311. break;
  1312. case SYM_ORIENT_180:
  1313. SetOrientation( SYM_ORIENT_0 );
  1314. SetOrientation( SYM_ROTATE_COUNTERCLOCKWISE );
  1315. SetOrientation( SYM_ROTATE_COUNTERCLOCKWISE );
  1316. break;
  1317. case SYM_ORIENT_270:
  1318. SetOrientation( SYM_ORIENT_0 );
  1319. SetOrientation( SYM_ROTATE_CLOCKWISE );
  1320. break;
  1321. case ( SYM_ORIENT_0 + SYM_MIRROR_X ):
  1322. SetOrientation( SYM_ORIENT_0 );
  1323. SetOrientation( SYM_MIRROR_X );
  1324. break;
  1325. case ( SYM_ORIENT_0 + SYM_MIRROR_Y ):
  1326. SetOrientation( SYM_ORIENT_0 );
  1327. SetOrientation( SYM_MIRROR_Y );
  1328. break;
  1329. case ( SYM_ORIENT_0 + SYM_MIRROR_X + SYM_MIRROR_Y ):
  1330. SetOrientation( SYM_ORIENT_0 );
  1331. SetOrientation( SYM_MIRROR_X );
  1332. SetOrientation( SYM_MIRROR_Y );
  1333. break;
  1334. case ( SYM_ORIENT_90 + SYM_MIRROR_X ):
  1335. SetOrientation( SYM_ORIENT_90 );
  1336. SetOrientation( SYM_MIRROR_X );
  1337. break;
  1338. case ( SYM_ORIENT_90 + SYM_MIRROR_Y ):
  1339. SetOrientation( SYM_ORIENT_90 );
  1340. SetOrientation( SYM_MIRROR_Y );
  1341. break;
  1342. case ( SYM_ORIENT_90 + SYM_MIRROR_X + SYM_MIRROR_Y ):
  1343. SetOrientation( SYM_ORIENT_90 );
  1344. SetOrientation( SYM_MIRROR_X );
  1345. SetOrientation( SYM_MIRROR_Y );
  1346. break;
  1347. case ( SYM_ORIENT_180 + SYM_MIRROR_X ):
  1348. SetOrientation( SYM_ORIENT_180 );
  1349. SetOrientation( SYM_MIRROR_X );
  1350. break;
  1351. case ( SYM_ORIENT_180 + SYM_MIRROR_Y ):
  1352. SetOrientation( SYM_ORIENT_180 );
  1353. SetOrientation( SYM_MIRROR_Y );
  1354. break;
  1355. case ( SYM_ORIENT_180 + SYM_MIRROR_X + SYM_MIRROR_Y ):
  1356. SetOrientation( SYM_ORIENT_180 );
  1357. SetOrientation( SYM_MIRROR_X );
  1358. SetOrientation( SYM_MIRROR_Y );
  1359. break;
  1360. case ( SYM_ORIENT_270 + SYM_MIRROR_X ):
  1361. SetOrientation( SYM_ORIENT_270 );
  1362. SetOrientation( SYM_MIRROR_X );
  1363. break;
  1364. case ( SYM_ORIENT_270 + SYM_MIRROR_Y ):
  1365. SetOrientation( SYM_ORIENT_270 );
  1366. SetOrientation( SYM_MIRROR_Y );
  1367. break;
  1368. case ( SYM_ORIENT_270 + SYM_MIRROR_X + SYM_MIRROR_Y ):
  1369. SetOrientation( SYM_ORIENT_270 );
  1370. SetOrientation( SYM_MIRROR_X );
  1371. SetOrientation( SYM_MIRROR_Y );
  1372. break;
  1373. default:
  1374. transform = false;
  1375. wxFAIL_MSG( "Invalid schematic symbol orientation type." );
  1376. break;
  1377. }
  1378. if( transform )
  1379. {
  1380. /* The new matrix transform is the old matrix transform modified by the
  1381. * requested transformation, which is the temp transform (rot,
  1382. * mirror ..) in order to have (in term of matrix transform):
  1383. * transform coord = new_m_transform * coord
  1384. * where transform coord is the coord modified by new_m_transform from
  1385. * the initial value coord.
  1386. * new_m_transform is computed (from old_m_transform and temp) to
  1387. * have:
  1388. * transform coord = old_m_transform * temp
  1389. */
  1390. TRANSFORM newTransform;
  1391. newTransform.x1 = m_transform.x1 * temp.x1 + m_transform.x2 * temp.y1;
  1392. newTransform.y1 = m_transform.y1 * temp.x1 + m_transform.y2 * temp.y1;
  1393. newTransform.x2 = m_transform.x1 * temp.x2 + m_transform.x2 * temp.y2;
  1394. newTransform.y2 = m_transform.y1 * temp.x2 + m_transform.y2 * temp.y2;
  1395. m_transform = newTransform;
  1396. }
  1397. }
  1398. int SCH_SYMBOL::GetOrientation() const
  1399. {
  1400. /*
  1401. * This is slow, but also a bizarre algorithm. I don't feel like unteasing the algorithm right
  1402. * now, so let's just cache it for the moment.
  1403. */
  1404. if( s_transformToOrientationCache.count( m_transform ) )
  1405. return s_transformToOrientationCache.at( m_transform );
  1406. int rotate_values[] =
  1407. {
  1408. SYM_ORIENT_0,
  1409. SYM_ORIENT_90,
  1410. SYM_ORIENT_180,
  1411. SYM_ORIENT_270,
  1412. SYM_MIRROR_X + SYM_ORIENT_0,
  1413. SYM_MIRROR_X + SYM_ORIENT_90,
  1414. SYM_MIRROR_X + SYM_ORIENT_270,
  1415. SYM_MIRROR_Y,
  1416. SYM_MIRROR_Y + SYM_ORIENT_0,
  1417. SYM_MIRROR_Y + SYM_ORIENT_90,
  1418. SYM_MIRROR_Y + SYM_ORIENT_180,
  1419. SYM_MIRROR_Y + SYM_ORIENT_270
  1420. };
  1421. // Try to find the current transform option:
  1422. TRANSFORM transform = m_transform;
  1423. SCH_SYMBOL temp( *this );
  1424. temp.SetParentGroup( nullptr );
  1425. for( int type_rotate : rotate_values )
  1426. {
  1427. temp.SetOrientation( type_rotate );
  1428. if( transform == temp.GetTransform() )
  1429. {
  1430. s_transformToOrientationCache[m_transform] = type_rotate;
  1431. return type_rotate;
  1432. }
  1433. }
  1434. // Error: orientation not found in list (should not happen)
  1435. wxFAIL_MSG( "Schematic symbol orientation matrix internal error." );
  1436. return SYM_NORMAL;
  1437. }
  1438. #if defined(DEBUG)
  1439. void SCH_SYMBOL::Show( int nestLevel, std::ostream& os ) const
  1440. {
  1441. // for now, make it look like XML:
  1442. NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
  1443. << " ref=\"" << TO_UTF8( GetField( FIELD_T::REFERENCE )->GetName() )
  1444. << '"' << " chipName=\""
  1445. << GetLibId().Format().wx_str() << '"' << m_pos
  1446. << " layer=\"" << m_layer
  1447. << '"' << ">\n";
  1448. // skip the reference, it's been output already.
  1449. for( int i = 1; i < (int) GetFields().size(); ++i )
  1450. {
  1451. const wxString& value = GetFields()[i].GetText();
  1452. if( !value.IsEmpty() )
  1453. {
  1454. NestedSpace( nestLevel + 1, os ) << "<field" << " name=\""
  1455. << TO_UTF8( GetFields()[i].GetName() )
  1456. << '"' << " value=\""
  1457. << TO_UTF8( value ) << "\"/>\n";
  1458. }
  1459. }
  1460. NestedSpace( nestLevel, os ) << "</" << TO_UTF8( GetClass().Lower() ) << ">\n";
  1461. }
  1462. #endif
  1463. BOX2I SCH_SYMBOL::doGetBoundingBox( bool aIncludePins, bool aIncludeFields ) const
  1464. {
  1465. BOX2I bBox;
  1466. if( m_part )
  1467. bBox = m_part->GetBodyBoundingBox( m_unit, m_bodyStyle, aIncludePins, false );
  1468. else
  1469. bBox = LIB_SYMBOL::GetDummy()->GetBodyBoundingBox( m_unit, m_bodyStyle, aIncludePins,
  1470. false );
  1471. bBox = m_transform.TransformCoordinate( bBox );
  1472. bBox.Normalize();
  1473. bBox.Offset( m_pos );
  1474. if( aIncludeFields )
  1475. {
  1476. for( const SCH_FIELD& field : m_fields )
  1477. {
  1478. if( field.IsVisible() )
  1479. bBox.Merge( field.GetBoundingBox() );
  1480. }
  1481. }
  1482. return bBox;
  1483. }
  1484. BOX2I SCH_SYMBOL::GetBodyBoundingBox() const
  1485. {
  1486. try
  1487. {
  1488. return doGetBoundingBox( false, false );
  1489. }
  1490. catch( const boost::bad_pointer& e )
  1491. {
  1492. wxFAIL_MSG( wxString::Format( wxT( "Boost pointer exception occurred: %s" ), e.what() ) );
  1493. return BOX2I();
  1494. }
  1495. }
  1496. BOX2I SCH_SYMBOL::GetBodyAndPinsBoundingBox() const
  1497. {
  1498. return doGetBoundingBox( true, false );
  1499. }
  1500. const BOX2I SCH_SYMBOL::GetBoundingBox() const
  1501. {
  1502. return doGetBoundingBox( true, true );
  1503. }
  1504. void SCH_SYMBOL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  1505. {
  1506. wxString msg;
  1507. SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
  1508. SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
  1509. auto addExcludes =
  1510. [&]()
  1511. {
  1512. wxArrayString msgs;
  1513. if( GetExcludedFromSim() )
  1514. msgs.Add( _( "Simulation" ) );
  1515. if( GetExcludedFromBOM() )
  1516. msgs.Add( _( "BOM" ) );
  1517. if( GetExcludedFromBoard() )
  1518. msgs.Add( _( "Board" ) );
  1519. if( GetDNP() )
  1520. msgs.Add( _( "DNP" ) );
  1521. msg = wxJoin( msgs, '|' );
  1522. msg.Replace( '|', wxS( ", " ) );
  1523. if( !msg.empty() )
  1524. aList.emplace_back( _( "Exclude from" ), msg );
  1525. };
  1526. // part and alias can differ if alias is not the root
  1527. if( m_part )
  1528. {
  1529. if( m_part.get() != LIB_SYMBOL::GetDummy() )
  1530. {
  1531. if( m_part->IsPower() )
  1532. {
  1533. // Don't use GetShownText(); we want to see the variable references here
  1534. aList.emplace_back( _( "Power symbol" ),
  1535. KIUI::EllipsizeStatusText( aFrame, GetField( FIELD_T::VALUE )->GetText() ) );
  1536. }
  1537. else
  1538. {
  1539. aList.emplace_back( _( "Reference" ),
  1540. UnescapeString( GetRef( currentSheet ) ) );
  1541. // Don't use GetShownText(); we want to see the variable references here
  1542. aList.emplace_back( _( "Value" ),
  1543. KIUI::EllipsizeStatusText( aFrame, GetField( FIELD_T::VALUE )->GetText() ) );
  1544. addExcludes();
  1545. aList.emplace_back( _( "Name" ),
  1546. KIUI::EllipsizeStatusText( aFrame,
  1547. GetLibId().GetLibItemName() ) );
  1548. }
  1549. #if 0 // Display symbol flags, for debug only
  1550. aList.emplace_back( _( "flags" ), wxString::Format( "%X", GetEditFlags() ) );
  1551. #endif
  1552. if( !m_part->IsRoot() )
  1553. {
  1554. msg = _( "Missing parent" );
  1555. std::shared_ptr< LIB_SYMBOL > parent = m_part->GetParent().lock();
  1556. if( parent )
  1557. msg = parent->GetName();
  1558. aList.emplace_back( _( "Derived from" ), UnescapeString( msg ) );
  1559. }
  1560. else if( !m_lib_id.GetLibNickname().empty() )
  1561. {
  1562. aList.emplace_back( _( "Library" ), m_lib_id.GetLibNickname() );
  1563. }
  1564. else
  1565. {
  1566. aList.emplace_back( _( "Library" ), _( "Undefined!!!" ) );
  1567. }
  1568. // Display the current associated footprint, if exists.
  1569. // Don't use GetShownText(); we want to see the variable references here
  1570. msg = KIUI::EllipsizeStatusText( aFrame, GetField( FIELD_T::FOOTPRINT )->GetText() );
  1571. if( msg.IsEmpty() )
  1572. msg = _( "<Unknown>" );
  1573. aList.emplace_back( _( "Footprint" ), msg );
  1574. // Display description of the symbol, and keywords found in lib
  1575. aList.emplace_back( _( "Description" ) + wxT( ": " )
  1576. + GetField( FIELD_T::DESCRIPTION )->GetText(),
  1577. _( "Keywords" ) + wxT( ": " ) + m_part->GetKeyWords() );
  1578. }
  1579. }
  1580. else
  1581. {
  1582. aList.emplace_back( _( "Reference" ), GetRef( currentSheet ) );
  1583. // Don't use GetShownText(); we want to see the variable references here
  1584. aList.emplace_back( _( "Value" ),
  1585. KIUI::EllipsizeStatusText( aFrame, GetField( FIELD_T::VALUE )->GetText() ) );
  1586. addExcludes();
  1587. aList.emplace_back( _( "Name" ),
  1588. KIUI::EllipsizeStatusText( aFrame, GetLibId().GetLibItemName() ) );
  1589. wxString libNickname = GetLibId().GetLibNickname();
  1590. if( libNickname.empty() )
  1591. msg = _( "No library defined!" );
  1592. else
  1593. msg.Printf( _( "Symbol not found in %s!" ), libNickname );
  1594. aList.emplace_back( _( "Library" ), msg );
  1595. }
  1596. }
  1597. BITMAPS SCH_SYMBOL::GetMenuImage() const
  1598. {
  1599. return BITMAPS::add_component;
  1600. }
  1601. EMBEDDED_FILES* SCH_SYMBOL::GetEmbeddedFiles()
  1602. {
  1603. return GetLibSymbolRef()->GetEmbeddedFiles();
  1604. }
  1605. void SCH_SYMBOL::MirrorHorizontally( int aCenter )
  1606. {
  1607. int dx = m_pos.x;
  1608. SetOrientation( SYM_MIRROR_Y );
  1609. MIRROR( m_pos.x, aCenter );
  1610. dx -= m_pos.x; // dx,0 is the move vector for this transform
  1611. for( SCH_FIELD& field : m_fields )
  1612. {
  1613. // Move the fields to the new position because the symbol itself has moved.
  1614. VECTOR2I pos = field.GetTextPos();
  1615. pos.x -= dx;
  1616. field.SetTextPos( pos );
  1617. }
  1618. }
  1619. void SCH_SYMBOL::MirrorVertically( int aCenter )
  1620. {
  1621. int dy = m_pos.y;
  1622. SetOrientation( SYM_MIRROR_X );
  1623. MIRROR( m_pos.y, aCenter );
  1624. dy -= m_pos.y; // 0,dy is the move vector for this transform
  1625. for( SCH_FIELD& field : m_fields )
  1626. {
  1627. // Move the fields to the new position because the symbol itself has moved.
  1628. VECTOR2I pos = field.GetTextPos();
  1629. pos.y -= dy;
  1630. field.SetTextPos( pos );
  1631. }
  1632. }
  1633. void SCH_SYMBOL::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
  1634. {
  1635. VECTOR2I prev = m_pos;
  1636. RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
  1637. SetOrientation( aRotateCCW ? SYM_ROTATE_COUNTERCLOCKWISE : SYM_ROTATE_CLOCKWISE );
  1638. for( SCH_FIELD& field : m_fields )
  1639. {
  1640. // Move the fields to the new position because the symbol itself has moved.
  1641. VECTOR2I pos = field.GetTextPos();
  1642. pos.x -= prev.x - m_pos.x;
  1643. pos.y -= prev.y - m_pos.y;
  1644. field.SetTextPos( pos );
  1645. }
  1646. }
  1647. bool SCH_SYMBOL::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
  1648. {
  1649. if( aSearchData.searchMetadata )
  1650. {
  1651. if( EDA_ITEM::Matches( GetSchSymbolLibraryName(), aSearchData ) )
  1652. return true;
  1653. if( EDA_ITEM::Matches( GetDescription(), aSearchData ) )
  1654. return true;
  1655. if( EDA_ITEM::Matches( GetKeyWords(), aSearchData ) )
  1656. return true;
  1657. }
  1658. for( SCH_ITEM& drawItem : GetLibSymbolRef()->GetDrawItems() )
  1659. {
  1660. if( drawItem.Matches( aSearchData, aAuxData ) )
  1661. return true;
  1662. }
  1663. // Symbols are searchable via the child field and pin item text.
  1664. return false;
  1665. }
  1666. void SCH_SYMBOL::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
  1667. {
  1668. for( std::unique_ptr<SCH_PIN>& pin : m_pins )
  1669. {
  1670. SCH_PIN* lib_pin = pin->GetLibPin();
  1671. if( lib_pin && lib_pin->GetUnit() && m_unit && ( m_unit != lib_pin->GetUnit() ) )
  1672. continue;
  1673. DANGLING_END_ITEM item( PIN_END, lib_pin, GetPinPhysicalPosition( lib_pin ), this );
  1674. aItemList.push_back( item );
  1675. }
  1676. }
  1677. bool SCH_SYMBOL::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
  1678. std::vector<DANGLING_END_ITEM>& aItemListByPos,
  1679. const SCH_SHEET_PATH* aPath )
  1680. {
  1681. bool changed = false;
  1682. for( std::unique_ptr<SCH_PIN>& pin : m_pins )
  1683. {
  1684. bool previousState = pin->IsDangling();
  1685. pin->SetIsDangling( true );
  1686. VECTOR2I pos = m_transform.TransformCoordinate( pin->GetLocalPosition() ) + m_pos;
  1687. auto lower = DANGLING_END_ITEM_HELPER::get_lower_pos( aItemListByPos, pos );
  1688. bool do_break = false;
  1689. for( auto it = lower; it < aItemListByPos.end() && it->GetPosition() == pos; it++ )
  1690. {
  1691. DANGLING_END_ITEM& each_item = *it;
  1692. // Some people like to stack pins on top of each other in a symbol to indicate
  1693. // internal connection. While technically connected, it is not particularly useful
  1694. // to display them that way, so skip any pins that are in the same symbol as this
  1695. // one.
  1696. if( each_item.GetParent() == this )
  1697. continue;
  1698. switch( each_item.GetType() )
  1699. {
  1700. case PIN_END:
  1701. case LABEL_END:
  1702. case SHEET_LABEL_END:
  1703. case WIRE_END:
  1704. case NO_CONNECT_END:
  1705. case JUNCTION_END:
  1706. pin->SetIsDangling( false );
  1707. do_break = true;
  1708. break;
  1709. default:
  1710. break;
  1711. }
  1712. if( do_break )
  1713. break;
  1714. }
  1715. changed = ( changed || ( previousState != pin->IsDangling() ) );
  1716. }
  1717. return changed;
  1718. }
  1719. VECTOR2I SCH_SYMBOL::GetPinPhysicalPosition( const SCH_PIN* aPin ) const
  1720. {
  1721. if( ( aPin == nullptr ) || ( aPin->Type() != SCH_PIN_T ) )
  1722. return VECTOR2I( 0, 0 );
  1723. return m_transform.TransformCoordinate( aPin->GetPosition() ) + m_pos;
  1724. }
  1725. bool SCH_SYMBOL::HasConnectivityChanges( const SCH_ITEM* aItem,
  1726. const SCH_SHEET_PATH* aInstance ) const
  1727. {
  1728. // Do not compare to ourself.
  1729. if( aItem == this )
  1730. return false;
  1731. const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( aItem );
  1732. // Don't compare against a different SCH_ITEM.
  1733. wxCHECK( symbol, false );
  1734. // The move algorithm marks any pins that are being moved without something attached
  1735. // (during the move) as dangling. We always need to recheck connectivity in this case
  1736. // or we will not notice changes when the user places the symbol back in the same position
  1737. // it started.
  1738. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  1739. {
  1740. if( pin->IsDangling() )
  1741. return true;
  1742. }
  1743. if( GetPosition() != symbol->GetPosition() )
  1744. return true;
  1745. if( GetLibId() != symbol->GetLibId() )
  1746. return true;
  1747. if( GetUnitSelection( aInstance ) != symbol->GetUnitSelection( aInstance ) )
  1748. return true;
  1749. if( GetRef( aInstance ) != symbol->GetRef( aInstance ) )
  1750. return true;
  1751. // Power symbol value field changes are connectivity changes.
  1752. if( IsPower()
  1753. && ( GetValue( true, aInstance, false ) != symbol->GetValue( true, aInstance, false ) ) )
  1754. return true;
  1755. if( m_pins.size() != symbol->m_pins.size() )
  1756. return true;
  1757. for( size_t i = 0; i < m_pins.size(); i++ )
  1758. {
  1759. if( m_pins[i]->HasConnectivityChanges( symbol->m_pins[i].get() ) )
  1760. return true;
  1761. }
  1762. return false;
  1763. }
  1764. std::vector<VECTOR2I> SCH_SYMBOL::GetConnectionPoints() const
  1765. {
  1766. std::vector<VECTOR2I> retval;
  1767. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  1768. {
  1769. // Collect only pins attached to the current unit and convert.
  1770. // others are not associated to this symbol instance
  1771. int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
  1772. : GetUnit();
  1773. int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
  1774. : GetBodyStyle();
  1775. if( pin_unit > 0 && pin_unit != GetUnit() )
  1776. continue;
  1777. if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
  1778. continue;
  1779. retval.push_back( m_transform.TransformCoordinate( pin->GetLocalPosition() ) + m_pos );
  1780. }
  1781. return retval;
  1782. }
  1783. SCH_ITEM* SCH_SYMBOL::GetDrawItem( const VECTOR2I& aPosition, KICAD_T aType )
  1784. {
  1785. if( m_part )
  1786. {
  1787. // Calculate the position relative to the symbol.
  1788. VECTOR2I libPosition = aPosition - m_pos;
  1789. return m_part->LocateDrawItem( m_unit, m_bodyStyle, aType, libPosition, m_transform );
  1790. }
  1791. return nullptr;
  1792. }
  1793. wxString SCH_SYMBOL::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
  1794. {
  1795. return wxString::Format( _( "Symbol %s [%s]" ),
  1796. KIUI::EllipsizeMenuText( GetField( FIELD_T::REFERENCE )->GetText() ),
  1797. KIUI::EllipsizeMenuText( GetLibId().GetLibItemName() ) );
  1798. }
  1799. INSPECT_RESULT SCH_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData,
  1800. const std::vector<KICAD_T>& aScanTypes )
  1801. {
  1802. for( KICAD_T scanType : aScanTypes )
  1803. {
  1804. if( scanType == SCH_LOCATE_ANY_T || ( scanType == SCH_SYMBOL_T )
  1805. || ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
  1806. {
  1807. if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) )
  1808. return INSPECT_RESULT::QUIT;
  1809. }
  1810. if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_FIELD_T )
  1811. {
  1812. for( SCH_FIELD& field : m_fields )
  1813. {
  1814. if( INSPECT_RESULT::QUIT == aInspector( &field, (void*) this ) )
  1815. return INSPECT_RESULT::QUIT;
  1816. }
  1817. }
  1818. if( scanType == SCH_FIELD_LOCATE_REFERENCE_T )
  1819. {
  1820. if( INSPECT_RESULT::QUIT == aInspector( GetField( FIELD_T::REFERENCE ), (void*) this ) )
  1821. return INSPECT_RESULT::QUIT;
  1822. }
  1823. if( scanType == SCH_FIELD_LOCATE_VALUE_T
  1824. || ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
  1825. {
  1826. if( INSPECT_RESULT::QUIT == aInspector( GetField( FIELD_T::VALUE ), (void*) this ) )
  1827. return INSPECT_RESULT::QUIT;
  1828. }
  1829. if( scanType == SCH_FIELD_LOCATE_FOOTPRINT_T )
  1830. {
  1831. if( INSPECT_RESULT::QUIT == aInspector( GetField( FIELD_T::FOOTPRINT ), (void*) this ) )
  1832. return INSPECT_RESULT::QUIT;
  1833. }
  1834. if( scanType == SCH_FIELD_LOCATE_DATASHEET_T )
  1835. {
  1836. if( INSPECT_RESULT::QUIT == aInspector( GetField( FIELD_T::DATASHEET ), (void*) this ) )
  1837. return INSPECT_RESULT::QUIT;
  1838. }
  1839. if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_PIN_T )
  1840. {
  1841. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  1842. {
  1843. // Collect only pins attached to the current unit and convert.
  1844. // others are not associated to this symbol instance
  1845. int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
  1846. : GetUnit();
  1847. int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
  1848. : GetBodyStyle();
  1849. if( pin_unit > 0 && pin_unit != GetUnit() )
  1850. continue;
  1851. if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
  1852. continue;
  1853. if( INSPECT_RESULT::QUIT == aInspector( pin.get(), (void*) this ) )
  1854. return INSPECT_RESULT::QUIT;
  1855. }
  1856. }
  1857. }
  1858. return INSPECT_RESULT::CONTINUE;
  1859. }
  1860. bool SCH_SYMBOL::operator <( const SCH_ITEM& aItem ) const
  1861. {
  1862. if( Type() != aItem.Type() )
  1863. return Type() < aItem.Type();
  1864. const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( &aItem );
  1865. BOX2I rect = GetBodyAndPinsBoundingBox();
  1866. if( rect.GetArea() != symbol->GetBodyAndPinsBoundingBox().GetArea() )
  1867. return rect.GetArea() < symbol->GetBodyAndPinsBoundingBox().GetArea();
  1868. if( m_pos.x != symbol->m_pos.x )
  1869. return m_pos.x < symbol->m_pos.x;
  1870. if( m_pos.y != symbol->m_pos.y )
  1871. return m_pos.y < symbol->m_pos.y;
  1872. return m_Uuid < aItem.m_Uuid; // Ensure deterministic sort
  1873. }
  1874. bool SCH_SYMBOL::operator==( const SCH_SYMBOL& aSymbol ) const
  1875. {
  1876. std::vector<SCH_FIELD*> fields, otherFields;
  1877. GetFields( fields, false );
  1878. aSymbol.GetFields( otherFields, false );
  1879. if( fields.size() != otherFields.size() )
  1880. return false;
  1881. for( int ii = 0; ii < (int) fields.size(); ii++ )
  1882. {
  1883. if( fields[ii]->GetId() == FIELD_T::REFERENCE )
  1884. continue;
  1885. if( fields[ii]->GetText().Cmp( otherFields[ii]->GetText() ) != 0 )
  1886. return false;
  1887. }
  1888. return true;
  1889. }
  1890. bool SCH_SYMBOL::operator!=( const SCH_SYMBOL& aSymbol ) const
  1891. {
  1892. return !( *this == aSymbol );
  1893. }
  1894. SCH_SYMBOL& SCH_SYMBOL::operator=( const SCH_SYMBOL& aSymbol )
  1895. {
  1896. wxCHECK_MSG( Type() == aSymbol.Type(), *this,
  1897. wxT( "Cannot assign object type " ) + aSymbol.GetClass() + wxT( " to type " ) +
  1898. GetClass() );
  1899. if( &aSymbol != this )
  1900. {
  1901. SYMBOL::operator=( aSymbol );
  1902. m_lib_id = aSymbol.m_lib_id;
  1903. m_part.reset( aSymbol.m_part ? new LIB_SYMBOL( *aSymbol.m_part ) : nullptr );
  1904. m_pos = aSymbol.m_pos;
  1905. m_unit = aSymbol.m_unit;
  1906. m_bodyStyle = aSymbol.m_bodyStyle;
  1907. m_transform = aSymbol.m_transform;
  1908. m_instanceReferences = aSymbol.m_instanceReferences;
  1909. m_fields = aSymbol.m_fields; // std::vector's assignment operator
  1910. // Reparent fields after assignment to new symbol.
  1911. for( SCH_FIELD& field : m_fields )
  1912. field.SetParent( this );
  1913. UpdatePins();
  1914. }
  1915. return *this;
  1916. }
  1917. bool SCH_SYMBOL::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
  1918. {
  1919. BOX2I bBox = GetBodyBoundingBox();
  1920. bBox.Inflate( aAccuracy / 2 );
  1921. if( bBox.Contains( aPosition ) )
  1922. return true;
  1923. return false;
  1924. }
  1925. bool SCH_SYMBOL::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
  1926. {
  1927. if( m_flags & STRUCT_DELETED || m_flags & SKIP_STRUCT )
  1928. return false;
  1929. BOX2I rect = aRect;
  1930. rect.Inflate( aAccuracy / 2 );
  1931. if( aContained )
  1932. return rect.Contains( GetBodyBoundingBox() );
  1933. return rect.Intersects( GetBodyBoundingBox() );
  1934. }
  1935. bool SCH_SYMBOL::doIsConnected( const VECTOR2I& aPosition ) const
  1936. {
  1937. VECTOR2I new_pos = m_transform.InverseTransform().TransformCoordinate( aPosition - m_pos );
  1938. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  1939. {
  1940. if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
  1941. continue;
  1942. // Collect only pins attached to the current unit and convert.
  1943. // others are not associated to this symbol instance
  1944. int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
  1945. : GetUnit();
  1946. int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
  1947. : GetBodyStyle();
  1948. if( pin_unit > 0 && pin_unit != GetUnit() )
  1949. continue;
  1950. if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
  1951. continue;
  1952. if( pin->GetLocalPosition() == new_pos )
  1953. return true;
  1954. }
  1955. return false;
  1956. }
  1957. bool SCH_SYMBOL::IsInNetlist() const
  1958. {
  1959. return m_isInNetlist;
  1960. }
  1961. void SCH_SYMBOL::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
  1962. int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
  1963. {
  1964. if( aBackground )
  1965. return;
  1966. if( m_part )
  1967. {
  1968. std::vector<SCH_PIN*> libPins = m_part->GetPins( GetUnit(), GetBodyStyle() );
  1969. // Copy the source so we can re-orient and translate it.
  1970. LIB_SYMBOL tempSymbol( *m_part );
  1971. std::vector<SCH_PIN*> tempPins = tempSymbol.GetPins( GetUnit(), GetBodyStyle() );
  1972. // Copy the pin info from the symbol to the temp pins
  1973. for( unsigned i = 0; i < tempPins.size(); ++ i )
  1974. {
  1975. SCH_PIN* symbolPin = GetPin( libPins[ i ] );
  1976. SCH_PIN* tempPin = tempPins[ i ];
  1977. tempPin->SetName( symbolPin->GetShownName() );
  1978. tempPin->SetType( symbolPin->GetType() );
  1979. tempPin->SetShape( symbolPin->GetShape() );
  1980. if( symbolPin->IsDangling() )
  1981. tempPin->SetFlags( IS_DANGLING );
  1982. }
  1983. for( SCH_ITEM& item : tempSymbol.GetDrawItems() )
  1984. {
  1985. if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( &item ) )
  1986. {
  1987. // Use SCH_FIELD's text resolver
  1988. SCH_FIELD dummy( this, FIELD_T::USER );
  1989. dummy.SetText( text->GetText() );
  1990. text->SetText( dummy.GetShownText( false ) );
  1991. }
  1992. }
  1993. SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
  1994. TRANSFORM savedTransform = renderSettings->m_Transform;
  1995. renderSettings->m_Transform = GetTransform();
  1996. aPlotter->StartBlock( nullptr );
  1997. for( bool local_background : { true, false } )
  1998. {
  1999. tempSymbol.Plot( aPlotter, local_background, aPlotOpts, GetUnit(), GetBodyStyle(),
  2000. m_pos, GetDNP() );
  2001. for( SCH_FIELD field : m_fields )
  2002. {
  2003. field.ClearRenderCache();
  2004. field.Plot( aPlotter, local_background, aPlotOpts, GetUnit(), GetBodyStyle(),
  2005. m_pos, GetDNP() );
  2006. }
  2007. }
  2008. if( m_DNP )
  2009. PlotDNP( aPlotter );
  2010. SCH_SHEET_PATH* sheet = &Schematic()->CurrentSheet();
  2011. // Plot attributes to a hypertext menu
  2012. if( aPlotOpts.m_PDFPropertyPopups )
  2013. {
  2014. std::vector<wxString> properties;
  2015. for( const SCH_FIELD& field : GetFields() )
  2016. {
  2017. wxString text_field = field.GetShownText( sheet, false);
  2018. if( text_field.IsEmpty() )
  2019. continue;
  2020. properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
  2021. field.GetName(), text_field ) );
  2022. }
  2023. if( !m_part->GetKeyWords().IsEmpty() )
  2024. {
  2025. properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
  2026. _( "Keywords" ),
  2027. m_part->GetKeyWords() ) );
  2028. }
  2029. aPlotter->HyperlinkMenu( GetBoundingBox(), properties );
  2030. }
  2031. aPlotter->EndBlock( nullptr );
  2032. renderSettings->m_Transform = savedTransform;
  2033. if( !m_part->IsPower() )
  2034. aPlotter->Bookmark( GetBoundingBox(), GetRef( sheet ), _( "Symbols" ) );
  2035. }
  2036. }
  2037. void SCH_SYMBOL::PlotDNP( PLOTTER* aPlotter ) const
  2038. {
  2039. BOX2I bbox = GetBodyBoundingBox();
  2040. BOX2I pins = GetBodyAndPinsBoundingBox();
  2041. VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(),
  2042. pins.GetEnd().x - bbox.GetEnd().x ),
  2043. std::max( bbox.GetY() - pins.GetY(),
  2044. pins.GetEnd().y - bbox.GetEnd().y ) );
  2045. int strokeWidth = 3.0 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
  2046. margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
  2047. margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
  2048. bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
  2049. SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
  2050. aPlotter->SetColor( renderSettings->GetLayerColor( LAYER_DNP_MARKER ) );
  2051. aPlotter->ThickSegment( bbox.GetOrigin(), bbox.GetEnd(), strokeWidth, nullptr );
  2052. aPlotter->ThickSegment( bbox.GetOrigin() + VECTOR2I( bbox.GetWidth(), 0 ),
  2053. bbox.GetOrigin() + VECTOR2I( 0, bbox.GetHeight() ),
  2054. strokeWidth, nullptr );
  2055. }
  2056. void SCH_SYMBOL::PlotPins( PLOTTER* aPlotter ) const
  2057. {
  2058. if( m_part )
  2059. {
  2060. SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
  2061. TRANSFORM savedTransform = renderSettings->m_Transform;
  2062. renderSettings->m_Transform = GetTransform();
  2063. std::vector<SCH_PIN*> libPins = m_part->GetPins( GetUnit(), GetBodyStyle() );
  2064. // Copy the source to stay const
  2065. LIB_SYMBOL tempSymbol( *m_part );
  2066. std::vector<SCH_PIN*> tempPins = tempSymbol.GetPins( GetUnit(), GetBodyStyle() );
  2067. SCH_PLOT_OPTS plotOpts;
  2068. // Copy the pin info from the symbol to the temp pins
  2069. for( unsigned i = 0; i < tempPins.size(); ++ i )
  2070. {
  2071. SCH_PIN* symbolPin = GetPin( libPins[ i ] );
  2072. SCH_PIN* tempPin = tempPins[ i ];
  2073. tempPin->SetName( symbolPin->GetShownName() );
  2074. tempPin->SetType( symbolPin->GetType() );
  2075. tempPin->SetShape( symbolPin->GetShape() );
  2076. tempPin->Plot( aPlotter, false, plotOpts, GetUnit(), GetBodyStyle(), m_pos, GetDNP() );
  2077. }
  2078. renderSettings->m_Transform = savedTransform;
  2079. }
  2080. }
  2081. bool SCH_SYMBOL::HasBrightenedPins()
  2082. {
  2083. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  2084. {
  2085. if( pin->IsBrightened() )
  2086. return true;
  2087. }
  2088. return false;
  2089. }
  2090. void SCH_SYMBOL::ClearBrightenedPins()
  2091. {
  2092. for( std::unique_ptr<SCH_PIN>& pin : m_pins )
  2093. pin->ClearBrightened();
  2094. }
  2095. /*
  2096. * When modified at the schematic level, we still store the values of these flags in the
  2097. * associated m_part. If m_part now diverges from other usages, a new derived LIB_SYMBOL
  2098. * will be created and stored locally in the schematic.
  2099. */
  2100. bool SCH_SYMBOL::GetShowPinNames() const
  2101. {
  2102. return m_part && m_part->GetShowPinNames();
  2103. }
  2104. void SCH_SYMBOL::SetShowPinNames( bool aShow )
  2105. {
  2106. if( m_part )
  2107. m_part->SetShowPinNames( aShow );
  2108. }
  2109. bool SCH_SYMBOL::GetShowPinNumbers() const
  2110. {
  2111. return m_part && m_part->GetShowPinNumbers();
  2112. }
  2113. void SCH_SYMBOL::SetShowPinNumbers( bool aShow )
  2114. {
  2115. if( m_part )
  2116. m_part->SetShowPinNumbers( aShow );
  2117. }
  2118. bool SCH_SYMBOL::IsPointClickableAnchor( const VECTOR2I& aPos ) const
  2119. {
  2120. for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
  2121. {
  2122. int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
  2123. : GetUnit();
  2124. int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
  2125. : GetBodyStyle();
  2126. if( pin_unit > 0 && pin_unit != GetUnit() )
  2127. continue;
  2128. if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
  2129. continue;
  2130. if( pin->IsPointClickableAnchor( aPos ) )
  2131. return true;
  2132. }
  2133. return false;
  2134. }
  2135. bool SCH_SYMBOL::IsSymbolLikePowerGlobalLabel() const
  2136. {
  2137. // return true if the symbol is equivalent to a global label:
  2138. // It is a Power symbol
  2139. // It has only one pin type Power input
  2140. if( !GetLibSymbolRef() || !GetLibSymbolRef()->IsGlobalPower() )
  2141. return false;
  2142. std::vector<SCH_PIN*> pin_list = GetAllLibPins();
  2143. if( pin_list.size() != 1 )
  2144. return false;
  2145. return pin_list[0]->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN;
  2146. }
  2147. bool SCH_SYMBOL::IsSymbolLikePowerLocalLabel() const
  2148. {
  2149. // return true if the symbol is equivalent to a local label:
  2150. // It is a Power symbol
  2151. // It has only one pin type Power input
  2152. if( !GetLibSymbolRef() || !GetLibSymbolRef()->IsLocalPower() )
  2153. return false;
  2154. std::vector<SCH_PIN*> pin_list = GetAllLibPins();
  2155. if( pin_list.size() != 1 )
  2156. return false;
  2157. return pin_list[0]->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN;
  2158. }
  2159. bool SCH_SYMBOL::IsLocalPower() const
  2160. {
  2161. if( !m_part )
  2162. return false;
  2163. return m_part->IsLocalPower();
  2164. }
  2165. bool SCH_SYMBOL::IsGlobalPower() const
  2166. {
  2167. if( !m_part )
  2168. return false;
  2169. return m_part->IsGlobalPower();
  2170. }
  2171. bool SCH_SYMBOL::IsPower() const
  2172. {
  2173. return IsLocalPower() || IsGlobalPower();
  2174. }
  2175. bool SCH_SYMBOL::IsNormal() const
  2176. {
  2177. wxCHECK( m_part, false );
  2178. return m_part->IsNormal();
  2179. }
  2180. std::unordered_set<wxString> SCH_SYMBOL::GetComponentClassNames( const SCH_SHEET_PATH* aPath ) const
  2181. {
  2182. std::unordered_set<wxString> componentClass;
  2183. auto getComponentClassFields =
  2184. [&]( const std::vector<SCH_FIELD>& fields )
  2185. {
  2186. for( const SCH_FIELD& field : fields )
  2187. {
  2188. if( field.GetCanonicalName() == wxT( "Component Class" ) )
  2189. {
  2190. if( field.GetShownText( aPath, false ) != wxEmptyString )
  2191. componentClass.insert( field.GetShownText( aPath, false ) );
  2192. }
  2193. }
  2194. };
  2195. // First get component classes set on the symbol itself
  2196. getComponentClassFields( m_fields );
  2197. // Now get component classes set on any enclosing rule areas
  2198. for( const SCH_RULE_AREA* ruleArea : m_rule_areas_cache )
  2199. {
  2200. for( const SCH_DIRECTIVE_LABEL* label : ruleArea->GetDirectives() )
  2201. {
  2202. getComponentClassFields( label->GetFields() );
  2203. }
  2204. }
  2205. return componentClass;
  2206. }
  2207. bool SCH_SYMBOL::operator==( const SCH_ITEM& aOther ) const
  2208. {
  2209. if( Type() != aOther.Type() )
  2210. return false;
  2211. const SCH_SYMBOL& symbol = static_cast<const SCH_SYMBOL&>( aOther );
  2212. if( GetLibId() != symbol.GetLibId() )
  2213. return false;
  2214. if( GetPosition() != symbol.GetPosition() )
  2215. return false;
  2216. if( GetUnit() != symbol.GetUnit() )
  2217. return false;
  2218. if( GetBodyStyle() != symbol.GetBodyStyle() )
  2219. return false;
  2220. if( GetTransform() != symbol.GetTransform() )
  2221. return false;
  2222. if( GetFields() != symbol.GetFields() )
  2223. return false;
  2224. if( m_pins.size() != symbol.m_pins.size() )
  2225. return false;
  2226. for( unsigned i = 0; i < m_pins.size(); ++i )
  2227. {
  2228. if( *m_pins[i] != *symbol.m_pins[i] )
  2229. return false;
  2230. }
  2231. return true;
  2232. }
  2233. double SCH_SYMBOL::Similarity( const SCH_ITEM& aOther ) const
  2234. {
  2235. if( Type() != aOther.Type() )
  2236. return 0.0;
  2237. const SCH_SYMBOL& symbol = static_cast<const SCH_SYMBOL&>( aOther );
  2238. if( GetLibId() != symbol.GetLibId() )
  2239. return 0.0;
  2240. if( GetPosition() == symbol.GetPosition() )
  2241. return 1.0;
  2242. return 0.0;
  2243. }
  2244. static struct SCH_SYMBOL_DESC
  2245. {
  2246. SCH_SYMBOL_DESC()
  2247. {
  2248. ENUM_MAP<SYMBOL_ORIENTATION_PROP>::Instance()
  2249. .Map( SYMBOL_ANGLE_0, wxS( "0" ) )
  2250. .Map( SYMBOL_ANGLE_90, wxS( "90" ) )
  2251. .Map( SYMBOL_ANGLE_180, wxS( "180" ) )
  2252. .Map( SYMBOL_ANGLE_270, wxS( "270" ) );
  2253. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  2254. REGISTER_TYPE( SCH_SYMBOL );
  2255. propMgr.InheritsAfter( TYPE_HASH( SCH_SYMBOL ), TYPE_HASH( SYMBOL ) );
  2256. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Position X" ),
  2257. &SCH_SYMBOL::SetX, &SCH_SYMBOL::GetX, PROPERTY_DISPLAY::PT_COORD,
  2258. ORIGIN_TRANSFORMS::ABS_X_COORD ) );
  2259. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Position Y" ),
  2260. &SCH_SYMBOL::SetY, &SCH_SYMBOL::GetY, PROPERTY_DISPLAY::PT_COORD,
  2261. ORIGIN_TRANSFORMS::ABS_Y_COORD ) );
  2262. propMgr.AddProperty( new PROPERTY_ENUM<SCH_SYMBOL, SYMBOL_ORIENTATION_PROP>(
  2263. _HKI( "Orientation" ),
  2264. &SCH_SYMBOL::SetOrientationProp, &SCH_SYMBOL::GetOrientationProp ) );
  2265. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Mirror X" ),
  2266. &SCH_SYMBOL::SetMirrorX, &SCH_SYMBOL::GetMirrorX ) );
  2267. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Mirror Y" ),
  2268. &SCH_SYMBOL::SetMirrorY, &SCH_SYMBOL::GetMirrorY ) );
  2269. auto hasLibPart =
  2270. []( INSPECTABLE* aItem ) -> bool
  2271. {
  2272. if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
  2273. return symbol->GetLibSymbolRef() != nullptr;
  2274. return false;
  2275. };
  2276. propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Pin numbers" ),
  2277. &SYMBOL::SetShowPinNumbers, &SYMBOL::GetShowPinNumbers ) )
  2278. .SetAvailableFunc( hasLibPart );
  2279. propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Pin names" ),
  2280. &SYMBOL::SetShowPinNames, &SYMBOL::GetShowPinNames ) )
  2281. .SetAvailableFunc( hasLibPart );
  2282. const wxString groupFields = _HKI( "Fields" );
  2283. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Reference" ),
  2284. &SCH_SYMBOL::SetRefProp, &SCH_SYMBOL::GetRefProp ),
  2285. groupFields );
  2286. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Value" ),
  2287. &SCH_SYMBOL::SetValueProp, &SCH_SYMBOL::GetValueProp ),
  2288. groupFields );
  2289. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Library Link" ),
  2290. NO_SETTER( SCH_SYMBOL, wxString ), &SCH_SYMBOL::GetSymbolIDAsString ),
  2291. groupFields );
  2292. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Library Description" ),
  2293. NO_SETTER( SCH_SYMBOL, wxString ), &SCH_SYMBOL::GetDescription ),
  2294. groupFields );
  2295. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Keywords" ),
  2296. NO_SETTER( SCH_SYMBOL, wxString ), &SCH_SYMBOL::GetKeyWords ),
  2297. groupFields );
  2298. auto multiUnit =
  2299. [=]( INSPECTABLE* aItem ) -> bool
  2300. {
  2301. if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
  2302. return symbol->IsMulti();
  2303. return false;
  2304. };
  2305. auto multiBodyStyle =
  2306. [=]( INSPECTABLE* aItem ) -> bool
  2307. {
  2308. if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
  2309. return symbol->HasAlternateBodyStyle();
  2310. return false;
  2311. };
  2312. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Unit" ),
  2313. &SCH_SYMBOL::SetUnitProp, &SCH_SYMBOL::GetUnitProp ) )
  2314. .SetAvailableFunc( multiUnit );
  2315. propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Body Style" ),
  2316. &SCH_SYMBOL::SetBodyStyleProp, &SCH_SYMBOL::GetBodyStyleProp ) )
  2317. .SetAvailableFunc( multiBodyStyle );
  2318. const wxString groupAttributes = _HKI( "Attributes" );
  2319. propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Exclude From Board" ),
  2320. &SYMBOL::SetExcludedFromBoard, &SYMBOL::GetExcludedFromBoard ),
  2321. groupAttributes );
  2322. propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Exclude From Simulation" ),
  2323. &SYMBOL::SetExcludedFromSim, &SYMBOL::GetExcludedFromSim ),
  2324. groupAttributes );
  2325. propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Exclude From Bill of Materials" ),
  2326. &SYMBOL::SetExcludedFromBOM, &SYMBOL::GetExcludedFromBOM ),
  2327. groupAttributes );
  2328. propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Do not Populate" ),
  2329. &SYMBOL::SetDNP, &SYMBOL::GetDNP ),
  2330. groupAttributes );
  2331. }
  2332. } _SCH_SYMBOL_DESC;
  2333. ENUM_TO_WXANY( SYMBOL_ORIENTATION_PROP )