← Back to team overview

kicad-developers team mailing list archive

[PATCH] Expose netclassptr constructor to python interface



This is my second contribution. It's a simple one line addition to
netclass.i to expose the netclassptr constructor, enabling python scripts
to add new netclasses.

In my first contribution, I made a couple errors in the contribution
process which Wayne graciously fixed for me. I did look at those
differences and I believe I'm adhering better now.

If I missed something this time, please be specific. I plan on contributing
again and want to make things as easy as possible.

In case anyone would like to exercise the code, this will do it. The new
api is in red:
import pcbnew

board = pcbnew.GetBoard()
ds = board.GetDesignSettings()
# ugly. exposes a public member not via an accessor method
nc = ds.m_NetClasses
foo = pcbnew.NETCLASSPTR("foo")


PS this is only a one-liner and I feel a little goofy for it. I wanted to
get it out there before it got lost in the pile other stuff I'm doing.
From 2812192e5928a8d72abceeef33291f4ac3a3dfa7 Mon Sep 17 00:00:00 2001
From: Miles McCoo <mail@xxxxxxxxxx>
Date: Thu, 13 Apr 2017 11:13:21 +0200
Subject: [PATCH] Minor Pcbnew Python scripting improvement.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.7.4"

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

Added NETCLASSPTR contructor to swig interface. This enables scripts to generate new net classes.
 pcbnew/swig/netclass.i | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

Content-Type: text/x-patch; name="0001-Minor-Pcbnew-Python-scripting-improvement.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-Minor-Pcbnew-Python-scripting-improvement.patch"

diff --git a/pcbnew/swig/netclass.i b/pcbnew/swig/netclass.i
index 200c8ed..64602c8 100644
--- a/pcbnew/swig/netclass.i
+++ b/pcbnew/swig/netclass.i
@@ -1,3 +1,26 @@
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@xxxxxxx>
+ * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
@@ -25,7 +48,8 @@ function set if you see something missing from class NETCLASS that you need.
 %extend std::shared_ptr<NETCLASS>
+    std::shared_ptr<NETCLASS>(std::string name)     { return new std::shared_ptr<NETCLASS>( new NETCLASS(name) ); }
     STRINGSET&  NetNames()                  { return (*self)->NetNames(); }
     const wxString& GetName()               { return (*self)->GetName(); }


Follow ups