[Kicad-developers] [PATCH] Add python apis: GetLogicalLibs, FootprintsInLib and FootprintInfo

2018-05-04 Thread miles mccoo
I submitted this patch before, but it fell through the cracks.

This patch makes it possible to query pcbnew for a list of footprint
libraries, and the footprints contained therein. (without reading fp-lib
myself)


my previous attempt:
https://lists.launchpad.net/kicad-developers/msg35236.html
It has some implementation notes that may be of interest.


I believe I have followed the coding guidelines which I have read several
times. If I missed something, please indicate more than "follow the
guidelines". At least a theme. (trailing space, curlies,...)


Since attachments don't seem to make it to the launchpad site, I've also
made the patch file available here:
http://mmccoo.com/random/0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-a.patch


Miles
From 3b5bc236d6b1c075e9cb49d6432f1ea2b8e876a6 Mon Sep 17 00:00:00 2001
From: Miles McCoo 
Date: Fri, 4 May 2018 10:01:54 +0200
Subject: [PATCH] Add the python apis: GetLogicalLibs, FootprintsInLib and
 FootprintInfo.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="2.17.0"

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


GetLogicalLibs will return the list of available footprint libraries
FootprintsInLib lists the footprints in a library based on the library's name.
FootprintInfo will return basic information about a particular footprint (num pads...)

A couple of interesting ways in which this patch may be different from other python interface patches:
created the file autodoc.i which gives help messages (docstrings as they are called in python) for the new APIs. The default docstrings generated by
SWIG are often not that helpful. knowing that a function takes a string is not enough. What should that string contain. It seemed to me these messages
should be together.

created the file swig_typemaps.i: a vector, by default is returned as a point to a vector instance. in swig_typemaps.i should go directives for
when to expand stl templates. Other reasons to have a typemap is to automagically convert classes into something like a python tuple, dict, or list.

exposed pcb_edit_frame pointer stored in pcbnew_scripting_helpers to other parts of the SWIG files. This doesn't expose it to python. pcb_edit_frame
has a lot of interesting methods and also many that should be excluded.

Thank you to Orson (Maciej Suminski) and Jeff Young for their hints.

This thread may be of interest: https://lists.launchpad.net/kicad-developers/msg34925.html
---
 pcbnew/CMakeLists.txt|   2 +
 pcbnew/swig/autodoc.i|  44 +
 pcbnew/swig/footprint.i  | 114 ++-
 pcbnew/swig/pcbnew.i |  13 ++-
 pcbnew/swig/pcbnew_scripting_helpers.cpp |   8 +-
 pcbnew/swig/pcbnew_scripting_helpers.h   |   3 +-
 pcbnew/swig/swig_typemaps.i  |  34 +++
 7 files changed, 212 insertions(+), 6 deletions(-)
 create mode 100644 pcbnew/swig/autodoc.i
 create mode 100644 pcbnew/swig/swig_typemaps.i


--2.17.0
Content-Type: text/x-patch; name="0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-a.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-a.patch"

diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt
index 04cad9b35..614074271 100644
--- a/pcbnew/CMakeLists.txt
+++ b/pcbnew/CMakeLists.txt
@@ -441,6 +441,7 @@ if( KICAD_SCRIPTING )   # Generate pcbnew.py and pcbnew_wrap.cxx using swig
 DEPENDS plotcontroller.h
 DEPENDS exporters/gendrill_Excellon_writer.h
 DEPENDS swig/pcbnew.i
+DEPENDS swig/autodoc.i
 DEPENDS swig/board.i
 DEPENDS swig/board_connected_item.i
 DEPENDS swig/board_design_settings.i
@@ -458,6 +459,7 @@ if( KICAD_SCRIPTING )   # Generate pcbnew.py and pcbnew_wrap.cxx using swig
 DEPENDS swig/pad.i
 DEPENDS swig/pcb_text.i
 DEPENDS swig/plugins.i
+DEPENDS swig/swig_typemaps.i
 DEPENDS swig/text_mod.i
 DEPENDS swig/track.i
 DEPENDS swig/units.i
diff --git a/pcbnew/swig/autodoc.i b/pcbnew/swig/autodoc.i
new file mode 100644
index 0..ded5a43f6
--- /dev/null
+++ b/pcbnew/swig/autodoc.i
@@ -0,0 +1,44 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 1992-2018 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU G

Re: [Kicad-developers] [PATCH] Add python apis: GetLogicalLibs, FootprintsInLib and FootprintInfo

2018-05-08 Thread Jeff Young
Hi Miles,

The only coding style issue I saw was that there should be blank lines above 
“if” statements.

Oh, and there’s still a K&R-style brace.  Search for "if ( footprint ) {“.  
(The brace should be down on its own line.)

I didn’t correct these and merge your patch as I can’t get scripting to build 
on my Mac so there’s no way for me to do a quick sanity test.

Cheers,
Jeff.


> On 4 May 2018, at 09:17, miles mccoo  wrote:
> 
> 
> 
> I submitted this patch before, but it fell through the cracks.
> 
> This patch makes it possible to query pcbnew for a list of footprint 
> libraries, and the footprints contained therein. (without reading fp-lib 
> myself)
> 
> 
> my previous attempt: 
> https://lists.launchpad.net/kicad-developers/msg35236.html 
> 
> It has some implementation notes that may be of interest.
> 
> 
> I believe I have followed the coding guidelines which I have read several 
> times. If I missed something, please indicate more than "follow the 
> guidelines". At least a theme. (trailing space, curlies,...)
> 
> 
> Since attachments don't seem to make it to the launchpad site, I've also made 
> the patch file available here:
> http://mmccoo.com/random/0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-a.patch
>  
> 
> 
> 
> Miles
> <0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-a.patch>___
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp

___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Kicad-developers] [PATCH] Add python apis: GetLogicalLibs, FootprintsInLib and FootprintInfo

2018-05-09 Thread miles mccoo
Thank you, Jeff, for taking the time to look at my patch.

attached is a new version of the patch. I've changed a couple things:

   - fixed the curly brace issue
   - added blanks before each of the if statements
   - I added a short test python function to the checkin comments[1]. It
   exercises the new functionality[2]
   - I added an additional function to instantiate a footprint. The only
   other such function I'm aware of wants a full path to a library. This one
   just takes the name of the lib


I've also posted the patch here:
http://mmccoo.com/random/0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-I.patch


Miles

[1] There's a thread on the developer list complaining about the poor
comments. That thread focuses on the symbol or footprint libraries. I'd
like to take this opportunity to comment that check comment and comments in
general in the kicad project they kinda suck. The code itself contains
very little in the way of explanation. The checkin comments are terse. I
haven't found any kind of design documents or discussion on the mail list.

Hopefully someone will correct me.


[2] does kicad have anything in the way of a regression? It would be nice
to have some python code to be periodically executed. Compile errors is one
thing, but a couple APIs have disappeared in the last year. Such scripting
might have caught that.



On Tue, May 8, 2018 at 5:36 PM, Jeff Young  wrote:

> Hi Miles,
>
> The only coding style issue I saw was that there should be blank lines
> above “if” statements.
>
> Oh, and there’s still a K&R-style brace.  Search for "if ( footprint ) {“.
>  (The brace should be down on its own line.)
>
> I didn’t correct these and merge your patch as I can’t get scripting to
> build on my Mac so there’s no way for me to do a quick sanity test.
>
> Cheers,
> Jeff.
>
>
> On 4 May 2018, at 09:17, miles mccoo  wrote:
>
>
>
> I submitted this patch before, but it fell through the cracks.
>
> This patch makes it possible to query pcbnew for a list of footprint
> libraries, and the footprints contained therein. (without reading fp-lib
> myself)
>
>
> my previous attempt: https://lists.launchpad.net/kicad-
> developers/msg35236.html
> It has some implementation notes that may be of interest.
>
>
> I believe I have followed the coding guidelines which I have read several
> times. If I missed something, please indicate more than "follow the
> guidelines". At least a theme. (trailing space, curlies,...)
>
>
> Since attachments don't seem to make it to the launchpad site, I've also
> made the patch file available here:
> http://mmccoo.com/random/0001-Add-the-python-apis-GetLogicalLibs-
> FootprintsInLib-a.patch
>
>
> Miles
> <0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-a.patch>__
> _
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
>
>
From c4ef67fad0622cd664e96285b33e133cd892e5f9 Mon Sep 17 00:00:00 2001
From: Miles McCoo 
Date: Wed, 9 May 2018 14:18:35 +0200
Subject: [PATCH] Add the python apis: GetLogicalLibs, FootprintsInLib,
 InstantiateFootprint and FootprintInfo.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="2.17.0"

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


GetLogicalLibs will return the list of available footprint libraries
FootprintsInLib lists the footprints in a library based on the library's name.
FootprintInfo will return basic information about a particular footprint (num pads...)
InstantiateFootprint will instantiate a footprint for placement in a board.

A couple of interesting ways in which this patch may be different from other python interface patches:
created the file autodoc.i which gives help messages (docstrings as they are called in python) for the new APIs. The default docstrings generated by
SWIG are often not that helpful. knowing that a function takes a string is not enough. What should that string contain? It seemed to me these messages
should be together.

created the file swig_typemaps.i: a vector, by default is returned as a point to a vector instance. in swig_typemaps.i should go directives for
when to expand stl templates. Other reasons to have a typemap is to automagically convert classes into something like a python tuple, dict, or list.

exposed pcb_edit_frame pointer stored in pcbnew_scripting_helpers to other parts of the SWIG files. This doesn't expose it to python. pcb_edit_frame
has a lot of interesting methods and also many that should be excluded.

Thank you to Orson (Maciej Suminski) and Jeff Young for their hints.

This thread may be of interest: https://lists.launchpad.net/kicad-developers/msg34925.html

Here is a quick test proc:
import pcbnew

def test_fp_stuff():
libs = pcb

Re: [Kicad-developers] [PATCH] Add python apis: GetLogicalLibs, FootprintsInLib and FootprintInfo

2018-05-09 Thread Nick Østergaard
See the unittests in the qa folder. Thay are executed by the build job also.

ons. 9. maj 2018 15.25 skrev miles mccoo :

> Thank you, Jeff, for taking the time to look at my patch.
>
> attached is a new version of the patch. I've changed a couple things:
>
>- fixed the curly brace issue
>- added blanks before each of the if statements
>- I added a short test python function to the checkin comments[1]. It
>exercises the new functionality[2]
>- I added an additional function to instantiate a footprint. The only
>other such function I'm aware of wants a full path to a library. This one
>just takes the name of the lib
>
>
> I've also posted the patch here:
> http://mmccoo.com/random/0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-I.patch
>
>
> Miles
>
> [1] There's a thread on the developer list complaining about the poor
> comments. That thread focuses on the symbol or footprint libraries. I'd
> like to take this opportunity to comment that check comment and comments in
> general in the kicad project they kinda suck. The code itself contains
> very little in the way of explanation. The checkin comments are terse. I
> haven't found any kind of design documents or discussion on the mail list.
>
> Hopefully someone will correct me.
>
>
> [2] does kicad have anything in the way of a regression? It would be nice
> to have some python code to be periodically executed. Compile errors is one
> thing, but a couple APIs have disappeared in the last year. Such scripting
> might have caught that.
>
>
>
> On Tue, May 8, 2018 at 5:36 PM, Jeff Young  wrote:
>
>> Hi Miles,
>>
>> The only coding style issue I saw was that there should be blank lines
>> above “if” statements.
>>
>> Oh, and there’s still a K&R-style brace.  Search for "if ( footprint )
>> {“.  (The brace should be down on its own line.)
>>
>> I didn’t correct these and merge your patch as I can’t get scripting to
>> build on my Mac so there’s no way for me to do a quick sanity test.
>>
>> Cheers,
>> Jeff.
>>
>>
>> On 4 May 2018, at 09:17, miles mccoo  wrote:
>>
>>
>>
>> I submitted this patch before, but it fell through the cracks.
>>
>> This patch makes it possible to query pcbnew for a list of footprint
>> libraries, and the footprints contained therein. (without reading fp-lib
>> myself)
>>
>>
>> my previous attempt:
>> https://lists.launchpad.net/kicad-developers/msg35236.html
>> It has some implementation notes that may be of interest.
>>
>>
>> I believe I have followed the coding guidelines which I have read several
>> times. If I missed something, please indicate more than "follow the
>> guidelines". At least a theme. (trailing space, curlies,...)
>>
>>
>> Since attachments don't seem to make it to the launchpad site, I've also
>> made the patch file available here:
>>
>> http://mmccoo.com/random/0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-a.patch
>>
>>
>> Miles
>> <0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-a.patch>
>> ___
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to : kicad-developers@lists.launchpad.net
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>>
>>
>>
> ___
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Kicad-developers] [PATCH] Add python apis: GetLogicalLibs, FootprintsInLib and FootprintInfo

2018-05-23 Thread miles mccoo
bump.

;-)

To my knowledge this patch hasn't been merged or rejected.

Miles

On Wed, May 9, 2018 at 3:47 PM, Nick Østergaard  wrote:

> See the unittests in the qa folder. Thay are executed by the build job
> also.
>
>
> ons. 9. maj 2018 15.25 skrev miles mccoo :
>
>> Thank you, Jeff, for taking the time to look at my patch.
>>
>> attached is a new version of the patch. I've changed a couple things:
>>
>>- fixed the curly brace issue
>>- added blanks before each of the if statements
>>- I added a short test python function to the checkin comments[1]. It
>>exercises the new functionality[2]
>>- I added an additional function to instantiate a footprint. The only
>>other such function I'm aware of wants a full path to a library. This one
>>just takes the name of the lib
>>
>>
>> I've also posted the patch here: http://mmccoo.com/
>> random/0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-I.patch
>>
>>
>> Miles
>>
>> [1] There's a thread on the developer list complaining about the poor
>> comments. That thread focuses on the symbol or footprint libraries. I'd
>> like to take this opportunity to comment that check comment and comments in
>> general in the kicad project they kinda suck. The code itself contains
>> very little in the way of explanation. The checkin comments are terse. I
>> haven't found any kind of design documents or discussion on the mail list.
>>
>> Hopefully someone will correct me.
>>
>>
>> [2] does kicad have anything in the way of a regression? It would be nice
>> to have some python code to be periodically executed. Compile errors is one
>> thing, but a couple APIs have disappeared in the last year. Such scripting
>> might have caught that.
>>
>>
>>
>> On Tue, May 8, 2018 at 5:36 PM, Jeff Young  wrote:
>>
>>> Hi Miles,
>>>
>>> The only coding style issue I saw was that there should be blank lines
>>> above “if” statements.
>>>
>>> Oh, and there’s still a K&R-style brace.  Search for "if ( footprint )
>>> {“.  (The brace should be down on its own line.)
>>>
>>> I didn’t correct these and merge your patch as I can’t get scripting to
>>> build on my Mac so there’s no way for me to do a quick sanity test.
>>>
>>> Cheers,
>>> Jeff.
>>>
>>>
>>> On 4 May 2018, at 09:17, miles mccoo  wrote:
>>>
>>>
>>>
>>> I submitted this patch before, but it fell through the cracks.
>>>
>>> This patch makes it possible to query pcbnew for a list of footprint
>>> libraries, and the footprints contained therein. (without reading fp-lib
>>> myself)
>>>
>>>
>>> my previous attempt: https://lists.launchpad.net/kicad-
>>> developers/msg35236.html
>>> It has some implementation notes that may be of interest.
>>>
>>>
>>> I believe I have followed the coding guidelines which I have read
>>> several times. If I missed something, please indicate more than "follow the
>>> guidelines". At least a theme. (trailing space, curlies,...)
>>>
>>>
>>> Since attachments don't seem to make it to the launchpad site, I've also
>>> made the patch file available here:
>>> http://mmccoo.com/random/0001-Add-the-python-apis-GetLogicalLibs-
>>> FootprintsInLib-a.patch
>>>
>>>
>>> Miles
>>> <0001-Add-the-python-apis-GetLogicalLibs-FootprintsInLib-a.patch>__
>>> _
>>> Mailing list: https://launchpad.net/~kicad-developers
>>> Post to : kicad-developers@lists.launchpad.net
>>> Unsubscribe : https://launchpad.net/~kicad-developers
>>> More help   : https://help.launchpad.net/ListHelp
>>>
>>>
>>>
>> ___
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to : kicad-developers@lists.launchpad.net
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>>
>
___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp