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.

1750 lines
60 KiB

Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 years ago
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
3 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
3 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
Mark null project initial screen as zoom-initialized The variable `m_Initialized` in `BASE_SCREEN` is used by `SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized by the "zoom to fit screen" action. When this variable is `false`, the function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit screen", modifying the zoom level. This function is indirectly called in the undo routines, so if `m_Initialized` is not set to `true`, a zoom change will occur when the user undoes an operation, a behavior that is undesired. `m_Initialized` was not initialized to `true` for the null schematic (the schematic that is loaded if no project is loaded), causing the aforementioned undesired behavior. To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set `m_Initialized` to `true`, since it zooms to fit screen already. I've moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used only in Eeschema, and renamed it to `m_zoomInitialized`, a name I believe that better describes what this variable does. I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to group the "zoom to fit screen" action with setting `m_Initialized` to `true`, as they often should occur together. I'd also like to say that I'm not confident whether `SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level initialization at this point, but I have decided to not change this behavior for now, as the commit history suggests it's several years old. Fixes https://gitlab.com/kicad/code/kicad/issues/7343
5 years ago
Use legacy schematic plugin for loading schematics in all code paths. Use the legacy plugin schematic loader in the sheet edit and append schematic code paths. Check for fully qualified LIB_ID objects (must have library nickname) when loading existing schematics when edit sheets. Rewrite append schematic feature to handle import issues rather than change the name and file name of all of the sheets in the imported schematic. This includes the following: - Load the schematic into a temporary SCH_SHEET object. - Make sure the imported schematic does not cause any hierarchy recursion issues. - Verify the imported schematic uses fully qualified #LIB_ID objects (symbol library table). - Check to see if any symbol libraries need to be added to the current project's symbol library table. This includes: - Check if the symbol library already exists in the project or global symbol library table. - Convert symbol library URLS that use the ${KIPRJMOD} environment variable to absolute paths. ${KIPRJMOD} will not be the same for this project. - Check for duplicate symbol library nicknames and change the new symbol library nickname to prevent library name clashes. - Update all schematic symbol LIB_ID object library nicknames when the library nickname was changed to prevent clashes. - Check for duplicate sheet names which is illegal and automatically rename any duplicate sheets in the imported schematic. - Clear all of the annotation in the imported schematic to prevent clashes. - Append the objects from the temporary sheet to the current page. - Replace any duplicate time stamps. - Refresh the symbol library links. Add support code to SCH_SCREEN object to assist with schematic import. Doxygen comment cleaning. Fixes lp:1731760 https://bugs.launchpad.net/kicad/+bug/1731760
8 years ago
Use legacy schematic plugin for loading schematics in all code paths. Use the legacy plugin schematic loader in the sheet edit and append schematic code paths. Check for fully qualified LIB_ID objects (must have library nickname) when loading existing schematics when edit sheets. Rewrite append schematic feature to handle import issues rather than change the name and file name of all of the sheets in the imported schematic. This includes the following: - Load the schematic into a temporary SCH_SHEET object. - Make sure the imported schematic does not cause any hierarchy recursion issues. - Verify the imported schematic uses fully qualified #LIB_ID objects (symbol library table). - Check to see if any symbol libraries need to be added to the current project's symbol library table. This includes: - Check if the symbol library already exists in the project or global symbol library table. - Convert symbol library URLS that use the ${KIPRJMOD} environment variable to absolute paths. ${KIPRJMOD} will not be the same for this project. - Check for duplicate symbol library nicknames and change the new symbol library nickname to prevent library name clashes. - Update all schematic symbol LIB_ID object library nicknames when the library nickname was changed to prevent clashes. - Check for duplicate sheet names which is illegal and automatically rename any duplicate sheets in the imported schematic. - Clear all of the annotation in the imported schematic to prevent clashes. - Append the objects from the temporary sheet to the current page. - Replace any duplicate time stamps. - Refresh the symbol library links. Add support code to SCH_SCREEN object to assist with schematic import. Doxygen comment cleaning. Fixes lp:1731760 https://bugs.launchpad.net/kicad/+bug/1731760
8 years ago
Mark null project initial screen as zoom-initialized The variable `m_Initialized` in `BASE_SCREEN` is used by `SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized by the "zoom to fit screen" action. When this variable is `false`, the function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit screen", modifying the zoom level. This function is indirectly called in the undo routines, so if `m_Initialized` is not set to `true`, a zoom change will occur when the user undoes an operation, a behavior that is undesired. `m_Initialized` was not initialized to `true` for the null schematic (the schematic that is loaded if no project is loaded), causing the aforementioned undesired behavior. To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set `m_Initialized` to `true`, since it zooms to fit screen already. I've moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used only in Eeschema, and renamed it to `m_zoomInitialized`, a name I believe that better describes what this variable does. I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to group the "zoom to fit screen" action with setting `m_Initialized` to `true`, as they often should occur together. I'd also like to say that I'm not confident whether `SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level initialization at this point, but I have decided to not change this behavior for now, as the commit history suggests it's several years old. Fixes https://gitlab.com/kicad/code/kicad/issues/7343
5 years ago
Use legacy schematic plugin for loading schematics in all code paths. Use the legacy plugin schematic loader in the sheet edit and append schematic code paths. Check for fully qualified LIB_ID objects (must have library nickname) when loading existing schematics when edit sheets. Rewrite append schematic feature to handle import issues rather than change the name and file name of all of the sheets in the imported schematic. This includes the following: - Load the schematic into a temporary SCH_SHEET object. - Make sure the imported schematic does not cause any hierarchy recursion issues. - Verify the imported schematic uses fully qualified #LIB_ID objects (symbol library table). - Check to see if any symbol libraries need to be added to the current project's symbol library table. This includes: - Check if the symbol library already exists in the project or global symbol library table. - Convert symbol library URLS that use the ${KIPRJMOD} environment variable to absolute paths. ${KIPRJMOD} will not be the same for this project. - Check for duplicate symbol library nicknames and change the new symbol library nickname to prevent library name clashes. - Update all schematic symbol LIB_ID object library nicknames when the library nickname was changed to prevent clashes. - Check for duplicate sheet names which is illegal and automatically rename any duplicate sheets in the imported schematic. - Clear all of the annotation in the imported schematic to prevent clashes. - Append the objects from the temporary sheet to the current page. - Replace any duplicate time stamps. - Refresh the symbol library links. Add support code to SCH_SCREEN object to assist with schematic import. Doxygen comment cleaning. Fixes lp:1731760 https://bugs.launchpad.net/kicad/+bug/1731760
8 years ago
Use legacy schematic plugin for loading schematics in all code paths. Use the legacy plugin schematic loader in the sheet edit and append schematic code paths. Check for fully qualified LIB_ID objects (must have library nickname) when loading existing schematics when edit sheets. Rewrite append schematic feature to handle import issues rather than change the name and file name of all of the sheets in the imported schematic. This includes the following: - Load the schematic into a temporary SCH_SHEET object. - Make sure the imported schematic does not cause any hierarchy recursion issues. - Verify the imported schematic uses fully qualified #LIB_ID objects (symbol library table). - Check to see if any symbol libraries need to be added to the current project's symbol library table. This includes: - Check if the symbol library already exists in the project or global symbol library table. - Convert symbol library URLS that use the ${KIPRJMOD} environment variable to absolute paths. ${KIPRJMOD} will not be the same for this project. - Check for duplicate symbol library nicknames and change the new symbol library nickname to prevent library name clashes. - Update all schematic symbol LIB_ID object library nicknames when the library nickname was changed to prevent clashes. - Check for duplicate sheet names which is illegal and automatically rename any duplicate sheets in the imported schematic. - Clear all of the annotation in the imported schematic to prevent clashes. - Append the objects from the temporary sheet to the current page. - Replace any duplicate time stamps. - Refresh the symbol library links. Add support code to SCH_SCREEN object to assist with schematic import. Doxygen comment cleaning. Fixes lp:1731760 https://bugs.launchpad.net/kicad/+bug/1731760
8 years ago
Use legacy schematic plugin for loading schematics in all code paths. Use the legacy plugin schematic loader in the sheet edit and append schematic code paths. Check for fully qualified LIB_ID objects (must have library nickname) when loading existing schematics when edit sheets. Rewrite append schematic feature to handle import issues rather than change the name and file name of all of the sheets in the imported schematic. This includes the following: - Load the schematic into a temporary SCH_SHEET object. - Make sure the imported schematic does not cause any hierarchy recursion issues. - Verify the imported schematic uses fully qualified #LIB_ID objects (symbol library table). - Check to see if any symbol libraries need to be added to the current project's symbol library table. This includes: - Check if the symbol library already exists in the project or global symbol library table. - Convert symbol library URLS that use the ${KIPRJMOD} environment variable to absolute paths. ${KIPRJMOD} will not be the same for this project. - Check for duplicate symbol library nicknames and change the new symbol library nickname to prevent library name clashes. - Update all schematic symbol LIB_ID object library nicknames when the library nickname was changed to prevent clashes. - Check for duplicate sheet names which is illegal and automatically rename any duplicate sheets in the imported schematic. - Clear all of the annotation in the imported schematic to prevent clashes. - Append the objects from the temporary sheet to the current page. - Replace any duplicate time stamps. - Refresh the symbol library links. Add support code to SCH_SCREEN object to assist with schematic import. Doxygen comment cleaning. Fixes lp:1731760 https://bugs.launchpad.net/kicad/+bug/1731760
8 years ago
Use legacy schematic plugin for loading schematics in all code paths. Use the legacy plugin schematic loader in the sheet edit and append schematic code paths. Check for fully qualified LIB_ID objects (must have library nickname) when loading existing schematics when edit sheets. Rewrite append schematic feature to handle import issues rather than change the name and file name of all of the sheets in the imported schematic. This includes the following: - Load the schematic into a temporary SCH_SHEET object. - Make sure the imported schematic does not cause any hierarchy recursion issues. - Verify the imported schematic uses fully qualified #LIB_ID objects (symbol library table). - Check to see if any symbol libraries need to be added to the current project's symbol library table. This includes: - Check if the symbol library already exists in the project or global symbol library table. - Convert symbol library URLS that use the ${KIPRJMOD} environment variable to absolute paths. ${KIPRJMOD} will not be the same for this project. - Check for duplicate symbol library nicknames and change the new symbol library nickname to prevent library name clashes. - Update all schematic symbol LIB_ID object library nicknames when the library nickname was changed to prevent clashes. - Check for duplicate sheet names which is illegal and automatically rename any duplicate sheets in the imported schematic. - Clear all of the annotation in the imported schematic to prevent clashes. - Append the objects from the temporary sheet to the current page. - Replace any duplicate time stamps. - Refresh the symbol library links. Add support code to SCH_SCREEN object to assist with schematic import. Doxygen comment cleaning. Fixes lp:1731760 https://bugs.launchpad.net/kicad/+bug/1731760
8 years ago
Use legacy schematic plugin for loading schematics in all code paths. Use the legacy plugin schematic loader in the sheet edit and append schematic code paths. Check for fully qualified LIB_ID objects (must have library nickname) when loading existing schematics when edit sheets. Rewrite append schematic feature to handle import issues rather than change the name and file name of all of the sheets in the imported schematic. This includes the following: - Load the schematic into a temporary SCH_SHEET object. - Make sure the imported schematic does not cause any hierarchy recursion issues. - Verify the imported schematic uses fully qualified #LIB_ID objects (symbol library table). - Check to see if any symbol libraries need to be added to the current project's symbol library table. This includes: - Check if the symbol library already exists in the project or global symbol library table. - Convert symbol library URLS that use the ${KIPRJMOD} environment variable to absolute paths. ${KIPRJMOD} will not be the same for this project. - Check for duplicate symbol library nicknames and change the new symbol library nickname to prevent library name clashes. - Update all schematic symbol LIB_ID object library nicknames when the library nickname was changed to prevent clashes. - Check for duplicate sheet names which is illegal and automatically rename any duplicate sheets in the imported schematic. - Clear all of the annotation in the imported schematic to prevent clashes. - Append the objects from the temporary sheet to the current page. - Replace any duplicate time stamps. - Refresh the symbol library links. Add support code to SCH_SCREEN object to assist with schematic import. Doxygen comment cleaning. Fixes lp:1731760 https://bugs.launchpad.net/kicad/+bug/1731760
8 years ago
3 years ago
3 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
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
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2013-2023 CERN (www.cern.ch)
  7. * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
  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
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <symbol_library.h>
  27. #include <confirm.h>
  28. #include <common.h>
  29. #include <connection_graph.h>
  30. #include <dialog_migrate_buses.h>
  31. #include <dialog_symbol_remap.h>
  32. #include <dialog_import_choose_project.h>
  33. #include <eeschema_settings.h>
  34. #include <id.h>
  35. #include <kiface_base.h>
  36. #include <kiplatform/app.h>
  37. #include <lockfile.h>
  38. #include <pgm_base.h>
  39. #include <core/profile.h>
  40. #include <project/project_file.h>
  41. #include <project_rescue.h>
  42. #include <project_sch.h>
  43. #include <dialog_HTML_reporter_base.h>
  44. #include <io/common/plugin_common_choose_project.h>
  45. #include <reporter.h>
  46. #include <richio.h>
  47. #include <sch_bus_entry.h>
  48. #include <sch_commit.h>
  49. #include <sch_edit_frame.h>
  50. #include <sch_io/kicad_legacy/sch_io_kicad_legacy.h>
  51. #include <sch_file_versions.h>
  52. #include <sch_line.h>
  53. #include <sch_sheet.h>
  54. #include <sch_sheet_path.h>
  55. #include <schematic.h>
  56. #include <settings/settings_manager.h>
  57. #include <sim/simulator_frame.h>
  58. #include <tool/actions.h>
  59. #include <tool/tool_manager.h>
  60. #include <tools/sch_editor_control.h>
  61. #include <tools/sch_navigate_tool.h>
  62. #include <trace_helpers.h>
  63. #include <widgets/filedlg_import_non_kicad.h>
  64. #include <widgets/wx_infobar.h>
  65. #include <wildcards_and_files_ext.h>
  66. #include <drawing_sheet/ds_data_model.h>
  67. #include <wx/app.h>
  68. #include <wx/ffile.h>
  69. #include <wx/filedlg.h>
  70. #include <wx/log.h>
  71. #include <wx/richmsgdlg.h>
  72. #include <wx/stdpaths.h>
  73. #include <tools/ee_actions.h>
  74. #include <tools/ee_inspection_tool.h>
  75. #include <tools/ee_selection_tool.h>
  76. #include <paths.h>
  77. #include <wx_filename.h> // For ::ResolvePossibleSymlinks
  78. #include <widgets/wx_progress_reporters.h>
  79. #include <widgets/wx_html_report_box.h>
  80. #include <kiplatform/io.h>
  81. #include "widgets/filedlg_hook_save_project.h"
  82. bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
  83. {
  84. // ensure the splash screen does not obscure any dialog at startup
  85. Pgm().HideSplash();
  86. // implement the pseudo code from KIWAY_PLAYER.h:
  87. wxString msg;
  88. EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
  89. // This is for python:
  90. if( aFileSet.size() != 1 )
  91. {
  92. msg.Printf( "Eeschema:%s() takes only a single filename.", __WXFUNCTION__ );
  93. DisplayError( this, msg );
  94. return false;
  95. }
  96. wxString fullFileName( aFileSet[0] );
  97. wxFileName wx_filename( fullFileName );
  98. // We insist on caller sending us an absolute path, if it does not, we say it's a bug.
  99. wxASSERT_MSG( wx_filename.IsAbsolute(), wxS( "Path is not absolute!" ) );
  100. if( !LockFile( fullFileName ) )
  101. {
  102. msg.Printf( _( "Schematic '%s' is already open by '%s' at '%s'." ), fullFileName,
  103. m_file_checker->GetUsername(), m_file_checker->GetHostname() );
  104. if( !AskOverrideLock( this, msg ) )
  105. return false;
  106. m_file_checker->OverrideLock();
  107. }
  108. if( !AskToSaveChanges() )
  109. return false;
  110. #ifdef PROFILE
  111. PROF_TIMER openFiles( "OpenProjectFile" );
  112. #endif
  113. wxFileName pro = fullFileName;
  114. pro.SetExt( FILEEXT::ProjectFileExtension );
  115. bool is_new = !wxFileName::IsFileReadable( fullFileName );
  116. // If its a non-existent schematic and caller thinks it exists
  117. if( is_new && !( aCtl & KICTL_CREATE ) )
  118. {
  119. // notify user that fullFileName does not exist, ask if user wants to create it.
  120. msg.Printf( _( "Schematic '%s' does not exist. Do you wish to create it?" ),
  121. fullFileName );
  122. if( !IsOK( this, msg ) )
  123. return false;
  124. }
  125. wxCommandEvent e( EDA_EVT_SCHEMATIC_CHANGING );
  126. ProcessEventLocally( e );
  127. // unload current project file before loading new
  128. {
  129. ClearUndoRedoList();
  130. ClearRepeatItemsList();
  131. SetScreen( nullptr );
  132. m_toolManager->GetTool<EE_INSPECTION_TOOL>()->Reset( TOOL_BASE::SUPERMODEL_RELOAD );
  133. CreateScreens();
  134. }
  135. SetStatusText( wxEmptyString );
  136. m_infoBar->Dismiss();
  137. WX_PROGRESS_REPORTER progressReporter( this, is_new ? _( "Creating Schematic" )
  138. : _( "Loading Schematic" ), 1 );
  139. bool differentProject = pro.GetFullPath() != Prj().GetProjectFullName();
  140. if( differentProject )
  141. {
  142. if( !Prj().IsNullProject() )
  143. {
  144. SaveProjectLocalSettings();
  145. GetSettingsManager()->SaveProject();
  146. }
  147. Schematic().SetProject( nullptr );
  148. GetSettingsManager()->UnloadProject( &Prj(), false );
  149. GetSettingsManager()->LoadProject( pro.GetFullPath() );
  150. wxFileName legacyPro( pro );
  151. legacyPro.SetExt( FILEEXT::LegacyProjectFileExtension );
  152. // Do not allow saving a project if one doesn't exist. This normally happens if we are
  153. // standalone and opening a schematic that has been moved from its project folder.
  154. if( !pro.Exists() && !legacyPro.Exists() && !( aCtl & KICTL_CREATE ) )
  155. Prj().SetReadOnly();
  156. CreateScreens();
  157. }
  158. SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( fullFileName, KICTL_KICAD_ONLY );
  159. if( schFileType == SCH_IO_MGR::SCH_LEGACY )
  160. {
  161. // Don't reload the symbol libraries if we are just launching Eeschema from KiCad again.
  162. // They are already saved in the kiface project object.
  163. if( differentProject || !Prj().GetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS ) )
  164. {
  165. // load the libraries here, not in SCH_SCREEN::Draw() which is a context
  166. // that will not tolerate DisplayError() dialog since we're already in an
  167. // event handler in there.
  168. // And when a schematic file is loaded, we need these libs to initialize
  169. // some parameters (links to PART LIB, dangling ends ...)
  170. Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr );
  171. PROJECT_SCH::SchLibs( &Prj() );
  172. }
  173. }
  174. else
  175. {
  176. // No legacy symbol libraries including the cache are loaded with the new file format.
  177. Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr );
  178. }
  179. // Load the symbol library table, this will be used forever more.
  180. Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr );
  181. PROJECT_SCH::SchSymbolLibTable( &Prj() );
  182. // Load project settings after schematic has been set up with the project link, since this will
  183. // update some of the needed schematic settings such as drawing defaults
  184. LoadProjectSettings();
  185. wxFileName rfn( GetCurrentFileName() );
  186. rfn.MakeRelativeTo( Prj().GetProjectPath() );
  187. LoadWindowState( rfn.GetFullPath() );
  188. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Schematic file changes are unsaved" ) );
  189. if( Kiface().IsSingle() )
  190. {
  191. KIPLATFORM::APP::RegisterApplicationRestart( fullFileName );
  192. }
  193. if( is_new || schFileType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
  194. {
  195. // mark new, unsaved file as modified.
  196. GetScreen()->SetContentModified();
  197. GetScreen()->SetFileName( fullFileName );
  198. if( schFileType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
  199. {
  200. msg.Printf( _( "'%s' is not a KiCad schematic file.\nUse File -> Import for "
  201. "non-KiCad schematic files." ),
  202. fullFileName );
  203. progressReporter.Hide();
  204. DisplayErrorMessage( this, msg );
  205. }
  206. }
  207. else
  208. {
  209. wxFileName autoSaveFn = fullFileName;
  210. autoSaveFn.SetName( getAutoSaveFileName() );
  211. autoSaveFn.ClearExt();
  212. if( ( aCtl & KICTL_REVERT ) )
  213. {
  214. DeleteAutoSaveFile( autoSaveFn );
  215. }
  216. else
  217. {
  218. // This will rename the file if there is an autosave and the user wants to recover
  219. CheckForAutoSaveFile( autoSaveFn );
  220. }
  221. SetScreen( nullptr );
  222. IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( schFileType ) );
  223. pi->SetProgressReporter( &progressReporter );
  224. bool failedLoad = false;
  225. try
  226. {
  227. {
  228. wxBusyCursor busy;
  229. Schematic().SetRoot( pi->LoadSchematicFile( fullFileName, &Schematic() ) );
  230. // Make ${SHEETNAME} work on the root sheet until we properly support
  231. // naming the root sheet
  232. Schematic().Root().SetName( _( "Root" ) );
  233. wxLogTrace( tracePathsAndFiles, wxS( "Loaded schematic with root sheet UUID %s" ),
  234. Schematic().Root().m_Uuid.AsString() );
  235. }
  236. if( !pi->GetError().IsEmpty() )
  237. {
  238. DisplayErrorMessage( this, _( "The entire schematic could not be loaded. Errors "
  239. "occurred attempting to load hierarchical sheets." ),
  240. pi->GetError() );
  241. }
  242. }
  243. catch( const FUTURE_FORMAT_ERROR& ffe )
  244. {
  245. msg.Printf( _( "Error loading schematic '%s'." ), fullFileName);
  246. progressReporter.Hide();
  247. DisplayErrorMessage( this, msg, ffe.Problem() );
  248. failedLoad = true;
  249. }
  250. catch( const IO_ERROR& ioe )
  251. {
  252. msg.Printf( _( "Error loading schematic '%s'." ), fullFileName);
  253. progressReporter.Hide();
  254. DisplayErrorMessage( this, msg, ioe.What() );
  255. failedLoad = true;
  256. }
  257. catch( const std::bad_alloc& )
  258. {
  259. msg.Printf( _( "Memory exhausted loading schematic '%s'." ), fullFileName );
  260. progressReporter.Hide();
  261. DisplayErrorMessage( this, msg, wxEmptyString );
  262. failedLoad = true;
  263. }
  264. // This fixes a focus issue after the progress reporter is done on GTK. It shouldn't
  265. // cause any issues on macOS and Windows. If it does, it will have to be conditionally
  266. // compiled.
  267. Raise();
  268. if( failedLoad )
  269. {
  270. // Do not leave g_RootSheet == NULL because it is expected to be
  271. // a valid sheet. Therefore create a dummy empty root sheet and screen.
  272. CreateScreens();
  273. m_toolManager->RunAction( ACTIONS::zoomFitScreen );
  274. msg.Printf( _( "Failed to load '%s'." ), fullFileName );
  275. SetMsgPanel( wxEmptyString, msg );
  276. return false;
  277. }
  278. // It's possible the schematic parser fixed errors due to bugs so warn the user
  279. // that the schematic has been fixed (modified).
  280. SCH_SHEET_LIST sheetList = Schematic().BuildSheetListSortedByPageNumbers();
  281. if( sheetList.IsModified() )
  282. {
  283. DisplayInfoMessage( this,
  284. _( "An error was found when loading the schematic that has "
  285. "been automatically fixed. Please save the schematic to "
  286. "repair the broken file or it may not be usable with other "
  287. "versions of KiCad." ) );
  288. }
  289. if( sheetList.AllSheetPageNumbersEmpty() )
  290. sheetList.SetInitialPageNumbers();
  291. UpdateFileHistory( fullFileName );
  292. SCH_SCREENS schematic( Schematic().Root() );
  293. // LIB_ID checks and symbol rescue only apply to the legacy file formats.
  294. if( schFileType == SCH_IO_MGR::SCH_LEGACY )
  295. {
  296. // Convert any legacy bus-bus entries to just be bus wires
  297. for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
  298. {
  299. std::vector<SCH_ITEM*> deleted;
  300. for( SCH_ITEM* item : screen->Items() )
  301. {
  302. if( item->Type() == SCH_BUS_BUS_ENTRY_T )
  303. {
  304. SCH_BUS_BUS_ENTRY* entry = static_cast<SCH_BUS_BUS_ENTRY*>( item );
  305. std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
  306. wire->SetLayer( LAYER_BUS );
  307. wire->SetStartPoint( entry->GetPosition() );
  308. wire->SetEndPoint( entry->GetEnd() );
  309. screen->Append( wire.release() );
  310. deleted.push_back( item );
  311. }
  312. }
  313. for( SCH_ITEM* item : deleted )
  314. screen->Remove( item );
  315. }
  316. // Convert old projects over to use symbol library table.
  317. if( schematic.HasNoFullyDefinedLibIds() )
  318. {
  319. DIALOG_SYMBOL_REMAP dlgRemap( this );
  320. dlgRemap.ShowQuasiModal();
  321. }
  322. else
  323. {
  324. // Double check to ensure no legacy library list entries have been
  325. // added to the project file symbol library list.
  326. wxString paths;
  327. wxArrayString libNames;
  328. SYMBOL_LIBS::GetLibNamesAndPaths( &Prj(), &paths, &libNames );
  329. if( !libNames.IsEmpty() )
  330. {
  331. if( eeconfig()->m_Appearance.show_illegal_symbol_lib_dialog )
  332. {
  333. wxRichMessageDialog invalidLibDlg(
  334. this,
  335. _( "Illegal entry found in project file symbol library list." ),
  336. _( "Project Load Warning" ),
  337. wxOK | wxCENTER | wxICON_EXCLAMATION );
  338. invalidLibDlg.ShowDetailedText(
  339. _( "Symbol libraries defined in the project file symbol library "
  340. "list are no longer supported and will be removed.\n\n"
  341. "This may cause broken symbol library links under certain "
  342. "conditions." ) );
  343. invalidLibDlg.ShowCheckBox( _( "Do not show this dialog again." ) );
  344. invalidLibDlg.ShowModal();
  345. eeconfig()->m_Appearance.show_illegal_symbol_lib_dialog =
  346. !invalidLibDlg.IsCheckBoxChecked();
  347. }
  348. libNames.Clear();
  349. paths.Clear();
  350. SYMBOL_LIBS::SetLibNamesAndPaths( &Prj(), paths, libNames );
  351. }
  352. if( !cfg || !cfg->m_RescueNeverShow )
  353. {
  354. SCH_EDITOR_CONTROL* editor = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
  355. editor->RescueSymbolLibTableProject( false );
  356. }
  357. }
  358. // Ensure there is only one legacy library loaded and that it is the cache library.
  359. SYMBOL_LIBS* legacyLibs = PROJECT_SCH::SchLibs( &Schematic().Prj() );
  360. if( legacyLibs->GetLibraryCount() == 0 )
  361. {
  362. wxString extMsg;
  363. wxFileName cacheFn = pro;
  364. cacheFn.SetName( cacheFn.GetName() + "-cache" );
  365. cacheFn.SetExt( FILEEXT::LegacySymbolLibFileExtension );
  366. msg.Printf( _( "The project symbol library cache file '%s' was not found." ),
  367. cacheFn.GetFullName() );
  368. extMsg = _( "This can result in a broken schematic under certain conditions. "
  369. "If the schematic does not have any missing symbols upon opening, "
  370. "save it immediately before making any changes to prevent data "
  371. "loss. If there are missing symbols, either manual recovery of "
  372. "the schematic or recovery of the symbol cache library file and "
  373. "reloading the schematic is required." );
  374. wxMessageDialog dlgMissingCache( this, msg, _( "Warning" ),
  375. wxOK | wxCANCEL | wxICON_EXCLAMATION | wxCENTER );
  376. dlgMissingCache.SetExtendedMessage( extMsg );
  377. dlgMissingCache.SetOKCancelLabels(
  378. wxMessageDialog::ButtonLabel( _( "Load Without Cache File" ) ),
  379. wxMessageDialog::ButtonLabel( _( "Abort" ) ) );
  380. if( dlgMissingCache.ShowModal() == wxID_CANCEL )
  381. {
  382. Schematic().Reset();
  383. CreateScreens();
  384. return false;
  385. }
  386. }
  387. // Update all symbol library links for all sheets.
  388. schematic.UpdateSymbolLinks();
  389. m_infoBar->RemoveAllButtons();
  390. m_infoBar->AddCloseButton();
  391. m_infoBar->ShowMessage( _( "This file was created by an older version of KiCad. "
  392. "It will be converted to the new format when saved." ),
  393. wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
  394. // Legacy schematic can have duplicate time stamps so fix that before converting
  395. // to the s-expression format.
  396. schematic.ReplaceDuplicateTimeStamps();
  397. for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
  398. screen->FixLegacyPowerSymbolMismatches();
  399. // Allow the schematic to be saved to new file format without making any edits.
  400. OnModify();
  401. }
  402. else // S-expression schematic.
  403. {
  404. if( schematic.GetFirst()->GetFileFormatVersionAtLoad() < SEXPR_SCHEMATIC_FILE_VERSION )
  405. {
  406. m_infoBar->RemoveAllButtons();
  407. m_infoBar->AddCloseButton();
  408. m_infoBar->ShowMessage( _( "This file was created by an older version of KiCad. "
  409. "It will be converted to the new format when saved." ),
  410. wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
  411. }
  412. for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
  413. screen->UpdateLocalLibSymbolLinks();
  414. // Restore all of the loaded symbol and sheet instances from the root sheet.
  415. if( Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221002 )
  416. sheetList.UpdateSymbolInstanceData( Schematic().RootScreen()->GetSymbolInstances());
  417. if( Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221110 )
  418. sheetList.UpdateSheetInstanceData( Schematic().RootScreen()->GetSheetInstances());
  419. if( Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20230221 )
  420. for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
  421. screen->FixLegacyPowerSymbolMismatches();
  422. for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
  423. screen->MigrateSimModels();
  424. if( schematic.GetFirst()->GetFileFormatVersionAtLoad() < SEXPR_SCHEMATIC_FILE_VERSION )
  425. {
  426. // Allow the schematic to be saved to new file format without making any edits.
  427. OnModify();
  428. }
  429. }
  430. schematic.PruneOrphanedSymbolInstances( Prj().GetProjectName(), sheetList );
  431. schematic.PruneOrphanedSheetInstances( Prj().GetProjectName(), sheetList );
  432. Schematic().ConnectionGraph()->Reset();
  433. SetScreen( GetCurrentSheet().LastScreen() );
  434. // Migrate conflicting bus definitions
  435. // TODO(JE) This should only run once based on schematic file version
  436. if( Schematic().ConnectionGraph()->GetBusesNeedingMigration().size() > 0 )
  437. {
  438. DIALOG_MIGRATE_BUSES dlg( this );
  439. dlg.ShowQuasiModal();
  440. OnModify();
  441. }
  442. SCH_COMMIT dummy( this );
  443. RecalculateConnections( &dummy, GLOBAL_CLEANUP );
  444. }
  445. // Load any exclusions from the project file
  446. Schematic().ResolveERCExclusionsPostUpdate();
  447. initScreenZoom();
  448. SetSheetNumberAndCount();
  449. RecomputeIntersheetRefs();
  450. GetCurrentSheet().UpdateAllScreenReferences();
  451. // Re-create junctions if needed. Eeschema optimizes wires by merging
  452. // colinear segments. If a schematic is saved without a valid
  453. // cache library or missing installed libraries, this can cause connectivity errors
  454. // unless junctions are added.
  455. //
  456. // TODO: (RFB) This really needs to be put inside the Load() function of the SCH_IO_KICAD_LEGACY
  457. // I can't put it right now because of the extra code that is above to convert legacy bus-bus
  458. // entries to bus wires
  459. if( schFileType == SCH_IO_MGR::SCH_LEGACY )
  460. Schematic().FixupJunctions();
  461. SyncView();
  462. GetScreen()->ClearDrawingState();
  463. TestDanglingEnds();
  464. UpdateHierarchyNavigator( false );
  465. wxCommandEvent changedEvt( EDA_EVT_SCHEMATIC_CHANGED );
  466. ProcessEventLocally( changedEvt );
  467. for( wxEvtHandler* listener : m_schematicChangeListeners )
  468. {
  469. wxCHECK2( listener, continue );
  470. // Use the windows variant when handling event messages in case there is any special
  471. // event handler pre and/or post processing specific to windows.
  472. wxWindow* win = dynamic_cast<wxWindow*>( listener );
  473. if( win )
  474. win->HandleWindowEvent( e );
  475. else
  476. listener->SafelyProcessEvent( e );
  477. }
  478. updateTitle();
  479. m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->ResetHistory();
  480. wxFileName fn = Prj().AbsolutePath( GetScreen()->GetFileName() );
  481. if( fn.FileExists() && !fn.IsFileWritable() )
  482. {
  483. m_infoBar->RemoveAllButtons();
  484. m_infoBar->AddCloseButton();
  485. m_infoBar->ShowMessage( _( "Schematic is read only." ),
  486. wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
  487. }
  488. #ifdef PROFILE
  489. openFiles.Show();
  490. #endif
  491. // Ensure all items are redrawn (especially the drawing-sheet items):
  492. if( GetCanvas() )
  493. GetCanvas()->DisplaySheet( GetCurrentSheet().LastScreen() );
  494. return true;
  495. }
  496. bool SCH_EDIT_FRAME::AppendSchematic()
  497. {
  498. SCH_SCREEN* screen = GetScreen();
  499. wxCHECK( screen, false );
  500. // open file chooser dialog
  501. wxString path = wxPathOnly( Prj().GetProjectFullName() );
  502. wxFileDialog dlg( this, _( "Insert Schematic" ), path, wxEmptyString,
  503. FILEEXT::KiCadSchematicFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
  504. if( dlg.ShowModal() == wxID_CANCEL )
  505. return false;
  506. return AddSheetAndUpdateDisplay( dlg.GetPath() );
  507. }
  508. bool SCH_EDIT_FRAME::AddSheetAndUpdateDisplay( const wxString aFullFileName )
  509. {
  510. SCH_COMMIT commit( m_toolManager );
  511. EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
  512. selectionTool->ClearSelection();
  513. // Mark all existing items on the screen so we don't select them after appending
  514. for( EDA_ITEM* item : GetScreen()->Items() )
  515. item->SetFlags( SKIP_STRUCT );
  516. if( !LoadSheetFromFile( GetCurrentSheet().Last(), &GetCurrentSheet(), aFullFileName ) )
  517. return false;
  518. initScreenZoom();
  519. SetSheetNumberAndCount();
  520. SyncView();
  521. OnModify();
  522. HardRedraw(); // Full reinit of the current screen and the display.
  523. // Select all new items
  524. for( EDA_ITEM* item : GetScreen()->Items() )
  525. {
  526. if( !item->HasFlag( SKIP_STRUCT ) )
  527. {
  528. commit.Added( item, GetScreen() );
  529. selectionTool->AddItemToSel( item );
  530. if( item->Type() == SCH_LINE_T )
  531. item->SetFlags( STARTPOINT | ENDPOINT );
  532. }
  533. else
  534. item->ClearFlags( SKIP_STRUCT );
  535. }
  536. // Start moving selection, cancel undoes the insertion
  537. if( !m_toolManager->RunSynchronousAction( EE_ACTIONS::move, &commit ) )
  538. commit.Revert();
  539. else
  540. commit.Push( _( "Import Schematic Sheet Content..." ) );
  541. UpdateHierarchyNavigator();
  542. return true;
  543. }
  544. void SCH_EDIT_FRAME::OnAppendProject( wxCommandEvent& event )
  545. {
  546. if( GetScreen() && GetScreen()->IsModified() )
  547. {
  548. wxString msg = _( "This operation cannot be undone.\n\n"
  549. "Do you want to save the current document before proceeding?" );
  550. if( IsOK( this, msg ) )
  551. SaveProject();
  552. }
  553. AppendSchematic();
  554. }
  555. void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent )
  556. {
  557. if( Schematic().RootScreen() && !Schematic().RootScreen()->Items().empty() )
  558. {
  559. wxString msg = _( "This operation replaces the contents of the current schematic, "
  560. "which will be permanently lost.\n\n"
  561. "Do you want to proceed?" );
  562. if( !IsOK( this, msg ) )
  563. return;
  564. }
  565. // Set the project location if none is set or if we are running in standalone mode
  566. bool setProject = Prj().GetProjectFullName().IsEmpty() || Kiface().IsSingle();
  567. wxString path = wxPathOnly( Prj().GetProjectFullName() );
  568. wxString fileFiltersStr;
  569. wxString allWildcardsStr;
  570. for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
  571. {
  572. if( fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY )
  573. continue; // this is "Import non-KiCad schematic"
  574. IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( fileType ) );
  575. if( !pi )
  576. continue;
  577. const IO_BASE::IO_FILE_DESC& desc = pi->GetSchematicFileDesc();
  578. if( desc.m_FileExtensions.empty() || !desc.m_CanRead )
  579. continue;
  580. if( !fileFiltersStr.IsEmpty() )
  581. fileFiltersStr += wxChar( '|' );
  582. fileFiltersStr += desc.FileFilter();
  583. for( const std::string& ext : desc.m_FileExtensions )
  584. allWildcardsStr << wxS( "*." ) << formatWildcardExt( ext ) << wxS( ";" );
  585. }
  586. fileFiltersStr = _( "All supported formats" ) + wxS( "|" ) + allWildcardsStr + wxS( "|" )
  587. + fileFiltersStr;
  588. wxFileDialog dlg( this, _( "Import Schematic" ), path, wxEmptyString, fileFiltersStr,
  589. wxFD_OPEN | wxFD_FILE_MUST_EXIST ); // TODO
  590. FILEDLG_IMPORT_NON_KICAD importOptions( eeconfig()->m_System.show_import_issues );
  591. dlg.SetCustomizeHook( importOptions );
  592. if( dlg.ShowModal() == wxID_CANCEL )
  593. return;
  594. eeconfig()->m_System.show_import_issues = importOptions.GetShowIssues();
  595. // Don't leave dangling pointers to previously-opened document.
  596. m_toolManager->GetTool<EE_SELECTION_TOOL>()->ClearSelection();
  597. ClearUndoRedoList();
  598. ClearRepeatItemsList();
  599. if( setProject )
  600. {
  601. Schematic().SetProject( nullptr );
  602. GetSettingsManager()->UnloadProject( &Prj(), false );
  603. // Clear view before destroying schematic as repaints depend on schematic being valid
  604. SetScreen( nullptr );
  605. Schematic().Reset();
  606. wxFileName projectFn( dlg.GetPath() );
  607. projectFn.SetExt( FILEEXT::ProjectFileExtension );
  608. GetSettingsManager()->LoadProject( projectFn.GetFullPath() );
  609. Schematic().SetProject( &Prj() );
  610. }
  611. wxFileName fn = dlg.GetPath();
  612. if( !fn.IsFileReadable() )
  613. {
  614. wxLogError( _( "Insufficient permissions to read file '%s'." ), fn.GetFullPath() );
  615. return;
  616. }
  617. SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN;
  618. for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
  619. {
  620. IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( fileType ) );
  621. if( !pi )
  622. continue;
  623. if( pi->CanReadSchematicFile( fn.GetFullPath() ) )
  624. {
  625. pluginType = fileType;
  626. break;
  627. }
  628. }
  629. if( pluginType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
  630. {
  631. wxLogError( _( "No loader can read the specified file: '%s'." ), fn.GetFullPath() );
  632. CreateScreens();
  633. SetScreen( Schematic().RootScreen() );
  634. return;
  635. }
  636. importFile( dlg.GetPath(), pluginType );
  637. RefreshCanvas();
  638. }
  639. bool SCH_EDIT_FRAME::saveSchematicFile( SCH_SHEET* aSheet, const wxString& aSavePath )
  640. {
  641. wxString msg;
  642. wxFileName schematicFileName;
  643. wxFileName oldFileName;
  644. bool success;
  645. SCH_SCREEN* screen = aSheet->GetScreen();
  646. wxCHECK( screen, false );
  647. // Cannot save to nowhere
  648. wxCHECK( !aSavePath.IsEmpty(), false );
  649. // Construct the name of the file to be saved
  650. schematicFileName = Prj().AbsolutePath( aSavePath );
  651. oldFileName = schematicFileName;
  652. // Write through symlinks, don't replace them
  653. WX_FILENAME::ResolvePossibleSymlinks( schematicFileName );
  654. if( !IsWritable( schematicFileName ) )
  655. return false;
  656. wxFileName projectFile( schematicFileName );
  657. projectFile.SetExt( FILEEXT::ProjectFileExtension );
  658. if( projectFile.FileExists() )
  659. {
  660. // Save various ERC settings, such as violation severities (which may have been edited
  661. // via the ERC dialog as well as the Schematic Setup dialog), ERC exclusions, etc.
  662. saveProjectSettings();
  663. }
  664. wxString tempFile = wxFileName::CreateTempFileName( wxS( "eeschema" ) );
  665. // Save
  666. wxLogTrace( traceAutoSave, wxS( "Saving file " ) + schematicFileName.GetFullPath() );
  667. if( m_infoBar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE )
  668. m_infoBar->Dismiss();
  669. SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::GuessPluginTypeFromSchPath(
  670. schematicFileName.GetFullPath() );
  671. if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
  672. pluginType = SCH_IO_MGR::SCH_KICAD;
  673. IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( pluginType ) );
  674. try
  675. {
  676. pi->SaveSchematicFile( tempFile, aSheet, &Schematic() );
  677. success = true;
  678. }
  679. catch( const IO_ERROR& ioe )
  680. {
  681. msg.Printf( _( "Error saving schematic file '%s'.\n%s" ),
  682. schematicFileName.GetFullPath(),
  683. ioe.What() );
  684. DisplayError( this, msg );
  685. msg.Printf( _( "Failed to create temporary file '%s'." ),
  686. tempFile );
  687. SetMsgPanel( wxEmptyString, msg );
  688. // In case we started a file but didn't fully write it, clean up
  689. wxRemoveFile( tempFile );
  690. success = false;
  691. }
  692. if( success )
  693. {
  694. // Preserve the permissions of the current file
  695. KIPLATFORM::IO::DuplicatePermissions( schematicFileName.GetFullPath(), tempFile );
  696. // Replace the original with the temporary file we just wrote
  697. success = wxRenameFile( tempFile, schematicFileName.GetFullPath() );
  698. if( !success )
  699. {
  700. msg.Printf( _( "Error saving schematic file '%s'.\n"
  701. "Failed to rename temporary file '%s'." ),
  702. schematicFileName.GetFullPath(),
  703. tempFile );
  704. DisplayError( this, msg );
  705. msg.Printf( _( "Failed to rename temporary file '%s'." ),
  706. tempFile );
  707. SetMsgPanel( wxEmptyString, msg );
  708. }
  709. }
  710. if( success )
  711. {
  712. // Delete auto save file.
  713. wxFileName autoSaveFileName = schematicFileName;
  714. autoSaveFileName.SetName( FILEEXT::AutoSaveFilePrefix + schematicFileName.GetName() );
  715. if( autoSaveFileName.FileExists() )
  716. {
  717. wxLogTrace( traceAutoSave,
  718. wxS( "Removing auto save file <" ) + autoSaveFileName.GetFullPath() +
  719. wxS( ">" ) );
  720. wxRemoveFile( autoSaveFileName.GetFullPath() );
  721. }
  722. screen->SetContentModified( false );
  723. msg.Printf( _( "File '%s' saved." ), screen->GetFileName() );
  724. SetStatusText( msg, 0 );
  725. }
  726. else
  727. {
  728. DisplayError( this, _( "File write operation failed." ) );
  729. }
  730. return success;
  731. }
  732. bool SCH_EDIT_FRAME::SaveProject( bool aSaveAs )
  733. {
  734. wxString msg;
  735. SCH_SCREEN* screen;
  736. SCH_SCREENS screens( Schematic().Root() );
  737. bool saveCopy = aSaveAs && !Kiface().IsSingle();
  738. bool success = true;
  739. bool updateFileHistory = false;
  740. bool createNewProject = false;
  741. // I want to see it in the debugger, show me the string! Can't do that with wxFileName.
  742. wxString fileName = Prj().AbsolutePath( Schematic().Root().GetFileName() );
  743. wxFileName fn = fileName;
  744. // Path to save each screen to: will be the stored filename by default, but is overwritten by
  745. // a Save As Copy operation.
  746. std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
  747. // Handle "Save As" and saving a new project/schematic for the first time in standalone
  748. if( Prj().IsNullProject() || aSaveAs )
  749. {
  750. // Null project should only be possible in standalone mode.
  751. wxCHECK( Kiface().IsSingle() || aSaveAs, false );
  752. wxFileName newFileName;
  753. wxFileName savePath( Prj().GetProjectFullName() );
  754. if( !savePath.IsOk() || !savePath.IsDirWritable() )
  755. {
  756. savePath = GetMruPath();
  757. if( !savePath.IsOk() || !savePath.IsDirWritable() )
  758. savePath = PATHS::GetDefaultUserProjectsPath();
  759. }
  760. if( savePath.HasExt() )
  761. savePath.SetExt( FILEEXT::KiCadSchematicFileExtension );
  762. else
  763. savePath.SetName( wxEmptyString );
  764. wxFileDialog dlg( this, _( "Schematic Files" ), savePath.GetPath(), savePath.GetFullName(),
  765. FILEEXT::KiCadSchematicFileWildcard(),
  766. wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
  767. FILEDLG_HOOK_SAVE_PROJECT newProjectHook;
  768. // Add a "Create a project" checkbox in standalone mode and one isn't loaded
  769. if( Kiface().IsSingle() || aSaveAs )
  770. {
  771. dlg.SetCustomizeHook( newProjectHook );
  772. }
  773. if( dlg.ShowModal() == wxID_CANCEL )
  774. return false;
  775. newFileName = EnsureFileExtension( dlg.GetPath(), FILEEXT::KiCadSchematicFileExtension );
  776. if( ( !newFileName.DirExists() && !newFileName.Mkdir() ) ||
  777. !newFileName.IsDirWritable() )
  778. {
  779. msg.Printf( _( "Folder '%s' could not be created.\n\n"
  780. "Make sure you have write permissions and try again." ),
  781. newFileName.GetPath() );
  782. wxMessageDialog dlgBadPath( this, msg, _( "Error" ),
  783. wxOK | wxICON_EXCLAMATION | wxCENTER );
  784. dlgBadPath.ShowModal();
  785. return false;
  786. }
  787. if( newProjectHook.IsAttachedToDialog() )
  788. createNewProject = newProjectHook.GetCreateNewProject();
  789. if( !saveCopy )
  790. {
  791. Schematic().Root().SetFileName( newFileName.GetFullName() );
  792. Schematic().RootScreen()->SetFileName( newFileName.GetFullPath() );
  793. updateFileHistory = true;
  794. }
  795. else
  796. {
  797. filenameMap[Schematic().RootScreen()] = newFileName.GetFullPath();
  798. }
  799. // Set the base path to all new sheets.
  800. for( size_t i = 0; i < screens.GetCount(); i++ )
  801. {
  802. screen = screens.GetScreen( i );
  803. wxCHECK2( screen, continue );
  804. // The root screen file name has already been set.
  805. if( screen == Schematic().RootScreen() )
  806. continue;
  807. wxFileName tmp = screen->GetFileName();
  808. // Assume existing sheet files are being reused and do not save them to the new
  809. // path. Maybe in the future, add a user option to copy schematic files to the
  810. // new project path.
  811. if( tmp.FileExists() )
  812. continue;
  813. if( tmp.GetPath().IsEmpty() )
  814. {
  815. tmp.SetPath( newFileName.GetPath() );
  816. }
  817. else if( tmp.GetPath() == fn.GetPath() )
  818. {
  819. tmp.SetPath( newFileName.GetPath() );
  820. }
  821. else if( tmp.GetPath().StartsWith( fn.GetPath() ) )
  822. {
  823. // NOTE: this hasn't been tested because the sheet properties dialog no longer
  824. // allows adding a path specifier in the file name field.
  825. wxString newPath = newFileName.GetPath();
  826. newPath += tmp.GetPath().Right( fn.GetPath().Length() );
  827. tmp.SetPath( newPath );
  828. }
  829. wxLogTrace( tracePathsAndFiles,
  830. wxS( "Moving schematic from '%s' to '%s'." ),
  831. screen->GetFileName(),
  832. tmp.GetFullPath() );
  833. if( !tmp.DirExists() && !tmp.Mkdir() )
  834. {
  835. msg.Printf( _( "Folder '%s' could not be created.\n\n"
  836. "Make sure you have write permissions and try again." ),
  837. newFileName.GetPath() );
  838. wxMessageDialog dlgBadFilePath( this, msg, _( "Error" ),
  839. wxOK | wxICON_EXCLAMATION | wxCENTER );
  840. dlgBadFilePath.ShowModal();
  841. return false;
  842. }
  843. if( saveCopy )
  844. filenameMap[screen] = tmp.GetFullPath();
  845. else
  846. screen->SetFileName( tmp.GetFullPath() );
  847. }
  848. // Attempt to make sheet file name paths relative to the new root schematic path.
  849. for( SCH_SHEET_PATH& sheet : Schematic().BuildUnorderedSheetList() )
  850. {
  851. if( !sheet.Last()->IsRootSheet() )
  852. sheet.MakeFilePathRelativeToParentSheet();
  853. }
  854. }
  855. else if( !fn.FileExists() )
  856. {
  857. // File doesn't exist yet; true if we just imported something
  858. updateFileHistory = true;
  859. }
  860. else if( !IsContentModified() )
  861. {
  862. return true;
  863. }
  864. if( filenameMap.empty() || !saveCopy )
  865. {
  866. for( size_t i = 0; i < screens.GetCount(); i++ )
  867. filenameMap[screens.GetScreen( i )] = screens.GetScreen( i )->GetFileName();
  868. }
  869. // Warn user on potential file overwrite. This can happen on shared sheets.
  870. wxArrayString overwrittenFiles;
  871. wxArrayString lockedFiles;
  872. for( size_t i = 0; i < screens.GetCount(); i++ )
  873. {
  874. screen = screens.GetScreen( i );
  875. wxCHECK2( screen, continue );
  876. // Convert legacy schematics file name extensions for the new format.
  877. wxFileName tmpFn = filenameMap[screen];
  878. if( !tmpFn.IsOk() )
  879. continue;
  880. if( tmpFn.FileExists() && !tmpFn.IsFileWritable() )
  881. lockedFiles.Add( tmpFn.GetFullPath() );
  882. if( tmpFn.GetExt() == FILEEXT::KiCadSchematicFileExtension )
  883. continue;
  884. tmpFn.SetExt( FILEEXT::KiCadSchematicFileExtension );
  885. if( tmpFn.FileExists() )
  886. overwrittenFiles.Add( tmpFn.GetFullPath() );
  887. }
  888. if( !lockedFiles.IsEmpty() )
  889. {
  890. for( const wxString& lockedFile : lockedFiles )
  891. {
  892. if( msg.IsEmpty() )
  893. msg = lockedFile;
  894. else
  895. msg += "\n" + lockedFile;
  896. }
  897. wxRichMessageDialog dlg( this, wxString::Format( _( "Failed to save %s." ),
  898. Schematic().Root().GetFileName() ),
  899. _( "Locked File Warning" ),
  900. wxOK | wxICON_WARNING | wxCENTER );
  901. dlg.SetExtendedMessage( _( "You do not have write permissions to:\n\n" ) + msg );
  902. dlg.ShowModal();
  903. return false;
  904. }
  905. if( !overwrittenFiles.IsEmpty() )
  906. {
  907. for( const wxString& overwrittenFile : overwrittenFiles )
  908. {
  909. if( msg.IsEmpty() )
  910. msg = overwrittenFile;
  911. else
  912. msg += "\n" + overwrittenFile;
  913. }
  914. wxRichMessageDialog dlg( this, _( "Saving will overwrite existing files." ),
  915. _( "Save Warning" ),
  916. wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxCENTER |
  917. wxICON_EXCLAMATION );
  918. dlg.ShowDetailedText( _( "The following files will be overwritten:\n\n" ) + msg );
  919. dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel( _( "Overwrite Files" ) ),
  920. wxMessageDialog::ButtonLabel( _( "Abort Project Save" ) ) );
  921. if( dlg.ShowModal() == wxID_CANCEL )
  922. return false;
  923. }
  924. screens.BuildClientSheetPathList();
  925. for( size_t i = 0; i < screens.GetCount(); i++ )
  926. {
  927. screen = screens.GetScreen( i );
  928. wxCHECK2( screen, continue );
  929. // Convert legacy schematics file name extensions for the new format.
  930. wxFileName tmpFn = filenameMap[screen];
  931. if( tmpFn.IsOk() && tmpFn.GetExt() != FILEEXT::KiCadSchematicFileExtension )
  932. {
  933. updateFileHistory = true;
  934. tmpFn.SetExt( FILEEXT::KiCadSchematicFileExtension );
  935. for( EDA_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
  936. {
  937. SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
  938. wxFileName sheetFileName = sheet->GetFileName();
  939. if( !sheetFileName.IsOk()
  940. || sheetFileName.GetExt() == FILEEXT::KiCadSchematicFileExtension )
  941. continue;
  942. sheetFileName.SetExt( FILEEXT::KiCadSchematicFileExtension );
  943. sheet->SetFileName( sheetFileName.GetFullPath() );
  944. UpdateItem( sheet );
  945. }
  946. filenameMap[screen] = tmpFn.GetFullPath();
  947. if( !saveCopy )
  948. screen->SetFileName( tmpFn.GetFullPath() );
  949. }
  950. // Do not save sheet symbols with no valid filename set
  951. if( !tmpFn.IsOk() )
  952. continue;
  953. std::vector<SCH_SHEET_PATH>& sheets = screen->GetClientSheetPaths();
  954. if( sheets.size() == 1 )
  955. screen->SetVirtualPageNumber( 1 );
  956. else
  957. screen->SetVirtualPageNumber( 0 ); // multiple uses; no way to store the real sheet #
  958. // This is a new schematic file so make sure it has a unique ID.
  959. if( !saveCopy && tmpFn.GetFullPath() != screen->GetFileName() )
  960. screen->AssignNewUuid();
  961. success &= saveSchematicFile( screens.GetSheet( i ), tmpFn.GetFullPath() );
  962. }
  963. if( success )
  964. m_autoSaveRequired = false;
  965. // One or more of the modified sheets did not save correctly so update the auto save file.
  966. if( !aSaveAs && !success )
  967. success &= updateAutoSaveFile();
  968. if( aSaveAs && success )
  969. LockFile( Schematic().RootScreen()->GetFileName() );
  970. if( updateFileHistory )
  971. UpdateFileHistory( Schematic().RootScreen()->GetFileName() );
  972. // Save the sheet name map to the project file
  973. std::vector<FILE_INFO_PAIR>& sheets = Prj().GetProjectFile().GetSheets();
  974. sheets.clear();
  975. for( SCH_SHEET_PATH& sheetPath : Schematic().BuildUnorderedSheetList() )
  976. {
  977. SCH_SHEET* sheet = sheetPath.Last();
  978. wxCHECK2( sheet, continue );
  979. // Use the schematic UUID for the root sheet.
  980. if( sheet->IsRootSheet() )
  981. {
  982. screen = sheet->GetScreen();
  983. wxCHECK2( screen, continue );
  984. sheets.emplace_back( std::make_pair( screen->GetUuid(), sheet->GetName() ) );
  985. }
  986. else
  987. {
  988. sheets.emplace_back( std::make_pair( sheet->m_Uuid, sheet->GetName() ) );
  989. }
  990. }
  991. wxASSERT( filenameMap.count( Schematic().RootScreen() ) );
  992. wxFileName projectPath( filenameMap.at( Schematic().RootScreen() ) );
  993. projectPath.SetExt( FILEEXT::ProjectFileExtension );
  994. if( Prj().IsNullProject() || ( aSaveAs && !saveCopy ) )
  995. {
  996. Prj().SetReadOnly( !createNewProject );
  997. GetSettingsManager()->SaveProjectAs( projectPath.GetFullPath() );
  998. }
  999. else if( saveCopy && createNewProject )
  1000. {
  1001. GetSettingsManager()->SaveProjectCopy( projectPath.GetFullPath() );
  1002. }
  1003. else
  1004. {
  1005. saveProjectSettings();
  1006. SaveProjectLocalSettings();
  1007. }
  1008. if( !Kiface().IsSingle() )
  1009. {
  1010. WX_STRING_REPORTER backupReporter( &msg );
  1011. if( !GetSettingsManager()->TriggerBackupIfNeeded( backupReporter ) )
  1012. SetStatusText( msg, 0 );
  1013. }
  1014. updateTitle();
  1015. if( m_infoBar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE )
  1016. m_infoBar->Dismiss();
  1017. return success;
  1018. }
  1019. bool SCH_EDIT_FRAME::doAutoSave()
  1020. {
  1021. wxFileName tmpFileName = Schematic().Root().GetFileName();
  1022. wxFileName fn = tmpFileName;
  1023. wxFileName tmp;
  1024. SCH_SCREENS screens( Schematic().Root() );
  1025. // Don't run autosave if content has not been modified
  1026. if( !IsContentModified() )
  1027. return true;
  1028. bool autoSaveOk = true;
  1029. if( fn.GetPath().IsEmpty() )
  1030. tmp.AssignDir( Prj().GetProjectPath() );
  1031. else
  1032. tmp.AssignDir( fn.GetPath() );
  1033. if( !tmp.IsOk() )
  1034. return false;
  1035. if( !IsWritable( tmp ) )
  1036. return false;
  1037. wxString title = GetTitle(); // Save frame title, that can be modified by the save process
  1038. for( size_t i = 0; i < screens.GetCount(); i++ )
  1039. {
  1040. // Only create auto save files for the schematics that have been modified.
  1041. if( !screens.GetScreen( i )->IsContentModified() )
  1042. continue;
  1043. tmpFileName = fn = screens.GetScreen( i )->GetFileName();
  1044. // Auto save file name is the normal file name prefixed with GetAutoSavePrefix().
  1045. fn.SetName( FILEEXT::AutoSaveFilePrefix + fn.GetName() );
  1046. if( saveSchematicFile( screens.GetSheet( i ), fn.GetFullPath() ) )
  1047. {
  1048. // This was only an auto-save, not a real save. Reset the modified flag.
  1049. screens.GetScreen( i )->SetContentModified();
  1050. }
  1051. else
  1052. {
  1053. autoSaveOk = false;
  1054. }
  1055. }
  1056. if( autoSaveOk && updateAutoSaveFile() )
  1057. {
  1058. m_autoSaveRequired = false;
  1059. m_autoSavePending = false;
  1060. if( !Kiface().IsSingle()
  1061. && GetSettingsManager()->GetCommonSettings()->m_Backup.backup_on_autosave )
  1062. {
  1063. GetSettingsManager()->TriggerBackupIfNeeded( NULL_REPORTER::GetInstance() );
  1064. }
  1065. }
  1066. SetTitle( title );
  1067. return autoSaveOk;
  1068. }
  1069. bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType,
  1070. const STRING_UTF8_MAP* aProperties )
  1071. {
  1072. wxFileName filename( aFileName );
  1073. wxFileName newfilename;
  1074. SCH_IO_MGR::SCH_FILE_T fileType = (SCH_IO_MGR::SCH_FILE_T) aFileType;
  1075. wxCommandEvent changingEvt( EDA_EVT_SCHEMATIC_CHANGING );
  1076. ProcessEventLocally( changingEvt );
  1077. switch( fileType )
  1078. {
  1079. case SCH_IO_MGR::SCH_ALTIUM:
  1080. case SCH_IO_MGR::SCH_CADSTAR_ARCHIVE:
  1081. case SCH_IO_MGR::SCH_EAGLE:
  1082. case SCH_IO_MGR::SCH_LTSPICE:
  1083. case SCH_IO_MGR::SCH_EASYEDA:
  1084. case SCH_IO_MGR::SCH_EASYEDAPRO:
  1085. {
  1086. // We insist on caller sending us an absolute path, if it does not, we say it's a bug.
  1087. wxCHECK_MSG( filename.IsAbsolute(), false,
  1088. wxS( "Import schematic: path is not absolute!" ) );
  1089. try
  1090. {
  1091. IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( fileType ) );
  1092. DIALOG_HTML_REPORTER errorReporter( this );
  1093. WX_PROGRESS_REPORTER progressReporter( this, _( "Importing Schematic" ), 1 );
  1094. if( PROJECT_CHOOSER_PLUGIN* c_pi = dynamic_cast<PROJECT_CHOOSER_PLUGIN*>( pi.get() ) )
  1095. {
  1096. c_pi->RegisterCallback( std::bind( DIALOG_IMPORT_CHOOSE_PROJECT::RunModal,
  1097. this, std::placeholders::_1 ) );
  1098. }
  1099. if( eeconfig()->m_System.show_import_issues )
  1100. pi->SetReporter( errorReporter.m_Reporter );
  1101. else
  1102. pi->SetReporter( &NULL_REPORTER::GetInstance() );
  1103. pi->SetProgressReporter( &progressReporter );
  1104. SCH_SHEET* loadedSheet = pi->LoadSchematicFile( aFileName, &Schematic(), nullptr,
  1105. aProperties );
  1106. if( loadedSheet )
  1107. {
  1108. Schematic().SetRoot( loadedSheet );
  1109. if( errorReporter.m_Reporter->HasMessage() )
  1110. {
  1111. errorReporter.m_Reporter->Flush(); // Build HTML messages
  1112. errorReporter.ShowModal();
  1113. }
  1114. // Non-KiCad schematics do not use a drawing-sheet (or if they do, it works
  1115. // differently to KiCad), so set it to an empty one.
  1116. DS_DATA_MODEL& drawingSheet = DS_DATA_MODEL::GetTheInstance();
  1117. drawingSheet.SetEmptyLayout();
  1118. BASE_SCREEN::m_DrawingSheetFileName = "empty.kicad_wks";
  1119. newfilename.SetPath( Prj().GetProjectPath() );
  1120. newfilename.SetName( Prj().GetProjectName() );
  1121. newfilename.SetExt( FILEEXT::KiCadSchematicFileExtension );
  1122. SetScreen( GetCurrentSheet().LastScreen() );
  1123. Schematic().Root().SetFileName( newfilename.GetFullName() );
  1124. GetScreen()->SetFileName( newfilename.GetFullPath() );
  1125. GetScreen()->SetContentModified();
  1126. RecalculateConnections( nullptr, GLOBAL_CLEANUP );
  1127. // Only perform the dangling end test on root sheet.
  1128. GetScreen()->TestDanglingEnds();
  1129. }
  1130. else
  1131. {
  1132. CreateScreens();
  1133. }
  1134. }
  1135. catch( const IO_ERROR& ioe )
  1136. {
  1137. // Do not leave g_RootSheet == NULL because it is expected to be
  1138. // a valid sheet. Therefore create a dummy empty root sheet and screen.
  1139. CreateScreens();
  1140. m_toolManager->RunAction( ACTIONS::zoomFitScreen );
  1141. wxString msg = wxString::Format( _( "Error loading schematic '%s'." ), aFileName );
  1142. DisplayErrorMessage( this, msg, ioe.What() );
  1143. msg.Printf( _( "Failed to load '%s'." ), aFileName );
  1144. SetMsgPanel( wxEmptyString, msg );
  1145. }
  1146. catch( const std::exception& exc )
  1147. {
  1148. CreateScreens();
  1149. m_toolManager->RunAction( ACTIONS::zoomFitScreen );
  1150. wxString msg = wxString::Format( _( "Unhandled exception occurred loading schematic "
  1151. "'%s'." ), aFileName );
  1152. DisplayErrorMessage( this, msg, exc.what() );
  1153. msg.Printf( _( "Failed to load '%s'." ), aFileName );
  1154. SetMsgPanel( wxEmptyString, msg );
  1155. }
  1156. ClearUndoRedoList();
  1157. ClearRepeatItemsList();
  1158. initScreenZoom();
  1159. SetSheetNumberAndCount();
  1160. SyncView();
  1161. UpdateHierarchyNavigator();
  1162. wxCommandEvent e( EDA_EVT_SCHEMATIC_CHANGED );
  1163. ProcessEventLocally( e );
  1164. for( wxEvtHandler* listener : m_schematicChangeListeners )
  1165. {
  1166. wxCHECK2( listener, continue );
  1167. // Use the windows variant when handling event messages in case there is any
  1168. // special event handler pre and/or post processing specific to windows.
  1169. wxWindow* win = dynamic_cast<wxWindow*>( listener );
  1170. if( win )
  1171. win->HandleWindowEvent( e );
  1172. else
  1173. listener->SafelyProcessEvent( e );
  1174. }
  1175. updateTitle();
  1176. break;
  1177. }
  1178. default:
  1179. break;
  1180. }
  1181. return true;
  1182. }
  1183. bool SCH_EDIT_FRAME::AskToSaveChanges()
  1184. {
  1185. SCH_SCREENS screenList( Schematic().Root() );
  1186. // Save any currently open and modified project files.
  1187. for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
  1188. {
  1189. SIMULATOR_FRAME* simFrame = (SIMULATOR_FRAME*) Kiway().Player( FRAME_SIMULATOR, false );
  1190. // Simulator must be closed before loading another schematic, otherwise it may crash.
  1191. // If there are any changes in the simulator the user will be prompted to save them.
  1192. if( simFrame && !simFrame->Close() )
  1193. return false;
  1194. if( screen->IsContentModified() )
  1195. {
  1196. if( !HandleUnsavedChanges( this, _( "The current schematic has been modified. "
  1197. "Save changes?" ),
  1198. [&]() -> bool
  1199. {
  1200. return SaveProject();
  1201. } ) )
  1202. {
  1203. return false;
  1204. }
  1205. }
  1206. }
  1207. return true;
  1208. }
  1209. bool SCH_EDIT_FRAME::updateAutoSaveFile()
  1210. {
  1211. wxFileName tmpFn = Prj().GetProjectFullName();
  1212. wxFileName autoSaveFileName( tmpFn.GetPath(), getAutoSaveFileName() );
  1213. wxLogTrace( traceAutoSave, "Creating auto save file %s", autoSaveFileName.GetFullPath() );
  1214. wxCHECK( autoSaveFileName.IsDirWritable(), false );
  1215. wxFileName fn;
  1216. SCH_SCREENS screens( Schematic().Root() );
  1217. std::vector< wxString > autoSavedFiles;
  1218. for( size_t i = 0; i < screens.GetCount(); i++ )
  1219. {
  1220. // Only create auto save files for the schematics that have been modified.
  1221. if( !screens.GetScreen( i )->IsContentModified() )
  1222. continue;
  1223. fn = screens.GetScreen( i )->GetFileName();
  1224. // Auto save file name is the normal file name prefixed with GetAutoSavePrefix().
  1225. fn.SetName( FILEEXT::AutoSaveFilePrefix + fn.GetName() );
  1226. autoSavedFiles.emplace_back( fn.GetFullPath() );
  1227. }
  1228. wxTextFile autoSaveFile( autoSaveFileName.GetFullPath() );
  1229. if( autoSaveFileName.FileExists() && !wxRemoveFile( autoSaveFileName.GetFullPath() ) )
  1230. {
  1231. wxLogTrace( traceAutoSave, "Error removing auto save file %s",
  1232. autoSaveFileName.GetFullPath() );
  1233. return false;
  1234. }
  1235. // No modified sheet files to save.
  1236. if( autoSavedFiles.empty() )
  1237. return true;
  1238. if( !autoSaveFile.Create() )
  1239. return false;
  1240. for( const wxString& fileName : autoSavedFiles )
  1241. {
  1242. wxLogTrace( traceAutoSave, "Adding auto save file %s to %s",
  1243. fileName, autoSaveFileName.GetName() );
  1244. autoSaveFile.AddLine( fileName );
  1245. }
  1246. if( !autoSaveFile.Write() )
  1247. return false;
  1248. wxLogTrace( traceAutoSave, "Auto save file '%s' written", autoSaveFileName.GetFullName() );
  1249. return true;
  1250. }
  1251. void removeFile( const wxString& aFilename, wxArrayString& aUnremoved )
  1252. {
  1253. wxLogTrace( traceAutoSave, wxS( "Removing auto save file " ) + aFilename );
  1254. if( wxFileExists( aFilename ) && !wxRemoveFile( aFilename ) )
  1255. aUnremoved.Add( aFilename );
  1256. };
  1257. void SCH_EDIT_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
  1258. {
  1259. if( !Pgm().IsGUI() )
  1260. return;
  1261. wxCHECK_RET( aFileName.IsOk(), wxS( "Invalid file name!" ) );
  1262. wxLogTrace( traceAutoSave,
  1263. wxS( "Checking for auto save file " ) + aFileName.GetFullPath() );
  1264. if( !aFileName.FileExists() )
  1265. return;
  1266. wxString msg = _(
  1267. "Well this is potentially embarrassing!\n"
  1268. "It appears that the last time you were editing one or more of the schematic files\n"
  1269. "were not saved properly. Do you wish to restore the last saved edits you made?" );
  1270. int response = wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
  1271. this );
  1272. wxTextFile fileList( aFileName.GetFullPath() );
  1273. if( !fileList.Open() )
  1274. {
  1275. msg.Printf( _( "The file '%s' could not be opened.\n"
  1276. "Manual recovery of automatically saved files is required." ),
  1277. aFileName.GetFullPath() );
  1278. wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
  1279. return;
  1280. }
  1281. if( response == wxYES )
  1282. {
  1283. wxArrayString unrecoveredFiles;
  1284. for( wxString fn = fileList.GetFirstLine(); !fileList.Eof(); fn = fileList.GetNextLine() )
  1285. {
  1286. wxFileName recoveredFn = fn;
  1287. wxString tmp = recoveredFn.GetName();
  1288. // Strip "_autosave-" prefix from the auto save file name.
  1289. tmp.Replace( FILEEXT::AutoSaveFilePrefix, wxS( "" ), false );
  1290. recoveredFn.SetName( tmp );
  1291. wxFileName backupFn = recoveredFn;
  1292. backupFn.SetExt( backupFn.GetExt() + FILEEXT::BackupFileSuffix );
  1293. wxLogTrace( traceAutoSave, wxS( "Recovering auto save file:\n"
  1294. " Original file: '%s'\n"
  1295. " Backup file: '%s'\n"
  1296. " Auto save file: '%s'" ),
  1297. recoveredFn.GetFullPath(), backupFn.GetFullPath(), fn );
  1298. if( !wxFileExists( fn ) )
  1299. {
  1300. unrecoveredFiles.Add( recoveredFn.GetFullPath() );
  1301. }
  1302. // Attempt to back up the last schematic file before overwriting it with the auto
  1303. // save file.
  1304. else if( recoveredFn.Exists()
  1305. && !wxCopyFile( recoveredFn.GetFullPath(), backupFn.GetFullPath() ) )
  1306. {
  1307. unrecoveredFiles.Add( recoveredFn.GetFullPath() );
  1308. }
  1309. // Attempt to replace last saved file with auto save file
  1310. else if( !wxRenameFile( fn, recoveredFn.GetFullPath() ) )
  1311. {
  1312. unrecoveredFiles.Add( recoveredFn.GetFullPath() );
  1313. }
  1314. }
  1315. if( !unrecoveredFiles.IsEmpty() )
  1316. {
  1317. msg = _( "The following automatically saved file(s) could not be restored\n" );
  1318. for( size_t i = 0; i < unrecoveredFiles.GetCount(); i++ )
  1319. msg += unrecoveredFiles[i] + wxS( "\n" );
  1320. msg += _( "Manual recovery will be required to restore the file(s) above." );
  1321. wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION,
  1322. this );
  1323. }
  1324. wxArrayString unremovedFiles;
  1325. removeFile( aFileName.GetFullPath(), unremovedFiles );
  1326. if( !unremovedFiles.IsEmpty() )
  1327. {
  1328. msg.Printf( _( "The autosave file '%s' could not be removed.\n"
  1329. "Manual removal will be required." ),
  1330. unremovedFiles[0] );
  1331. wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
  1332. }
  1333. }
  1334. else
  1335. {
  1336. DeleteAutoSaveFile( aFileName );
  1337. }
  1338. }
  1339. void SCH_EDIT_FRAME::DeleteAutoSaveFile( const wxFileName& aFileName )
  1340. {
  1341. if( !Pgm().IsGUI() )
  1342. return;
  1343. wxCHECK_RET( aFileName.IsOk(), wxS( "Invalid file name!" ) );
  1344. if( !aFileName.FileExists() )
  1345. return;
  1346. wxTextFile fileList( aFileName.GetFullPath() );
  1347. wxArrayString unremovedFiles;
  1348. for( wxString fn = fileList.GetFirstLine(); !fileList.Eof(); fn = fileList.GetNextLine() )
  1349. removeFile( fn, unremovedFiles );
  1350. removeFile( aFileName.GetFullPath(), unremovedFiles );
  1351. if( !unremovedFiles.IsEmpty() )
  1352. {
  1353. wxString msg = _( "The following automatically saved file(s) could not be removed\n" );
  1354. for( size_t i = 0; i < unremovedFiles.GetCount(); i++ )
  1355. msg += unremovedFiles[i] + wxS( "\n" );
  1356. msg += _( "Manual removal will be required for the file(s) above." );
  1357. wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
  1358. }
  1359. }
  1360. const wxString& SCH_EDIT_FRAME::getAutoSaveFileName() const
  1361. {
  1362. static wxString autoSaveFileName( wxS( "#auto_saved_files#" ) );
  1363. return autoSaveFileName;
  1364. }