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.

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