← Back to team overview

kicad-developers team mailing list archive

[PATCH] additions/fix to python interface

 

Hello,

This is the first patch I'm submitting to Kicad. Hopefully, I'm following
the directions correctly.

My interest is in pcbnew's python interface and this patch adds/fixes a
couple things


   - EDA_RECT.Inflate takes a wxCoord as an argument. swig didn't know that
   wxCoord is just an int. I've added a typedef to wx.i. wxCoord is defined in
   include/wx/defs.h
   - Within the C code, frames, toolbars and such are identified using an
   enum in id.h. To expose those names to the python interface, I've added
   include "id.h" to pcbnew.i
   - There doesn't appear to be a good way from python to ask pcbnew to
   Refresh the screen or to Zoom to a specific area. So I've added Refresh and
   WindowZoom to pcbnew_scripting_helpers




Since this is also my first post to this mail list, a couple words about
myself...

Perhaps of most immediate interest to you is a blog I've started recently
explaining how to use pcbnew's scripting abilities:
https://kicad.mmccoo.com/kicad-scripting-table-of-contents/. I haven't
found much documentation about how to do scripting in pcbnew, so hopefully
you'll find it useful.

Until a year and a half ago, I spent many years working on VLSI EDA tools
for a major CPU manufacture whose name starts with In and ends with tel.
Not quite PCB, but...

Going forward, I hope to contribute more enhancements to pcbnew's python
stuff. The layout tools used by my former employer included many, many
features written in TCL. In the PCB realm, I'd like to help enable
something similar in Kicad.

Miles
From 818407cb30ea1fe141cf466ec8310a9184b9f6f2 Mon Sep 17 00:00:00 2001
From: Miles McCoo <mail@xxxxxxxxxx>
Date: Fri, 17 Mar 2017 08:38:21 +0100
Subject: [PATCH] add typedef for wxCoord to wx.i to enable usage of methods
 like EDA_RECT.Inflate added id.h to pcbnew.i to expose window,toolbar
 identifier names added Refresh and WindowZoom to pcbnew_scripting_helper.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.7.4"

This is a multi-part message in MIME format.
--------------2.7.4
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit

---
 common/swig/wx.i                         |  4 ++++
 pcbnew/swig/pcbnew.i                     |  1 +
 pcbnew/swig/pcbnew_scripting_helpers.cpp | 15 +++++++++++++++
 pcbnew/swig/pcbnew_scripting_helpers.h   |  2 ++
 4 files changed, 22 insertions(+)


--------------2.7.4
Content-Type: text/x-patch; name="0001-add-typedef-for-wxCoord-to-wx.i-to-enable-usage-of-m.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-add-typedef-for-wxCoord-to-wx.i-to-enable-usage-of-m.patch"

diff --git a/common/swig/wx.i b/common/swig/wx.i
index dddd683..9f74dee 100644
--- a/common/swig/wx.i
+++ b/common/swig/wx.i
@@ -39,6 +39,10 @@
 void wxSetDefaultPyEncoding(const char* encoding);
 const char* wxGetDefaultPyEncoding();
 
+// wxCoord /////////////////////////////////////////////////////////
+// need to let swig know that wxCoord is an int. Ref: wx/defs.h
+typedef int wxCoord;
+
 
 // wxRect class wrapper ///////////////////////////////////////////////////////
 
diff --git a/pcbnew/swig/pcbnew.i b/pcbnew/swig/pcbnew.i
index 6e9997c..ddfc151 100644
--- a/pcbnew/swig/pcbnew.i
+++ b/pcbnew/swig/pcbnew.i
@@ -104,6 +104,7 @@ HANDLE_EXCEPTIONS(PLUGIN::FootprintDelete)
 %include <plot_common.h>
 %include <exporters/gendrill_Excellon_writer.h>
 %include <gal/color4d.h>
+%include <id.h>
 
 %include <pcbnew_scripting_helpers.h>
 
diff --git a/pcbnew/swig/pcbnew_scripting_helpers.cpp b/pcbnew/swig/pcbnew_scripting_helpers.cpp
index 62b21b3..f7def78 100644
--- a/pcbnew/swig/pcbnew_scripting_helpers.cpp
+++ b/pcbnew/swig/pcbnew_scripting_helpers.cpp
@@ -34,6 +34,7 @@
 #include <pcbnew_id.h>
 #include <build_version.h>
 #include <class_board.h>
+#include <class_drawpanel.h>
 #include <kicad_string.h>
 #include <io_mgr.h>
 #include <macros.h>
@@ -107,3 +108,17 @@ bool SaveBoard( wxString& aFileName, BOARD* aBoard,
 #endif
     return true;
 }
+
+
+
+void Refresh()
+{
+    // first argument is erase background, second is a wxRect
+    PcbEditFrame->GetCanvas()->Refresh(true, NULL);
+}
+
+void WindowZoom(int xl, int yl, int width, int height)
+{
+    EDA_RECT Rect(wxPoint(xl, yl), wxSize(width, height));
+    PcbEditFrame->Window_Zoom(Rect);  
+}
diff --git a/pcbnew/swig/pcbnew_scripting_helpers.h b/pcbnew/swig/pcbnew_scripting_helpers.h
index bff3d0e..028c849 100644
--- a/pcbnew/swig/pcbnew_scripting_helpers.h
+++ b/pcbnew/swig/pcbnew_scripting_helpers.h
@@ -43,5 +43,7 @@ BOARD*  LoadBoard( wxString& aFileName );
 bool    SaveBoard( wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat );
 bool    SaveBoard( wxString& aFileName, BOARD* aBoard );
 
+void Refresh();
+void WindowZoom(int xl, int yl, int width, int height);
 
 #endif

--------------2.7.4--



Follow ups