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.

2747 lines
80 KiB

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