← Back to team overview

kicad-developers team mailing list archive

Append schematic feature in Eeschema

 

Hi,

I have noticed there is a feature in Pcbnew, "Append board", to add all
the components from a .brd file into the currently opened document. This
feature doesn't exist in Eeschema but I thought it would be useful there
too.

The attached patch adds this feature linked to a new entry in the "File"
menu.

-- 
Jacobo
=== modified file 'eeschema/files-io.cpp'
--- eeschema/files-io.cpp	2012-09-28 17:47:41 +0000
+++ eeschema/files-io.cpp	2012-12-12 10:51:18 +0000
@@ -353,6 +353,50 @@
 }
 
 
+bool SCH_EDIT_FRAME::AppendOneEEProject()
+{
+    SCH_SCREEN* screen;
+    wxString    FullFileName;
+
+    screen = GetScreen();
+
+    if( !screen )
+    {
+        wxLogError( wxT("Document not ready, cannot import") );
+        return false;
+    }
+
+    wxFileDialog dlg( this, _( "Import Schematic" ), wxGetCwd(),
+                      wxEmptyString, SchematicFileWildcard,
+                      wxFD_OPEN | wxFD_FILE_MUST_EXIST );
+
+    if( dlg.ShowModal() == wxID_CANCEL )
+        return false;
+
+    FullFileName = dlg.GetPath();
+
+    wxFileName fn = FullFileName;
+
+    if( fn.IsRelative() )
+    {
+        fn.MakeAbsolute();
+        FullFileName = fn.GetFullPath();
+    }
+
+    wxLogDebug( wxT( "Importing schematic " ) + FullFileName );
+
+    // load the project.
+    bool success = LoadOneEEFile( screen, FullFileName);
+
+    /* Redraw base screen (ROOT) if necessary. */
+    GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
+    Zoom_Automatique( false );
+    SetSheetNumberAndCount();
+    m_canvas->Refresh( true );
+    return success;
+}
+
+
 void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent )
 {
     SCH_SCREEN* screen;

=== modified file 'eeschema/menubar.cpp'
--- eeschema/menubar.cpp	2012-09-28 17:47:41 +0000
+++ eeschema/menubar.cpp	2012-12-12 10:51:18 +0000
@@ -97,6 +97,12 @@
                  _( "Open a recent opened schematic project" ),
                  KiBitmap( open_project_xpm ) );
 
+    // Import
+    AddMenuItem( fileMenu,
+                 ID_APPEND_PROJECT, _( "&Append Schematic" ),
+                 _( "Append another schematic project to the current loaded schematic" ),
+                 KiBitmap( open_document_xpm ) );
+
     // Separator
     fileMenu->AppendSeparator();
 

=== modified file 'eeschema/schframe.cpp'
--- eeschema/schframe.cpp	2012-12-10 19:08:09 +0000
+++ eeschema/schframe.cpp	2012-12-12 10:51:18 +0000
@@ -75,6 +75,8 @@
 
     EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, SCH_EDIT_FRAME::OnLoadFile )
 
+    EVT_MENU( ID_APPEND_PROJECT, SCH_EDIT_FRAME::OnAppendProject )
+
     EVT_TOOL( ID_NEW_PROJECT, SCH_EDIT_FRAME::OnNewProject )
     EVT_TOOL( ID_LOAD_PROJECT, SCH_EDIT_FRAME::OnLoadProject )
 
@@ -735,6 +737,12 @@
 }
 
 
+void SCH_EDIT_FRAME::OnAppendProject( wxCommandEvent& event )
+{
+    AppendOneEEProject();
+}
+
+
 void SCH_EDIT_FRAME::OnOpenPcbnew( wxCommandEvent& event )
 {
     wxFileName fn = g_RootSheet->GetScreen()->GetFileName();

=== modified file 'include/id.h'
--- include/id.h	2012-10-14 16:57:11 +0000
+++ include/id.h	2012-12-12 10:51:18 +0000
@@ -47,6 +47,7 @@
     ID_TO_PCB = wxID_HIGHEST,
     ID_TO_CVPCB,
     ID_LOAD_PROJECT,
+    ID_APPEND_PROJECT,
     ID_NEW_PROJECT,
     ID_NEW_PROJECT_FROM_TEMPLATE,
     ID_SAVE_PROJECT,

=== modified file 'include/wxEeschemaStruct.h'
--- include/wxEeschemaStruct.h	2012-09-28 18:45:04 +0000
+++ include/wxEeschemaStruct.h	2012-12-12 10:51:18 +0000
@@ -631,6 +631,14 @@
     bool LoadOneEEProject( const wxString& aFileName, bool aIsNew );
 
     /**
+     * Function AppendOneEEProject
+     * read an entire project and loads it into the schematic editor *whitout* replacing the
+     * existing contents.
+     * @return True if the project was imported properly.
+     */
+    bool AppendOneEEProject();
+
+    /**
      * Function LoadOneEEFile
      * loads the schematic (.sch) file \a aFullFileName into \a aScreen.
      *
@@ -746,6 +754,7 @@
     void OnLoadStuffFile( wxCommandEvent& event );
     void OnNewProject( wxCommandEvent& event );
     void OnLoadProject( wxCommandEvent& event );
+    void OnAppendProject( wxCommandEvent& event );
     void OnOpenPcbnew( wxCommandEvent& event );
     void OnOpenCvpcb( wxCommandEvent& event );
     void OnOpenLibraryEditor( wxCommandEvent& event );


Follow ups