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.

187 lines
5.7 KiB

Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 CERN
  5. * Copyright (C) 2016-2021 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * @author Wayne Stambaugh <stambaughw@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include <wx/filename.h>
  23. #include <wx/uri.h>
  24. #include <sch_io_mgr.h>
  25. #include <sch_plugins/legacy/sch_legacy_plugin.h>
  26. #include <sch_plugins/eagle/sch_eagle_plugin.h>
  27. #include <sch_plugins/kicad/sch_sexpr_plugin.h>
  28. #include <sch_plugins/altium/sch_altium_plugin.h>
  29. #include <sch_plugins/cadstar/cadstar_sch_archive_plugin.h>
  30. #include <wildcards_and_files_ext.h>
  31. #define FMT_UNIMPLEMENTED _( "Plugin \"%s\" does not implement the \"%s\" function." )
  32. #define FMT_NOTFOUND _( "Plugin type \"%s\" is not found." )
  33. // Some day plugins might be in separate DLL/DSOs, simply because of numbers of them
  34. // and code size. Until then, use the simplest method:
  35. // This implementation is one of two which could be done.
  36. // The other one would cater to DLL/DSO's. But since it would be nearly
  37. // impossible to link a KICAD type DLL/DSO right now without pulling in all
  38. // ::Draw() functions, I forgo that option temporarily.
  39. // Some day it may be possible to have some built in AND some DLL/DSO
  40. // plugins coexisting.
  41. SCH_PLUGIN* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType )
  42. {
  43. // This implementation is subject to change, any magic is allowed here.
  44. // The public SCH_IO_MGR API is the only pertinent public information.
  45. switch( aFileType )
  46. {
  47. case SCH_LEGACY: return new SCH_LEGACY_PLUGIN();
  48. case SCH_KICAD: return new SCH_SEXPR_PLUGIN();
  49. case SCH_ALTIUM: return new SCH_ALTIUM_PLUGIN();
  50. case SCH_CADSTAR_ARCHIVE: return new CADSTAR_SCH_ARCHIVE_PLUGIN();
  51. case SCH_EAGLE: return new SCH_EAGLE_PLUGIN();
  52. default: return nullptr;
  53. }
  54. }
  55. void SCH_IO_MGR::ReleasePlugin( SCH_PLUGIN* aPlugin )
  56. {
  57. // This function is a place holder for a future point in time where
  58. // the plugin is a DLL/DSO. It could do reference counting, and then
  59. // unload the DLL/DSO when count goes to zero.
  60. delete aPlugin;
  61. }
  62. const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType )
  63. {
  64. // keep this function in sync with EnumFromStr() relative to the
  65. // text spellings. If you change the spellings, you will obsolete
  66. // library tables, so don't do change, only additions are ok.
  67. switch( aType )
  68. {
  69. case SCH_LEGACY: return wxString( wxT( "Legacy" ) );
  70. case SCH_KICAD: return wxString( wxT( "KiCad" ) );
  71. case SCH_ALTIUM: return wxString( wxT( "Altium" ) );
  72. case SCH_CADSTAR_ARCHIVE: return wxString( wxT( "CADSTAR Schematic Archive" ) );
  73. case SCH_EAGLE: return wxString( wxT( "EAGLE" ) );
  74. default: return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ),
  75. aType );
  76. }
  77. }
  78. SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::EnumFromStr( const wxString& aType )
  79. {
  80. // keep this function in sync with ShowType() relative to the
  81. // text spellings. If you change the spellings, you will obsolete
  82. // library tables, so don't do change, only additions are ok.
  83. if( aType == wxT( "Legacy" ) )
  84. return SCH_LEGACY;
  85. else if( aType == wxT( "KiCad" ) )
  86. return SCH_KICAD;
  87. else if( aType == wxT( "Altium" ) )
  88. return SCH_ALTIUM;
  89. else if( aType == wxT( "CADSTAR Schematic Archive" ) )
  90. return SCH_CADSTAR_ARCHIVE;
  91. else if( aType == wxT( "EAGLE" ) )
  92. return SCH_EAGLE;
  93. // wxASSERT( blow up here )
  94. return SCH_FILE_T( -1 );
  95. }
  96. const wxString SCH_IO_MGR::GetFileExtension( SCH_FILE_T aFileType )
  97. {
  98. wxString ext = wxEmptyString;
  99. SCH_PLUGIN* plugin = FindPlugin( aFileType );
  100. if( plugin != nullptr )
  101. {
  102. ext = plugin->GetFileExtension();
  103. ReleasePlugin( plugin );
  104. }
  105. return ext;
  106. }
  107. const wxString SCH_IO_MGR::GetLibraryFileExtension( SCH_FILE_T aFileType )
  108. {
  109. wxString ext = wxEmptyString;
  110. SCH_PLUGIN* plugin = FindPlugin( aFileType );
  111. if( plugin != nullptr )
  112. {
  113. ext = plugin->GetLibraryFileExtension();
  114. ReleasePlugin( plugin );
  115. }
  116. return ext;
  117. }
  118. SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath )
  119. {
  120. SCH_FILE_T ret = SCH_KICAD; // default guess, unless detected otherwise.
  121. wxFileName fn( aLibPath );
  122. if( fn.GetExt() == LegacySymbolLibFileExtension )
  123. {
  124. ret = SCH_LEGACY;
  125. }
  126. else if( fn.GetExt() == KiCadSymbolLibFileExtension )
  127. {
  128. ret = SCH_KICAD;
  129. }
  130. return ret;
  131. }
  132. SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromSchPath( const wxString& aSchematicPath )
  133. {
  134. SCH_FILE_T ret = SCH_KICAD; // default guess, unless detected otherwise.
  135. wxFileName fn( aSchematicPath );
  136. if( fn.GetExt() == LegacySchematicFileExtension )
  137. {
  138. ret = SCH_LEGACY;
  139. }
  140. else if( fn.GetExt() == KiCadSchematicFileExtension )
  141. {
  142. ret = SCH_KICAD;
  143. }
  144. return ret;
  145. }
  146. DECLARE_ENUM_VECTOR( SCH_IO_MGR, SCH_FILE_T )