Added 'Import Non-KiCad Schematic'

This commit is contained in:
Maciej Suminski 2017-09-20 16:20:38 +02:00
parent 6b44d12bd8
commit d617021d98
5 changed files with 75 additions and 33 deletions

View File

@ -60,6 +60,7 @@ enum id_eeschema_frm
{
ID_UPDATE_ONE_SHEET = ID_END_LIST,
ID_SAVE_ONE_SHEET_UNDER_NEW_NAME,
ID_IMPORT_NON_KICAD_SCH,
/* Schematic editor main menubar IDs. */
ID_RESCUE_CACHED,

View File

@ -191,8 +191,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
{
// implement the pseudo code from KIWAY_PLAYER.h:
SCH_SCREENS screenList;
// This is for python:
if( aFileSet.size() != 1 )
{
@ -217,34 +215,8 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
return false;
}
// Save any currently open and modified project files.
for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
{
if( screen->IsModify() )
{
int response = YesNoCancelDialog( this, _(
"The current schematic has been modified. Do you wish to save the changes?" ),
wxEmptyString,
_( "Save and Load" ),
_( "Load Without Saving" )
);
if( response == wxID_CANCEL )
{
return false;
}
else if( response == wxID_YES )
{
wxCommandEvent dummy;
OnSaveProject( dummy );
}
else
{
// response == wxID_NO, fall thru
}
break;
}
}
if( !AskToSaveChanges() )
return false;
wxFileName pro = fullFileName;
pro.SetExt( ProjectFileExtension );
@ -399,7 +371,7 @@ bool SCH_EDIT_FRAME::AppendOneEEProject()
// open file chooser dialog
wxString path = wxPathOnly( Prj().GetProjectFullName() );
wxFileDialog dlg( this, _( "Import Schematic" ), path,
wxFileDialog dlg( this, _( "Append Schematic" ), path,
wxEmptyString, SchematicFileWildcard,
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
@ -533,6 +505,25 @@ void SCH_EDIT_FRAME::OnAppendProject( wxCommandEvent& event )
}
void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent )
{
if( !AskToSaveChanges() )
return;
wxString path = wxPathOnly( Prj().GetProjectFullName() );
wxFileDialog dlg( this, _( "Import Schematic" ), path,
wxEmptyString, EagleSchematicFileWildcard,
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL )
return;
// For now there is only one import plugin
ImportFile( dlg.GetPath(), SCH_IO_MGR::SCH_EAGLE );
}
void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent )
{
SCH_SCREEN* screen;
@ -668,3 +659,38 @@ bool SCH_EDIT_FRAME::ImportFile( const wxString& aFileName, int aFileType )
return false;
}
bool SCH_EDIT_FRAME::AskToSaveChanges()
{
SCH_SCREENS screenList;
// Save any currently open and modified project files.
for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
{
if( screen->IsModify() )
{
int response = YesNoCancelDialog( m_parent, _(
"The current schematic has been modified. Do you wish to save the changes?" ),
wxEmptyString,
_( "Save and Load" ),
_( "Load Without Saving" )
);
if( response == wxID_CANCEL )
{
return false;
}
else if( response == wxID_YES )
{
wxCommandEvent dummy;
OnSaveProject( dummy );
}
// else wxID_NO, so do not save
break;
}
}
return true;
}

View File

@ -338,10 +338,15 @@ void prepareFilesMenu( wxMenu* aParentMenu, bool aIsOutsideProject )
}
AddMenuItem( aParentMenu,
ID_APPEND_PROJECT, _( "Imp&ort Schematic Sheet Content" ),
_( "Import schematic sheet content from other project in current sheet" ),
ID_APPEND_PROJECT, _( "App&end Schematic Sheet" ),
_( "Import schematic sheet content from another project to current sheet" ),
KiBitmap( open_document_xpm ) );
AddMenuItem( aParentMenu,
ID_IMPORT_NON_KICAD_SCH, _( "&Import Non-Kicad Schematic File" ),
_( "Import schematic file from other applications" ),
KiBitmap( open_document_xpm ) ); // TODO needs a different icon
aParentMenu->AppendSeparator();
text = AddHotkeyName( _( "&Save Schematic Project" ),

View File

@ -223,6 +223,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, SCH_EDIT_FRAME::OnLoadFile )
EVT_MENU( ID_APPEND_PROJECT, SCH_EDIT_FRAME::OnAppendProject )
EVT_MENU( ID_IMPORT_NON_KICAD_SCH, SCH_EDIT_FRAME::OnImportProject )
EVT_TOOL( ID_NEW_PROJECT, SCH_EDIT_FRAME::OnNewProject )
EVT_TOOL( ID_LOAD_PROJECT, SCH_EDIT_FRAME::OnLoadProject )

View File

@ -793,6 +793,14 @@ public:
*/
bool ImportFile( const wxString& aFileName, int aFileType ) override;
/**
* Checks whether any of the screens has unsaved changes and asks the user
* whether to save or drop them.
* @return True if user decided to save or drop changes, false if the
* operation should be cancelled.
*/
bool AskToSaveChanges();
private:
/**
@ -876,6 +884,7 @@ private:
void OnNewProject( wxCommandEvent& event );
void OnLoadProject( wxCommandEvent& event );
void OnAppendProject( wxCommandEvent& event );
void OnImportProject( wxCommandEvent& event );
void OnOpenPcbnew( wxCommandEvent& event );
void OnOpenPcbModuleEditor( wxCommandEvent& event );
void OnOpenCvpcb( wxCommandEvent& event );