← Back to team overview

kicad-developers team mailing list archive

[RFC][PATCH] import pins from CSV

 

I've not submitted a patch before nor really used a mailing list, so please let
me know if I did something wrong.

This adds a button on the component editor toolbar that prompts for a csv file,
and then reads pin numbers and names and generates pins.

I decided to start with something small but a few potential avenues for
improvement I can see are:
- adding a parser for electrical type based on regex
- integrating this into it's own dialog with selectors for parsing options,
  default pin direction
- moving the button from the toolbar to the pin table, or even more integration
  of some sort with pin table

I tested it on linux and there is a build that will hopefully finish soon here:
http://ci.kicad-pcb.org/job/windows-kicad-msys2-patch/560/

Cheers,
Alex
---
 bitmaps_png/CMakeLists.txt         |   1 +
 bitmaps_png/cpp_26/import_csv.cpp  |  59 ++++++++++++++
 bitmaps_png/sources/import_csv.svg | 152 +++++++++++++++++++++++++++++++++++++
 eeschema/eeschema_id.h             |   1 +
 eeschema/libeditframe.cpp          | 115 ++++++++++++++++++++++++++++
 eeschema/libeditframe.h            |  13 +++-
 eeschema/pinedit.cpp               |  11 ++-
 eeschema/tool_lib.cpp              |   2 +
 include/bitmaps.h                  |   1 +
 9 files changed, 349 insertions(+), 6 deletions(-)
 create mode 100644 bitmaps_png/cpp_26/import_csv.cpp
 create mode 100644 bitmaps_png/sources/import_csv.svg

diff --git a/bitmaps_png/CMakeLists.txt b/bitmaps_png/CMakeLists.txt
index 41097a3..68d6fae 100644
--- a/bitmaps_png/CMakeLists.txt
+++ b/bitmaps_png/CMakeLists.txt
@@ -288,6 +288,7 @@ set( BMAPS_MID
     image
     import_brd_file
     import_cmp_from_lib
+    import_csv
     import_footprint_names
     import_hierarchical_label
     import_module
diff --git a/bitmaps_png/cpp_26/import_csv.cpp b/bitmaps_png/cpp_26/import_csv.cpp
new file mode 100644
index 0000000..e284a72
--- /dev/null
+++ b/bitmaps_png/cpp_26/import_csv.cpp
@@ -0,0 +1,59 @@
+
+/* Do not modify this file, it was automatically generated by the
+ * PNG2cpp CMake script, using a *.png file as input.
+ */
+
+#include <bitmaps.h>
+
+static const unsigned char png[] = {
+ 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 0x4e, 0x44, 0xae, 0x42, 0x60,
+ 0x82,
+};
+
+const BITMAP_OPAQUE import_csv_xpm[1] = {{ png, sizeof( png ), "import_csv_xpm" }};
+
+//EOF
diff --git a/bitmaps_png/sources/import_csv.svg b/bitmaps_png/sources/import_csv.svg
new file mode 100644
index 0000000..940ffa9
--- /dev/null
+++ b/bitmaps_png/sources/import_csv.svg
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/";
+   xmlns:cc="http://creativecommons.org/ns#";
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+   xmlns:svg="http://www.w3.org/2000/svg";
+   xmlns="http://www.w3.org/2000/svg";
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
+   viewBox="0 0 26 26"
+   id="svg2"
+   version="1.1"
+   width="26"
+   height="26"
+   inkscape:version="0.91 r13725"
+   sodipodi:docname="import_csv.svg"
+   inkscape:export-filename="/home/alex/code/kicad/bitmaps_png/sources/import_csv3.png"
+   inkscape:export-xdpi="90"
+   inkscape:export-ydpi="90">
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1855"
+     inkscape:window-height="1056"
+     id="namedview29"
+     showgrid="true"
+     inkscape:zoom="22.627417"
+     inkscape:cx="4.3947345"
+     inkscape:cy="11.871002"
+     inkscape:window-x="65"
+     inkscape:window-y="24"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="svg2">
+    <inkscape:grid
+       type="xygrid"
+       id="grid3357" />
+  </sodipodi:namedview>
+  <metadata
+     id="metadata87">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage"; />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <defs
+     id="defs4" />
+  <circle
+     r="4"
+     cy="7"
+     cx="-6"
+     transform="scale(-1,1)"
+     id="path3003"
+     style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#800000;stroke-width:1.88976383;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+     inkscape:export-xdpi="90"
+     inkscape:export-ydpi="90" />
+  <path
+     id="path3771"
+     d="M 11,7 24,7"
+     style="fill:none;stroke:#800000;stroke-width:1.88976383;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+     inkscape:export-xdpi="90"
+     inkscape:export-ydpi="90" />
+  <g
+     id="g17"
+     transform="matrix(2.4566,0,0,2.2316,-37.589,-61.022)"
+     inkscape:export-xdpi="90"
+     inkscape:export-ydpi="90">
+    <rect
+       style="fill-opacity:0"
+       id="rect19"
+       x="0"
+       y="0"
+       width="16"
+       height="16" />
+  </g>
+  <g
+     id="g47"
+     transform="matrix(2.6586,0,0,2.1996,5.9761,-10.078)"
+     inkscape:export-xdpi="90"
+     inkscape:export-ydpi="90">
+    <rect
+       style="fill-opacity:0"
+       id="rect49"
+       x="0"
+       y="0"
+       width="16"
+       height="16" />
+  </g>
+  <g
+     transform="matrix(2.4482476,0,0,2.4295429,2.830298,-7.57155)"
+     id="g69"
+     inkscape:export-xdpi="90"
+     inkscape:export-ydpi="90">
+    <rect
+       height="16"
+       width="16"
+       y="0"
+       x="0"
+       id="rect71"
+       style="fill-opacity:0" />
+  </g>
+  <g
+     transform="matrix(2.4482476,0,0,2.4295429,5.162342,-14.86007)"
+     id="g73"
+     inkscape:export-xdpi="90"
+     inkscape:export-ydpi="90">
+    <rect
+       height="16"
+       width="16"
+       y="0"
+       x="0"
+       id="rect75"
+       style="fill-opacity:0" />
+  </g>
+  <text
+     xml:space="preserve"
+     style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+     x="16.6875"
+     y="23.4375"
+     id="text3451"
+     sodipodi:linespacing="125%"
+     inkscape:export-xdpi="90"
+     inkscape:export-ydpi="90"><tspan
+       sodipodi:role="line"
+       id="tspan3453"
+       x="16.6875"
+       y="23.4375" /></text>
+  <text
+     xml:space="preserve"
+     style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.40000001;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+     x="1.3125"
+     y="22.96875"
+     id="text3455"
+     sodipodi:linespacing="125%"
+     inkscape:export-xdpi="90"
+     inkscape:export-ydpi="90"><tspan
+       sodipodi:role="line"
+       id="tspan3457"
+       x="1.3125"
+       y="22.96875"
+       style="font-size:13.75px;fill:#800000;fill-opacity:1;stroke:#000000;stroke-width:0.40000001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">csv</tspan></text>
+</svg>
diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h
index 85f50d5..cb8c649 100644
--- a/eeschema/eeschema_id.h
+++ b/eeschema/eeschema_id.h
@@ -194,6 +194,7 @@ enum id_eeschema_frm
     ID_DE_MORGAN_CONVERT_BUTT,
     ID_LIBEDIT_EDIT_PIN_BY_PIN,
     ID_LIBEDIT_EDIT_PIN_BY_TABLE,
+    ID_LIBEDIT_IMPORT_CSV,
     ID_LIBEDIT_VIEW_DOC,
     ID_LIBEDIT_CHECK_PART,
 
diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp
index 7f0fcc8..6329550 100644
--- a/eeschema/libeditframe.cpp
+++ b/eeschema/libeditframe.cpp
@@ -107,6 +107,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
     EVT_TOOL( ID_LIBEDIT_VIEW_DOC, LIB_EDIT_FRAME::OnViewEntryDoc )
     EVT_TOOL( ID_LIBEDIT_EDIT_PIN_BY_PIN, LIB_EDIT_FRAME::Process_Special_Functions )
     EVT_TOOL( ID_LIBEDIT_EDIT_PIN_BY_TABLE, LIB_EDIT_FRAME::OnOpenPinTable )
+    EVT_TOOL( ID_LIBEDIT_IMPORT_CSV, LIB_EDIT_FRAME::OnOpenImportCSV )
     EVT_TOOL( ExportPartId, LIB_EDIT_FRAME::OnExportPart )
     EVT_TOOL( CreateNewLibAndSavePartId, LIB_EDIT_FRAME::OnExportPart )
     EVT_TOOL( ImportPartId, LIB_EDIT_FRAME::OnImportPart )
@@ -1420,3 +1421,117 @@ bool LIB_EDIT_FRAME::SynchronizePins()
     return !m_editPinsPerPartOrConvert && ( part &&
         ( part->HasConversion() || part->IsMulti() ) );
 }
+
+void LIB_EDIT_FRAME::OnOpenImportCSV( wxCommandEvent& aEvent )
+{
+    const wxString CSVFileWildcard( _("Comma separated value file (*.csv)|*csv") );
+
+    // Create dialog to get name of CSV file
+    wxFileDialog openFileDialog( this, _("Select CSV File to Import Pins"),
+        wxEmptyString, wxEmptyString,
+        CSVFileWildcard, wxFD_OPEN );
+
+    if( openFileDialog.ShowModal() == wxID_CANCEL )
+        return;
+
+    LIB_PART*      part = GetCurPart();
+
+    if( !part )
+        return;
+
+    // If file doesn't exist, bail out
+    if( !wxFileExists( openFileDialog.GetPath() ) )
+    {
+      wxString msg = wxString::Format( _(
+              "File %s not found" ),
+              GetChars( openFileDialog.GetPath() )
+              );
+      DisplayError( this, msg );
+      return;
+    }
+
+    // Read raw CSV data
+    wxFile csv_file(openFileDialog.GetPath());
+    // There was an error opening the file
+    if (!csv_file.IsOpened()) {
+        wxString msg = wxString::Format( _(
+            "There was an error opening the file %s" ),
+            GetChars( openFileDialog.GetPath() )
+            );
+        DisplayError( this, msg );
+        return;
+    }
+    wxString file_contents;
+    if (!csv_file.ReadAll( &file_contents )) return;
+
+    // pins vector holds the parsed contents of the entire file
+    std::vector<std::vector<wxString>> pins;
+
+    // First split the file by newline
+    wxStringTokenizer tokenizer1(file_contents,"\r\n");
+    while (tokenizer1.HasMoreTokens())
+    {
+        wxString line = tokenizer1.GetNextToken();
+        // pin vector holds the parsed contents of one line of the file
+        std::vector<wxString> pin;
+
+        // Split this line by comma
+        wxStringTokenizer tokenizer2(line,",");
+        while (tokenizer2.HasMoreTokens())
+        {
+            wxString property = tokenizer2.GetNextToken();
+
+            // Strip quotation marks now that they've served their purpose
+            property.Replace( _("\""), wxEmptyString );
+            // Add it to our vector
+            pin.push_back( property );
+        }
+        pins.push_back( pin );
+    }
+    // Parsing complete.
+
+    // I don't know what this does
+    part->ClearStatus();
+
+    // Pin location is arbitray. Calculate spacing to put them
+    // in a big vertical column. Easy to move them around, rotate, etc. afterwards
+    unsigned int num_pins = pins.size();
+    int pin_spacing = 100;
+    int pins_offset = (num_pins / 2) * pin_spacing + (pin_spacing / 2);
+
+    // This iterates through each pin that was read
+    // and adds it to the part
+    for (std::vector<wxString>::size_type i = 0; i != num_pins; i++)
+    {
+        std::vector<wxString> csv_pin = pins[i];
+        LIB_PIN* pin = new LIB_PIN( part );
+
+        wxString pin_num = csv_pin[0];
+        wxString pin_name = csv_pin[1];
+
+        // Not sure what this does but the whole thing breaks without it
+        m_drawItem = pin;
+
+        // Set all defaults. Eventually it would be nice to have these in a GUI
+        pin->SetFlags( IS_NEW );
+        pin->SetUnit( m_unit );
+        pin->SetConvert( m_convert );
+        pin->SetLength( GetDefaultPinLength() );
+        pin->SetOrientation( PIN_LEFT );
+        pin->SetType( PIN_INPUT );
+        pin->SetShape( PINSHAPE_LINE );
+        pin->SetNameTextSize( GetPinNameDefaultSize() );
+        pin->SetNumberTextSize( GetPinNumDefaultSize() );
+        pin->SetConvert( false );
+        pin->SetUnit( false );
+        pin->SetVisible( true );
+
+        pin->SetName( pin_name );
+        pin->SetNumber( pin_num );
+
+        int pin_y = i*pin_spacing - pins_offset;
+        PlacePinLocation( wxPoint( 300, pin_y ) );
+    }
+
+    return;
+}
\ No newline at end of file
diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h
index 878cfd3..74ff4f5 100644
--- a/eeschema/libeditframe.h
+++ b/eeschema/libeditframe.h
@@ -37,6 +37,8 @@
 #include <lib_draw_item.h>
 #include <lib_collectors.h>
 
+#include <wx/tokenzr.h> // String tokenizer for CSV support
+
 
 class SCH_EDIT_FRAME;
 class PART_LIB;
@@ -281,6 +283,7 @@ public:
 
     void OnOpenPinTable( wxCommandEvent& aEvent );
 
+    void OnOpenImportCSV( wxCommandEvent& aEvent );
     void OnUpdateSelectTool( wxUpdateUIEvent& aEvent );
     void OnUpdateEditingPart( wxUpdateUIEvent& event );
     void OnUpdateNotEditingPart( wxUpdateUIEvent& event );
@@ -642,12 +645,18 @@ public:
 
     /**
      * Function PlacePin
-     * Place at cursor location the pin currently moved (i.e. pin pointed by m_drawItem)
-     * (and the linked pins, if any)
+     * Shim function that calls PlacePinLocation with GetCrossHairPosition as param
      */
     void PlacePin();
 
     /**
+     * Function PlacePin
+     * Place at specified location the pin currently moved (i.e. pin pointed by m_drawItem)
+     * (and the linked pins, if any)
+     */
+    void PlacePinLocation(wxPoint);
+
+    /**
      * Function GlobalSetPins
      * @param aMasterPin is the "template" pin
      * @param aId is a param to select what should be mofified:
diff --git a/eeschema/pinedit.cpp b/eeschema/pinedit.cpp
index ef97672..f826dd4 100644
--- a/eeschema/pinedit.cpp
+++ b/eeschema/pinedit.cpp
@@ -235,16 +235,21 @@ static void AbortPinMove( EDA_DRAW_PANEL* Panel, wxDC* DC )
 }
 
 
+void LIB_EDIT_FRAME::PlacePin()
+{
+    PlacePinLocation(GetCrossHairPosition( true ));
+}
 /**
  * Managed cursor callback for placing component pins.
  */
-void LIB_EDIT_FRAME::PlacePin()
+void LIB_EDIT_FRAME::PlacePinLocation(wxPoint newpos)
 {
     LIB_PIN* cur_pin  = (LIB_PIN*) m_drawItem;
     bool     ask_for_pin = true;
-    wxPoint  newpos;
     bool     status;
 
+
+
     // Some tests
     if( !cur_pin || cur_pin->Type() != LIB_PIN_T )
     {
@@ -252,8 +257,6 @@ void LIB_EDIT_FRAME::PlacePin()
         return;
     }
 
-    newpos = GetCrossHairPosition( true );
-
     LIB_PART*      part = GetCurPart();
 
     // Test for an other pin in same new position:
diff --git a/eeschema/tool_lib.cpp b/eeschema/tool_lib.cpp
index 7f5a25c..5914e14 100644
--- a/eeschema/tool_lib.cpp
+++ b/eeschema/tool_lib.cpp
@@ -214,6 +214,8 @@ void LIB_EDIT_FRAME::ReCreateHToolbar()
                             msg, wxITEM_CHECK );
     m_mainToolBar->AddTool( ID_LIBEDIT_EDIT_PIN_BY_TABLE, wxEmptyString, KiBitmap( pin_table_xpm ),
                             _( "Show pin table" ) );
+    m_mainToolBar->AddTool( ID_LIBEDIT_IMPORT_CSV, wxEmptyString, KiBitmap( import_csv_xpm ),
+                            _( "Import pins from CSV file" ) );
 
     // after adding the buttons to the toolbar, must call Realize() to reflect the changes
     m_mainToolBar->Realize();
diff --git a/include/bitmaps.h b/include/bitmaps.h
index 886b183..eaa2bd3 100644
--- a/include/bitmaps.h
+++ b/include/bitmaps.h
@@ -271,6 +271,7 @@ EXTERN_BITMAP( icon_pagelayout_editor_xpm )
 EXTERN_BITMAP( image_xpm )
 EXTERN_BITMAP( import_brd_file_xpm )
 EXTERN_BITMAP( import_cmp_from_lib_xpm )
+EXTERN_BITMAP( import_csv_xpm  )
 EXTERN_BITMAP( import_footprint_names_xpm )
 EXTERN_BITMAP( import_hierarchical_label_xpm )
 EXTERN_BITMAP( import_module_xpm )
-- 
2.7.4


Follow ups