Rounded Tracks Reloaded ... again: RF Tools for KiCad

Nice work, @maui
Dialog resize works well now.

1 Like

@nickoe @adamwolf
It seems that this library is a bit difficult to be installed on Win and OSX systems…
Would it be possible to package KiCad 5 and KiCad 6 with pyclipper?
that would help users with Via Fence plugins…

The library weight is just few hundreds KB

Thanks in advance
Maurice

1 Like

Either that route or can you bundle pyclipper.so with the plugin for mac users? Once pyclipper.so was in the plugins directory, the ViaFence plugin worked.

As much for my own reference as anything, these are some random notes on KicadPython on macOS. I am not trying to teach anyone how to suck eggs - but getting some of these plugins to work in macOS can be tricky. Using links is a useful trick for managing and updating these easily.

KiCad on macOS uses its own, bundled version of Python2.7 at /Applications/Kicad/kicad.app/Contents/Frameworks/Python.framework/Versions/Current/bin/python
Unlike linux, macOS KiCad does not use the system Python so installing stuff directly with pip does not work

[I believe this will be upgraded to 3 in Kicad 6 but that is where we are at present]
To make matters trickier, the KiCad Python doesn’t have pip or easy_install directly available or can you use it easily to install using the system pip.
(i.e. you can’t do /Applications/Kicad/kicad.app/Contents/Frameworks/Python.framework/Versions/Current/bin/python /usr/local/bin/pip install pyclipper)

You need the pyclipper version installed by Python2 not Python3. The file you need will be called pyclipper.so - not pyclipper.cpython-36m-darwin.so or similar.

Find out which version of Python the system uses by typing python -V at the command prompt. If you have 2.7 all good. Do a pip install pyclipper' and copy the pyclipper.sofile from/usr/local/lib/python2.7/site-packages/ to the plugins directory. (~/Library/Preferences/kicad/scripting`).

If you get 3.x, then try python2 -V. You may then need to use pip2 install pyclipper to install the correct version of pyclipper. Once you have the right file, copy it to the plugins as before.

The scripting and plugins files are buried several layers deep and it is a pain to copy the original plugin files there - especially if you need to update them. The simplest way to deal with them is to git clone them into a directory that you have easy access to. (I have an EDA directory with a directory of plugins with in it). I would suggest aliasing the real file into the plugin directory -

ln -s PATH_TO_DIRECTORY/RF-tools-KiCAD/via_fence_generator/ ~/Library/Preferences/kicad/scripting/ ln -s PATH_TO_DIRECTORY/RF-tools-KiCAD//trace_solder_expander ~/Library/Preferences/kicad/scripting/ ln -s PATH_TO_DIRECTORY/RF-tools-KiCAD/tracks_length/ ~/Library/Preferences/kicad/scripting/ ln -s PATH_TO_DIRECTORY/RF-tools-KiCAD//round_tracks/ ~/Library/Preferences/kicad/scripting/

This will allow you to git pull the latest version in wherever you keep the plugins and not have to move them into the correct directory each time you pull a new version.

The footprint generator has to go in a different location. According to the KiCad documentation, it should be possible to put footprint generators in ~/Library/Application Support/kicad/scripting/plugins but I have never got this to work. (Probably should be a bug report). The alternative is to put them into /Applications/KiCad/kicad.app/Contents/SharedSupport/scripting/plugins (Again, the kicad-source docs are slightly worn here - note the ‘.app’. (I have linked the documentation) You can use the same aliasing here -

ln -s PATH_TO/RF-tools-KiCAD/rf_tools_wizards /Applications/KiCad/kicad.app/Contents/SharedSupport/scripting/plugins

Hope this is of use to someone!

this is a viable workaround…
but the issue is that the lib must be of the same python version… it is not enough the main release, but it must match also the minor version (i.e. python version 2.7.15 -> the same for the lib).
So if I would bundle a pyclipper lib with the plugin, it would work until KiCad would move to a new python release (even if there is change in the minor version)…

My best option/suggestion would be to get pyclipper deployed within KiCAD installer on the three OSes.

Even with Daily compile from master I ran into the same installation issue.

The fix in my case turned out to be:

and in CMakeLists.txt set those two compiler directives to ON (they default to OFF)

  • KICAD_SCRIPTING_PYTHON3
  • KICAD_SCRIPTING_WXPYTHON_PHOENIX

As for the stiching tool itself. Went with the default settings. It is kinda inconsiderte towards pads at the end of a track. Vias are being placed too close to pads, and actually touching track-end-pads even under a different net name than the pad touched. The DRC rightfully throws up lots of errors because of that. Otherwise a tool that sure will come in handy at times.

1 Like

This is because ATM Via fencing is not considering DRC at all.
But as already reported :

Anyway, I’ve included the plugin code just now and it will take a bit to add DRC checking as already included in the Via Stitching plugin.
BTW any PR code to fix this @ the new repo would be welcomed :smiley:

On Linux the solution is quite straightforward… unfortunately it is much worse on Win or OSX because the python libs are bundled.

2 Likes

Oh windox praised be thy before the gates onto heaven. amenx

Yes - that would certainly be easiest - or at least bundle pip so that you can install additional modules. (Although I appreciate that having inconsistent, user installed python modules might cause debugging problems and perhaps not be desirable).

As a follow on from @Rene_Poschl suggestions about using subprocess, which I should have mentioned earlier, I did not have much luck with this either.

>>>import sys
>>>import subprocess
>>>subprocess.check_output([sys.executable, '-m', '/usr/local/bin/pip2', 'list'])
''

This seems to spawn another instance of KiCad and then lock up. I think you would have to specify the exact path to an external pip version as there is no pip in the Kicad python path and it needs a full path anyway. I gave up at this point and tried what i said above. I could perhaps have tried to run the pip setup from within the KiCad python console by using curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py and then run that from the KiCad CLI.

Since I have a satisfactory solution, I am going to stop digging!

Are this PIP not the same PIP that we are looking for ? (Sorry, I do not use Python that much to know )

grafik

EDIT: Running PIP

Please have a look above

Would you please try to run:
pip install pyclipper

I just did and failed miserably, sorry:

Collecting pyclipper
  Using cached https://files.pythonhosted.org/packages/20/a3/a60a7bad5246d66f3c54127b34b90e6d34b2cc006b84135bfcbfee4514b1/pyclipper-1.1.0.post1.zip
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\ua772~1.est\appdata\local\temp\pip-build-env-tw2qxr\lib\python2.7\site-packages/setuptools/__init__.py", line 228, in <module>
        monkey.patch_all()
      File "c:\users\ua772~1.est\appdata\local\temp\pip-build-env-tw2qxr\lib\python2.7\site-packages/setuptools/monkey.py", line 101, in patch_all
        patch_for_msvc_specialized_compiler()
      File "c:\users\ua772~1.est\appdata\local\temp\pip-build-env-tw2qxr\lib\python2.7\site-packages/setuptools/monkey.py", line 164, in patch_for_msvc_specialized_compiler
        patch_func(*msvc9('find_vcvarsall'))
      File "c:\users\ua772~1.est\appdata\local\temp\pip-build-env-tw2qxr\lib\python2.7\site-packages/setuptools/monkey.py", line 151, in patch_params
        mod = import_module(mod_name)
      File "D:\Program Files\KiCad_v5_1_4\lib\python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
      File "D:\Program Files\KiCad_v5_1_4\lib\python2.7/distutils/msvc9compiler.py", line 306, in <module>
        raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)
    distutils.errors.DistutilsPlatformError: VC 6.0 is not supported by this module

EDIT:
The command I used was:
python pip-script.py install pyclipper

Thanks @maui with the workaround worked as advertised!

However, I had to dump the files in the “scripting” folder, if I put them in the “plugins” folder, thery where not being picked up by KiCAD.

@maui It would be better to request this on the bug trackers instead of pinging them, since you are not guaranteed that they will view this.

Humm that is strange … from your pictures I don’t see any ‘plugins’ folder inside ‘scripting’ folder …
Anyway I’m going to see if I get attention at the bug tracker or the dev mailing list as suggested by @imcinerney

PS @der.ule thanks for reporting your testing results.

The reason why my script should work is because it does guarantee that pip from the currently running python instance is used. You remove this benefit by pointing to the system pip. Of course if the currently running python instance does not come with pip then you will get an error. Would then mean that pip must be installed for that instance. (as mentioned there is a way to do even this from within a script but i could not find the blog post that showed how.)

And an other user case:
Round corner traces for Flex PCB

The best practice for Flex PCB Design, when the circuit bend is unavoidable, is to keep the track work as gently curving as possible, using conical radius bends.

This goal could be reached both with Round Tracks plugins (being aware to highly discretize the curve) or even with real arcs, using the Arc footprint Wizard included in the tools.

Moreover near the connectors it is advisable to taper down from the pads.
This can be achieved using the Taper footprint Wizard included in the tools.

3 Likes

I have this general question: These RF tools are truly great. However, in practice, many traces will be created by an RF/μwave simulator. The question I have is what would be the best way to import such traces into KiCAD? (I exclude the hard way of measuring the dimensions of each trace in the simulator individually and then transferring it to KiCAD.) Would DXF work, if the simulator could output the traces in DXF format? Is there a systematized way to transfer a layout from QUCS to KiCAD? There were some presentations earlier this year about “marrying” KiCAD to openEMS earlier this year, but I don’t think anybody has figured out how to easily import layout files into KiCAD from other programs. One reference I found is this: https://github.com/Valber/qucs2kicad. This, however, is only for schematic files, plus it seems to be stagnating since 2011.

Consider a hairpin filter (https://en.wikipedia.org/wiki/Distributed-element_filter). You will see that some of its traces do not connect to anything; they just lie there. Regardless of how they can be created (importing them from a simulator or the hard way by hand), how can we make sure KiCAD is not going to remove them?

I’m not experienced in RF, but my gut instinct is because these different features you mention are acting like passive components (resistors, inductors, capacitors, etc) they would be better served as built as footprints. Additional benefit of locking them in as footprints is when doing the board layout nudging things around won’t risk changing the geometry of the RF elements.

@SembazuruCDE: Thank you for your insightful suggestion. I had not considered the possibility of such traces getting nudged. To follow your suggestion, would I need to create a separate footprint for every length of microstrip of a distributed element (such as a hairline filter)? That would be a lot of footprints! Maybe there could be a way to import the whole filter layout from the simulator as a footprint and then lock it? What about the case of stripline (RF trace between two ground layers; see, for example https://en.wikipedia.org/wiki/Stripline)? I am not sure you can have a footprint which is not on the top or bottom layer.