Eeschema: Add CheckHeader function to SCH_PLUGIN and cycle through plugins when loading files.

This commit is contained in:
Russell Oliver 2017-06-21 22:41:00 +10:00 committed by Maciej Suminski
parent e03bc32e49
commit 4e69acbb49
7 changed files with 55 additions and 21 deletions

View File

@ -47,6 +47,7 @@
#include <project_rescue.h>
#include <eeschema_config.h>
#include <sch_legacy_plugin.h>
#include <sch_eagle_plugin.h>
//#define USE_SCH_LEGACY_IO_PLUGIN
@ -315,30 +316,13 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
delete g_RootSheet; // Delete the current project.
g_RootSheet = NULL; // Force CreateScreens() to build new empty project on load failure.
// Open file and guess at filetype Kicad/Eagle
wxTextFile tempFile;
tempFile.Open( fullFileName );
wxString firstline;
// read the first line
firstline = tempFile.GetFirstLine();
tempFile.Close();
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
SCH_IO_MGR::SCH_FILE_T filetype;
if( firstline.StartsWith( "<?xml" ) )
// cycle through plugins as they are added to Eeschema
if( !pi->CheckHeader( fullFileName ) )
{
filetype = SCH_IO_MGR::SCH_EAGLE;
pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) );
}
else if( firstline.StartsWith( "(schematic" ) )
{
filetype = SCH_IO_MGR::SCH_KICAD;
}
else
{
filetype = SCH_IO_MGR::SCH_LEGACY;
}
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( filetype ) );
try
{

View File

@ -835,6 +835,21 @@ LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymboltext( LIB_PART* aPart, wxXmlNode* aLibText
}
bool SCH_EAGLE_PLUGIN::CheckHeader( const wxString& aFileName )
{
// Open file and check first line
wxTextFile tempFile;
tempFile.Open( aFileName );
wxString firstline;
// read the first line
firstline = tempFile.GetFirstLine();
tempFile.Close();
return firstline.StartsWith( "<?xml" );
}
void SCH_EAGLE_PLUGIN::Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
const PROPERTIES* aProperties )
{

View File

@ -108,6 +108,7 @@ public:
void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override;
bool CheckHeader( const wxString& aFileName ) override;
private:
void loadDrawing( wxXmlNode* aDrawingNode );

View File

@ -484,6 +484,16 @@ public:
*/
virtual void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const;
/**
* Function CheckHeader
* returns true if the first line in @a aFileName begins with the expected header
* system libraries are read only because of where they are installed.)
*
* @param aFileName is the name of the file to use as input
*
*/
virtual bool CheckHeader( const wxString& aFileName );
//-----</PUBLIC SCH_PLUGIN API>------------------------------------------------

View File

@ -3604,5 +3604,19 @@ void SCH_LEGACY_PLUGIN::SaveLibrary( const wxString& aLibraryPath, const PROPERT
}
bool SCH_LEGACY_PLUGIN::CheckHeader( const wxString& aFileName )
{
// Open file and check first line
wxTextFile tempFile;
tempFile.Open( aFileName );
wxString firstline;
// read the first line
firstline = tempFile.GetFirstLine();
tempFile.Close();
return firstline.StartsWith( "EESchema" );
}
const char* SCH_LEGACY_PLUGIN::PropBuffering = "buffering";
const char* SCH_LEGACY_PLUGIN::PropNoDocFile = "no_doc_file";

View File

@ -124,6 +124,8 @@ public:
const PROPERTIES* aProperties = NULL ) override;
void SaveLibrary( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL ) override;
bool CheckHeader(const wxString& aFileName) override;
private:
void loadHierarchy( SCH_SHEET* aSheet );
void loadHeader( FILE_LINE_READER& aReader, SCH_SCREEN* aScreen );

View File

@ -188,3 +188,11 @@ void SCH_PLUGIN::SymbolLibOptions( PROPERTIES* aListToAppendTo ) const
) );
#endif
}
bool SCH_PLUGIN::CheckHeader( const wxString& aFileName )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
return NULL;
}