← Back to team overview

kicad-developers team mailing list archive

Re: Kicad scripting progress :-)

 

It seems like I introduced any dependency with the DEBUG mode, please
enable the DEBUG
on build (not sure what flag was it..)


For python, I built it with Python 2.7 (or 2.6), (I choosed to stay in
2.x because all the wx wrappers
are in 2.x yet as far as I remember). But making the jump into 3.x
later shouldn't be anything complex.

Thanks a lot for testing, I'll try to remove the "DEBUG" dependency.



2012/3/19 lajos kamocsay <panka.nospam@xxxxxxxxx>:
> Hi Miguel-
>
> This sounds pretty awesome! But for some reason I can't build it (revno 3453):
>
> ...
> ...
> [ 67%] Building CXX object
> pcbnew/CMakeFiles/_pcbnew.dir/scripting/pcbnewPYTHON_wrap.cxx.o
> /Projects/linux/kicad/build.scripting.bzr/Release/pcbnew/scripting/pcbnewPYTHON_wrap.cxx:
> In function 'PyObject* _wrap_DHEAD_VerifyListIntegrity(PyObject*,
> PyObject*)':
> /Projects/linux/kicad/build.scripting.bzr/Release/pcbnew/scripting/pcbnewPYTHON_wrap.cxx:3985:11:
> error: 'class DHEAD' has no member named 'VerifyListIntegrity'
> /Projects/linux/kicad/build.scripting.bzr/Release/pcbnew/scripting/pcbnewPYTHON_wrap.cxx:
> In function 'PyObject* _wrap_EDA_ITEM_Show(PyObject*, PyObject*)':
> /Projects/linux/kicad/build.scripting.bzr/Release/pcbnew/scripting/pcbnewPYTHON_wrap.cxx:7210:29:
> error: 'const class EDA_ITEM' has no member named 'Show'
> /Projects/linux/kicad/build.scripting.bzr/Release/pcbnew/scripting/pcbnewPYTHON_wrap.cxx:
> In function 'PyObject* _wrap_EDA_ITEM_ShowDummy(PyObject*,
> PyObject*)':
> /Projects/linux/kicad/build.scripting.bzr/Release/pcbnew/scripting/pcbnewPYTHON_wrap.cxx:7243:29:
> error: 'const class EDA_ITEM' has no member named 'ShowDummy'
> ....
> .... (and lots more)
>
> My cmake:
>
> cmake ../../scripting -DKICAD_SCRIPTING=ON
> -DKICAD_SCRIPTING_MODULES=ON -DUSE_NEW_PCBNEW_LOAD=ON
> -DUSE_NEW_PCBNEW_SAVE=ON -DKICAD_STABLE_VERSION=ON
> -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
>
> I have swig 2.0.4 and python 3.2.2. Do I need anything else?
>
>
> Thanks-
> -lajos
>
>
>
>
>
> On Sun, Mar 18, 2012 at 12:19 PM, Miguel Angel Ajo Pelayo
> <miguelangel@xxxxxxx> wrote:
>>
>> Hi All,
>>
>>     I wanted to share our progress on this, and ask a few questions.
>>
>>     At this moment, we're already able to:
>>
>> 1) run scripts (python) from inside pcbnew,
>>         pcbnew.GetBoard()  must return our current BOARD* in the editor.
>>
>> A little example:
>>
>>    from pcbnew import *
>>
>>    m = GetBoard().m_Modules
>>
>>    x,y=54000,54000
>>    i=1
>>
>>    while m:
>>         m.SetPosition(wxPoint(x+i*2000,y))
>>         m.SetReference("C%d"%i)
>>   i+=1
>> m = m.Next()
>>
>>
>> 2) run pcbnew classes and objects from inside a standalone python script.
>>
>> #!/bin/env python
>> from pcbnew import *
>>
>> pcb = LoadBoard("/tmp/my.brd")
>> m = pcb.m_Modules
>>
>> x,y=54000,54000
>> i=1
>>
>> while m:
>>      m.SetPosition(wxPoint(x+i*2000,y+i*1000))
>>      m.SetReference("C%d"%i)
>>      i+=1
>>      m = m.Next()
>>
>> SaveBoard("/tmp/my.brd",pcb)
>>
>> Same example from commandline:
>>
>>     For which I added some functions to easily load or save a PCB file via
>> IO_MGR // KICAD_PLUGIN (as Dick asked, it
>> was the best way)
>>
>>     I added typemaps for strings<->wxString, and also wrappers for wxPoint
>> and wxRect, which let
>> us to talk to methods depending on this types.
>>
>>     We have wrappers for most objects (BOARD, COMPONENT, PAD, segments ,
>> tracks, text, etc... ) and lists (DLIST based),
>> but we still miss access to std::vector and std::list objects yet.
>>
>>
>> We already have something quite useful, but testing is very welcome.
>>
>> https://code.launchpad.net/~miguelangel-r/kicad/scripting
>>
>> I only tested it on Linux/x86, and will test on Linux/x64, but testing in
>> other systems is welcome.
>> To build the branch you should compile with:
>>
>> KICAD_SCRIPTING                (for embedded scripting support in pcbnew)
>> KICAD_SCRIPTING_MODULES  (for module scripting support from python)
>> USE_NEW_PCBNEW_LOAD
>> USE_NEW_PCBNEW_SAVE
>>
>>
>> The problems I facing now are:
>>
>> a) Some pcbnew functionalities are highly coupled with UI, so dependencies
>> from objects to UI
>> are in many places (making the .SO/.DLL module approach very hard), I tried
>> to split in ui and
>> non ui .cpp files, but I ended always with linking problems, so the
>> currently built _pcbnew.so links
>> all the UI items inside, it works prefectly, but most code won't be ever
>> called.
>>
>> b) From a), for example, I'm not able to load a MODULE object from library,
>> without having a
>> PCB_BASE_FRAME object:
>>
>> from loadcmp.cpp:
>>
>> MODULE* PCB_BASE_FRAME::GetModuleLibrary( const wxString&
>> aLibraryFullFilename,
>>                                           const wxString& aModuleName,
>>                                           bool
>>  aDisplayMessageError )
>>
>>    This could be fixed by splitting the library functionality in a different
>> class, and then using it
>> from those functions (and from scripting).
>>
>> c) same for DRC, I thought it could be very helpful to run DRC checkings
>> (automated commandline
>> scripts for DRC checking) , but it also was highly coupled to the UI.
>>
>> d) this is minor, but it's there... if you run pcbnew from the same
>> directory _pcbnew.so is (this is normal
>> when building), then pcbnew will load _pcbnew.so from it's local directory
>> (this is some swig feature...),
>> then GetBoard() won't work (return None) because it's a separeted instance
>> from our running pcbnew...,
>> so if you want to test ./pcbnew from your build directory, then move
>> _pcbnew.so somewhere else ;)
>>
>>
>> e) other minor, if you make install to /usr/local, then the _pcbnew.so and
>> pcbnew.py will go to
>> /usr/local/share/python, which is out of the normal python path, so you will
>> need to do:
>>
>> export PYTHONPATH=$PYTHONPATH:/usr/local/share/python
>>
>> and then run your script.
>>
>>
>>
>> I will keep working on it, and keep you updated, but any tests/feedback are
>> really welcome :-)
>>
>>
>> --
>>
>> Miguel Angel Ajo Pelayo
>> http://www.nbee.es
>> +34 636 52 25 69
>> skype: ajoajoajo
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp



-- 

Miguel Angel Ajo Pelayo
http://www.nbee.es
+34 636 52 25 69
skype: ajoajoajo


References