Add CADSTAR_SCH_ARCHIVE_PLUGIN::CanReadLibrary

This commit is contained in:
Alex Shvartzkop 2023-11-08 23:37:38 +03:00
parent 819c0f2082
commit d016f596f5
2 changed files with 32 additions and 0 deletions

View File

@ -38,6 +38,8 @@
#include <wildcards_and_files_ext.h>
#include <wx_filename.h>
#include <wx/dir.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
const wxString CADSTAR_SCH_ARCHIVE_PLUGIN::GetName() const
@ -46,6 +48,34 @@ const wxString CADSTAR_SCH_ARCHIVE_PLUGIN::GetName() const
}
bool CADSTAR_SCH_ARCHIVE_PLUGIN::CanReadLibrary( const wxString& aFileName ) const
{
if( !SCH_PLUGIN::CanReadLibrary( aFileName ) )
return false;
wxFFileInputStream input( aFileName );
if( !input.IsOk() || input.Eof() )
return false;
// Find first non-empty line
wxTextInputStream text( input );
wxString line = text.ReadLine();
while( !input.Eof() && line.IsEmpty() )
line = text.ReadLine().Trim( false /*trim from left*/ );
// CADSTAR libs start with
// # FORMAT 32
// or
// .PartName :2 ;Part 0 Description
if( line.StartsWith( wxS( "#" ) ) || line.StartsWith( wxS( "." ) ) )
return true;
return false;
}
int CADSTAR_SCH_ARCHIVE_PLUGIN::GetModifyHash() const
{
return 0;

View File

@ -70,6 +70,8 @@ public:
{ CadstarPartsLibraryFileExtension } );
}
bool CanReadLibrary( const wxString& aFileName ) const override;
int GetModifyHash() const override;
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,