← Back to team overview

kicad-lib-committers team mailing list archive

plot component image from command line

 

Hello Everyone.

I've attached a patch that allows to eeschema plot a PNG image from given
library and component names via command line. First let me say that my
intention is not to have this patch applied to upstream KiCad code, I wrote
the patch exclusively to got this feature, I know it's wrong in many ways.
My aim here is to use it as a tool to help us (librarians) with the
evaluation of the users libraries pull requests at kicad-library.

Ideally we would have a patched kicad version running over Jenkis, similiar
with what Jon Neal has done for checking scripts.

To test it, apply the patch and run as following:

eeschema --component-png microchip_pic12mcu "PIC12(L)F1501-I/MC"

You will see the eeschema window pop up and close automatically. After this
an output.png file should have been plotted to local dir.

I'm copying the developers mail list to ask a help to guide me where to
tweak in order to prevent the windows to pop up (if possible). I've tried
to comment out some Show and Raise methods but it didn't work out. I got a
corrupted png and program did stop to close automatically.


Best Regards,
Ricardo.
diff --git a/common/single_top.cpp b/common/single_top.cpp
index c3dbe05..4b25935 100644
--- a/common/single_top.cpp
+++ b/common/single_top.cpp
@@ -277,6 +277,14 @@ bool PGM_SINGLE_TOP::OnPgmInit( wxApp* aWxApp )
         // special attention to the first argument: argv[1] (==argSet[0])
         wxFileName argv1( argSet[0] );
 
+        if( argc == 4 )
+        {
+            if ( App().argv[1] == "--component-png" )
+            {
+                frame->CreateComponentPNG( wxString(App().argv[2]), wxString(App().argv[3]) );
+            }
+        }
+
         if( argc == 2 )
         {
 #if defined(PGM_DATA_FILE_EXT)
@@ -311,7 +319,7 @@ bool PGM_SINGLE_TOP::OnPgmInit( wxApp* aWxApp )
         }
     }
 
-    frame->Show();
+    //frame->Show();
 
     return true;
 }
diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp
index 81b6d69..a492c6d 100644
--- a/eeschema/files-io.cpp
+++ b/eeschema/files-io.cpp
@@ -180,6 +180,9 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
 
     SCH_SCREENS screenList;
 
+    if( aFileSet.size() > 1 )
+        return true;
+
     // This is for python:
     if( aFileSet.size() != 1 )
     {
@@ -333,6 +336,25 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
     return true;
 }
 
+bool SCH_EDIT_FRAME::CreateComponentPNG( wxString libraryName, wxString componentName )
+{
+    wxCommandEvent dummy = wxCommandEvent( wxEVT_NULL );
+    OnOpenLibraryEditor(dummy);
+
+    LIB_EDIT_FRAME* frame = this->m_libeditFrame;
+    frame->m_libraryName = libraryName;
+    frame->m_componentName = componentName;
+
+    wxCommandEvent cmd = wxCommandEvent( wxEVT_NULL, 999 );
+    frame->LoadOneLibraryPart(cmd);
+
+    wxCommandEvent cmd2 = wxCommandEvent( wxEVT_NULL, ID_LIBEDIT_GEN_PNG_FILE );
+    frame->OnPlotCurrentComponent(cmd2);
+
+    Close();
+
+    return true;
+}
 
 bool SCH_EDIT_FRAME::AppendOneEEProject()
 {
diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp
index fe2f121..f01c216 100644
--- a/eeschema/libedit.cpp
+++ b/eeschema/libedit.cpp
@@ -111,7 +111,7 @@ bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( LIB_ALIAS* aLibEntry )
 
 void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
 {
-    wxString   cmp_name;
+    wxString   cmp_name = wxEmptyString;
     LIB_ALIAS* libEntry = NULL;
 
     m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
@@ -120,6 +120,12 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
         && !IsOK( this, _( "The current component is not saved.\n\nDiscard current changes?" ) ) )
         return;
 
+    if ( event.GetId() == 999 )
+    {
+        SelectActiveLibrary( SelectLibraryFromList( m_libraryName ) );
+        cmp_name = m_componentName;
+    }
+
     PART_LIB* lib = GetCurLib();
 
     // No current lib, ask user for the library to use.
@@ -136,8 +142,12 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
     int dummyLastUnit;
     SCHLIB_FILTER filter;
     filter.LoadFrom( lib->GetName() );
-    cmp_name = SelectComponentFromLibrary( &filter, dummyHistoryList, dummyLastUnit,
-                                          true, NULL, NULL );
+
+    if( cmp_name.IsEmpty() )
+    {
+        cmp_name = SelectComponentFromLibrary( &filter, dummyHistoryList, dummyLastUnit,
+                                              true, NULL, NULL );
+    }
 
     if( cmp_name.IsEmpty() )
         return;
diff --git a/eeschema/libedit_plot_component.cpp b/eeschema/libedit_plot_component.cpp
index ccdca67..52d0b00 100644
--- a/eeschema/libedit_plot_component.cpp
+++ b/eeschema/libedit_plot_component.cpp
@@ -70,10 +70,12 @@ void LIB_EDIT_FRAME::OnPlotCurrentComponent( wxCommandEvent& event )
             fn.SetExt( file_ext );
 
             wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
-
+#if 0
             fullFileName = EDA_FILE_SELECTOR( _( "Filename:" ), pro_dir,
                                              fn.GetFullName(), file_ext, mask, this,
                                              wxFD_SAVE, true );
+#endif
+            fullFileName = "output." + file_ext;
 
             if( fullFileName.IsEmpty() )
                 return;
diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp
index 6663cf6..10727f4 100644
--- a/eeschema/libeditframe.cpp
+++ b/eeschema/libeditframe.cpp
@@ -284,7 +284,7 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
     m_auimgr.Update();
 
     Raise();
-    Show( true );
+    Show( false );
 
     wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, ID_ZOOM_PAGE );
     wxPostEvent( this, evt );
diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h
index 06c4169..db50599 100644
--- a/eeschema/libeditframe.h
+++ b/eeschema/libeditframe.h
@@ -128,6 +128,7 @@ class LIB_EDIT_FRAME : public SCH_BASE_FRAME
     LIB_ITEM* locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] );
 
 public:
+    wxString m_libraryName, m_componentName;
 
     LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
 
diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h
index c99e1a6..1a44aea 100644
--- a/eeschema/sch_base_frame.h
+++ b/eeschema/sch_base_frame.h
@@ -194,7 +194,7 @@ protected:
      * This list is sorted, with the library cache always at end of the list
      * @return a reference to the selected library, or NULL
      */
-    PART_LIB* SelectLibraryFromList();
+    PART_LIB* SelectLibraryFromList(wxString libname=wxEmptyString);
 
     /**
      * Function SelectPartNameToLoad
diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp
index ecd775f..acd49c5 100644
--- a/eeschema/schframe.cpp
+++ b/eeschema/schframe.cpp
@@ -1140,7 +1140,7 @@ void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event )
     if( !libeditFrame )
     {
         libeditFrame = (LIB_EDIT_FRAME*) Kiway().Player( FRAME_SCH_LIB_EDITOR, true );
-        libeditFrame->Show( true );
+        libeditFrame->Show( false );
     }
 
     libeditFrame->PushPreferences( m_canvas );
@@ -1166,6 +1166,8 @@ void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event )
         }
     }
 
+    m_libeditFrame = libeditFrame;
+
     GetScreen()->SchematicCleanUp();
     m_canvas->Refresh();
 }
diff --git a/eeschema/schframe.h b/eeschema/schframe.h
index 59f65cf..aca4391 100644
--- a/eeschema/schframe.h
+++ b/eeschema/schframe.h
@@ -179,6 +179,9 @@ private:
     static wxSize   m_lastSheetPinTextSize;         ///< Last sheet pin text size.
     static wxPoint  m_lastSheetPinPosition;         ///< Last sheet pin position.
 
+    /// used for --component-png option
+    wxString    m_libraryPath, m_componentName;
+
 protected:
     TEMPLATES             m_TemplateFieldNames;
 
@@ -230,6 +233,7 @@ protected:
     void sendNetlist();
 
 public:
+    LIB_EDIT_FRAME* m_libeditFrame;
     SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
     ~SCH_EDIT_FRAME();
 
@@ -765,6 +769,8 @@ public:
 
     bool IsSearchCacheObsolete( const SCH_FIND_REPLACE_DATA& aSearchCriteria );
 
+    bool CreateComponentPNG( wxString libraryName, wxString componentName );
+
 
 private:
 
diff --git a/eeschema/selpart.cpp b/eeschema/selpart.cpp
index b0b3629..ed495b3 100644
--- a/eeschema/selpart.cpp
+++ b/eeschema/selpart.cpp
@@ -54,7 +54,7 @@ static void DisplayCmpDocAndKeywords( wxString& aName, void* aData )
 }
 
 
-PART_LIB* SCH_BASE_FRAME::SelectLibraryFromList()
+PART_LIB* SCH_BASE_FRAME::SelectLibraryFromList(wxString libname)
 {
     PROJECT&    prj = Prj();
 
@@ -88,10 +88,13 @@ PART_LIB* SCH_BASE_FRAME::SelectLibraryFromList()
 
         EDA_LIST_DIALOG dlg( this, _( "Select Library" ), headers, itemsToDisplay, old_lib_name );
 
-        if( dlg.ShowModal() != wxID_OK )
-            return NULL;
+        if ( !libname )
+        {
+            if( dlg.ShowModal() != wxID_OK )
+                return NULL;
 
-        wxString libname = dlg.GetTextSelection();
+            libname = dlg.GetTextSelection();
+        }
 
         if( !libname )
             return NULL;
diff --git a/include/kiway_player.h b/include/kiway_player.h
index eeff8a5..7810bbd 100644
--- a/include/kiway_player.h
+++ b/include/kiway_player.h
@@ -175,6 +175,11 @@ public:
         return false;
     }
 
+    VTBL_ENTRY bool CreateComponentPNG( wxString libraryName, wxString componentName )
+    {
+        return false;
+    }
+
     /**
      * Function ShowModal
      * puts up this wxFrame as if it were a modal dialog, with all other instantiated
diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp
index 6dd3677..6943386 100644
--- a/kicad/kicad.cpp
+++ b/kicad/kicad.cpp
@@ -195,7 +195,7 @@ bool PGM_KICAD::OnPgmInit( wxApp* aWxApp )
         frame->OnLoadProject( cmd );
     }
 
-    frame->Show( true );
+    //frame->Show( true );
     frame->Raise();
 
     return true;

Follow ups