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.

177 lines
7.0 KiB

  1. #ifndef _SCH_LEGACY_PLUGIN_H_
  2. #define _SCH_LEGACY_PLUGIN_H_
  3. /*
  4. * This program source code file is part of KiCad, a free EDA CAD application.
  5. *
  6. * Copyright (C) 2016 CERN
  7. * Copyright (C) 2016-2017 KiCad Developers, see change_log.txt for contributors.
  8. *
  9. * @author Wayne Stambaugh <stambaughw@gmail.com>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #include <sch_io_mgr.h>
  25. #include <stack>
  26. class KIWAY;
  27. class LINE_READER;
  28. class SCH_SCREEN;
  29. class SCH_SHEET;
  30. class SCH_BITMAP;
  31. class SCH_JUNCTION;
  32. class SCH_NO_CONNECT;
  33. class SCH_LINE;
  34. class SCH_BUS_ENTRY_BASE;
  35. class SCH_TEXT;
  36. class SCH_COMPONENT;
  37. class SCH_FIELD;
  38. class PROPERTIES;
  39. class SCH_LEGACY_PLUGIN_CACHE;
  40. class LIB_PART;
  41. class PART_LIB;
  42. class LIB_ALIAS;
  43. /**
  44. * A #SCH_PLUGIN derivation for loading schematic files created before the new s-expression
  45. * file format.
  46. *
  47. * The legacy parser and formatter attempt to be compatible with the legacy file format.
  48. * The original parser was very forgiving in that it would parse only part of a keyword.
  49. * So "$C", "$Co", and "$Com" could be used for "$Comp" and the old parser would allow
  50. * this. This parser is not that forgiving and sticks to the legacy file format document.
  51. *
  52. * As with all SCH_PLUGINs there is no UI dependencies i.e. windowing calls allowed.
  53. */
  54. class SCH_LEGACY_PLUGIN : public SCH_PLUGIN
  55. {
  56. public:
  57. SCH_LEGACY_PLUGIN();
  58. virtual ~SCH_LEGACY_PLUGIN();
  59. const wxString GetName() const override
  60. {
  61. return wxT( "Eeschema-Legacy" );
  62. }
  63. const wxString GetFileExtension() const override
  64. {
  65. return wxT( "sch" );
  66. }
  67. /**
  68. * const char* PropBuffering
  69. *
  70. * is a property used internally by the plugin to enable cache buffering which prevents
  71. * the library file from being written every time the cache is changed. This is useful
  72. * when writing the schematic cache library file or saving a library to a new file name.
  73. */
  74. static const char* PropBuffering;
  75. /**
  76. * const char* PropBuffering
  77. *
  78. * is a property used internally by the plugin to disable writing the library
  79. * documentation (.dcm) file when saving the library cache.
  80. */
  81. static const char* PropNoDocFile;
  82. int GetModifyHash() const override;
  83. SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
  84. SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL ) override;
  85. void Save( const wxString& aFileName, SCH_SCREEN* aScreen, KIWAY* aKiway,
  86. const PROPERTIES* aProperties = NULL ) override;
  87. void Format( SCH_SCREEN* aScreen );
  88. size_t GetSymbolLibCount( const wxString& aLibraryPath,
  89. const PROPERTIES* aProperties = NULL ) override;
  90. void EnumerateSymbolLib( wxArrayString& aAliasNameList,
  91. const wxString& aLibraryPath,
  92. const PROPERTIES* aProperties = NULL ) override;
  93. void EnumerateSymbolLib( std::vector<LIB_ALIAS*>& aAliasList,
  94. const wxString& aLibraryPath,
  95. const PROPERTIES* aProperties = NULL ) override;
  96. LIB_ALIAS* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
  97. const PROPERTIES* aProperties = NULL ) override;
  98. void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
  99. const PROPERTIES* aProperties = NULL ) override;
  100. void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
  101. const PROPERTIES* aProperties = NULL ) override;
  102. void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
  103. const PROPERTIES* aProperties = NULL ) override;
  104. void CreateSymbolLib( const wxString& aLibraryPath,
  105. const PROPERTIES* aProperties = NULL ) override;
  106. bool DeleteSymbolLib( const wxString& aLibraryPath,
  107. const PROPERTIES* aProperties = NULL ) override;
  108. void SaveLibrary( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL ) override;
  109. bool CheckHeader( const wxString& aFileName ) override;
  110. bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
  111. const wxString& GetError() const override { return m_error; }
  112. private:
  113. void loadHierarchy( SCH_SHEET* aSheet );
  114. void loadHeader( FILE_LINE_READER& aReader, SCH_SCREEN* aScreen );
  115. void loadPageSettings( FILE_LINE_READER& aReader, SCH_SCREEN* aScreen );
  116. void loadFile( const wxString& aFileName, SCH_SCREEN* aScreen );
  117. SCH_SHEET* loadSheet( FILE_LINE_READER& aReader );
  118. SCH_BITMAP* loadBitmap( FILE_LINE_READER& aReader );
  119. SCH_JUNCTION* loadJunction( FILE_LINE_READER& aReader );
  120. SCH_NO_CONNECT* loadNoConnect( FILE_LINE_READER& aReader );
  121. SCH_LINE* loadWire( FILE_LINE_READER& aReader );
  122. SCH_BUS_ENTRY_BASE* loadBusEntry( FILE_LINE_READER& aReader );
  123. SCH_TEXT* loadText( FILE_LINE_READER& aReader );
  124. SCH_COMPONENT* loadComponent( FILE_LINE_READER& aReader );
  125. void saveComponent( SCH_COMPONENT* aComponent );
  126. void saveField( SCH_FIELD* aField );
  127. void saveBitmap( SCH_BITMAP* aBitmap );
  128. void saveSheet( SCH_SHEET* aSheet );
  129. void saveJunction( SCH_JUNCTION* aJunction );
  130. void saveNoConnect( SCH_NO_CONNECT* aNoConnect );
  131. void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry );
  132. void saveLine( SCH_LINE* aLine );
  133. void saveText( SCH_TEXT* aText );
  134. void cacheLib( const wxString& aLibraryFileName );
  135. bool writeDocFile( const PROPERTIES* aProperties );
  136. bool isBuffering( const PROPERTIES* aProperties );
  137. protected:
  138. int m_version; ///< Version of file being loaded.
  139. /** For throwing exceptions or errors on partial schematic loads. */
  140. wxString m_error;
  141. wxString m_path; ///< Root project path for loading child sheets.
  142. std::stack<wxString> m_currentPath; ///< Stack to maintain nested sheet paths
  143. const PROPERTIES* m_props; ///< Passed via Save() or Load(), no ownership, may be NULL.
  144. KIWAY* m_kiway; ///< Required for path to legacy component libraries.
  145. SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
  146. FILE_OUTPUTFORMATTER* m_out; ///< The output formatter for saving SCH_SCREEN objects.
  147. SCH_LEGACY_PLUGIN_CACHE* m_cache;
  148. /// initialize PLUGIN like a constructor would.
  149. void init( KIWAY* aKiway, const PROPERTIES* aProperties = NULL );
  150. };
  151. #endif // _SCH_LEGACY_PLUGIN_H_