Multiple Track Dragging development investigations

77 views
Skip to first unread message

Stuart Tyler

unread,
Jul 3, 2023, 6:49:41 AM7/3/23
to KiCad Developers
Hi, this is my first ever post here. I am really impressed with the development of KiCad over the past few releases. The python interface is really good and I am keen to learn. I have been designing PCBs for a few decades now and keen to help improve KiCad.

I have seen some discussion on supporting Flex/Rigid in Issue #12928 and #8118. This is way beyond my KiCad development ability, but this development is very important to taking KiCad to the next level - please reach out to me for any Beta testing on this development - I have designed many Flex/Rigid PCBs and know many of the implementation issues. This feature will open so many new development possibilities for KiCad.

What I have been working on for the past few days is understanding how I can implement multiple track dragging from isssue #14983. I think this is something within my programming capability and is a feature that I really want. I cannot imagine having to route a decent sized PCB without this feature - and so I am keen to work on a simple solution. 

My solution works like this. If the drag mode is on and there are multiple items selected, then deselect everything that is not a straight track. Now if there is 0 straight tracks - no multi track routing to be done. If there is 1 straight track then do a currently implemented drag. If there is 2 or more tracks selected, wait for the user to do a down press on the left mouse button. Find the closest open track end. The mouse will jump to that track. All other selected open track ends will move in the same direction. Thats the easy bit. The harder bit is doing a 45deg turn. All the trace ends need to turn at 45deg and maintain the same distance between the traces. 

I started to look at the cpp code and the dev tools to do this. As a background I am a hardware designer and do embedded C and on the PC use Python to do all PC GUI (pySimpleGUI) and interfacing work. I dropped staying up with cpp many decades ago, and though I could do cpp, have chosen to stay away from it, focusing more on hardware - PCB design - and mech/electronic production processes - using Python for development testing.

I see KiCad now supports Python based Action Plugins. I have watched a number of YouTube videos and done some reading of others developments using Python. The great work by Miles McCoo on routing his LED PCB mostly by Python scripts was very impressive. Also a number of other modules in Python - taking off.

So how to implement the multiple track drag feature? 
1. Implement in pcbnew in cpp. Need to have a handle on cpp development environment and pcbnew drag implementation. What scares me personally here is the cpp development environment.
2. Implement in Action Plugin in Python. Need to have a handle on Python, but does the Action Plugin interface support user mouse clicks and mouse movements across the PCB? What happens when the user wants to pan or zoom. I am not sure if the Python Action Plugins support PCB interaction while in Python.

I really want to develop first in Python, but need some help on clarifying if Python can have the user interact with the PCB.

If this is possible, then I will develop the drag algorithm in Python first. Then once the algorithm is robust, others can use it. If it is too slow from Python, then someone with cpp skill could take the algorithm and implement in cpp. That might be me, or could be a more skilled KiCad cpp developer.

As a first step, could someone please clarify if Python Action Plugins could interact with user mouse movements on the PCB?

Planning on being at KiCon later this year. Hope to see you there.

Regards
Stuart



Andrew Lutsenko

unread,
Jul 3, 2023, 8:35:09 AM7/3/23
to dev...@kicad.org
Hello Stuart,

Current python api does not support interactive tool-like plugins, no mouse or keyboard events are passed to the plugin. Plugin API is simple and transactional, kicad instantiates a plugin object and calls its Run() method. After the method completes, kicad checks if anything changed on the board and updates the ui. That's it.

Hope that helps.

What you want to implement is a great feature and I would love to see it in kicad too but it will have to be done in cpp.

Best,
Andrew

--
You received this message because you are subscribed to the Google Groups "KiCad Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to devlist+u...@kicad.org.
To view this discussion on the web visit https://groups.google.com/a/kicad.org/d/msgid/devlist/baeb8e8a-27eb-43d9-a61c-d1b733fe3df1n%40kicad.org.

Tomasz Wlostowski

unread,
Jul 3, 2023, 9:11:23 AM7/3/23
to dev...@kicad.org, Stuart Tyler
On 03/07/2023 12:49, Stuart Tyler wrote:
> Hi, this is my first ever post here. I am really impressed with the
> development of KiCad over the past few releases. The python interface is
> really good and I am keen to learn. I have been designing PCBs for a few
> decades now and keen to help improve KiCad.
>
> I have seen some discussion on supporting Flex/Rigid in Issue #12928 and
> #8118. This is way beyond my KiCad development ability, but this
> development is very important to taking KiCad to the next level - please
> reach out to me for any Beta testing on this development - I have
> designed many Flex/Rigid PCBs and know many of the implementation
> issues. This feature will open so many new development possibilities for
> KiCad.
>
> What I have been working on for the past few days is understanding how I
> can implement multiple track dragging from isssue #14983. I think this
> is something within my programming capability and is a feature that I
> really want. I cannot imagine having to route a decent sized PCB without
> this feature - and so I am keen to work on a simple solution.
>
Hi Stuart,

Thanks for your interest in contributing to KiCad.

To quickly answer your questions:
- Python is a bad idea because there's no interactive tools support in
the pcbnew Python API. It's intended to be used mostly for batch
(one-shot) tools.
- As for C++, the single track drag code is in pns_dragger.cpp.
(PNS::DRAGGER::Move() performs the actual computation of dragged trace's
geometry). I guess you could start by making another implementation of
PNS::DRAG_ALGO that drags multiple traces. It should be relatively
simple to implement in the "mark collisions" mode, but nowhere near
simple in walk/shove modes, especially when vias are attached to the
ends of any subset of the multidrag traces...

Tom

Eeli Kaikkonen

unread,
Jul 3, 2023, 11:28:35 AM7/3/23
to dev...@kicad.org
I now nothing about the PNS code but I wonder if there's more than
just superficial similarity with dragging multiple tracks and dragging
a footprint (or even a group of footprints) with tracks. This means:
could it be possible to combine, at least partly, these two use cases
in the implementation?
https://gitlab.com/kicad/code/kicad/-/issues/4214

Eeli Kaikkonen

Stuart Tyler

unread,
Jul 3, 2023, 12:58:32 PM7/3/23
to KiCad Developers
Thank you all for those pointers.

I suspected as much, and so it looks like off to cpp land I go. 

Thank you Tomasz Wlostowski for the pointer into the code base where to start looking for the implementation. Agree - I am only attempting "mark collisions" mode. Personally I never use push/shove or walk around when routing - by never I mean very rarely. The modes just destroy the good look and feel of a PCB.

Thanks for the pointer Eeli Kaikkonen to the component/part dragging issue. I did observe this issue too on the drag when I played with pcbnew, but that is not something that I want to tackle first up. That is one nasty problem, of which I am not interested in attempting to solve right now. The nastiness comes from footprints can have many trace orientations and what to do to drag the component is non-obvious.

Thanks
Stuart

Stuart Tyler

unread,
Jul 8, 2023, 5:32:11 AM7/8/23
to KiCad Developers, Stuart Tyler
Hi,
I seem to be progressing along. I now have a handle on the GUI and adding a new key stroke - I have coded up Alt-D for multi-track dragging for now - and I am examining ROUTER_TOOL::performDragging and understanding how this works in detail all the way down to LINE::dragCorner45 and all the other methods around it. There is quite a lot here to understand and how they all interact, but slowly I am understanding the complexities and how to make things work. 

My top level code is a copy of ROUTER_TOOL::performDragging and I am calling my top level ROUTER_TOOL::performDraggingMultiTrack. I am expecting to use all the same methods as used by performDragging, except only working on the selected traces in 45 deg mode, and highlight mode.

What I would like is to use printf() to output some debug information. I see that Tom uses this method - as the code is sprinkled with printf()'s behind #ifdef's. What I am not too sure on is how to get to the stdout on a gui application. I currently start pcbnew from within MS Visual Studio. I have looked around for a window that may have stdout with no luck. Do I need to start pcbnew from the command line?

When I go to the pcbnew build directory (..\build\x64-Debug\pcbnew) and try to run pcbnew it complains about python not being installed. I believe that is because the python path is not set correctly.

I then started playing with the (install)(bin\pcbnew.exe) to see if this version can be run from the command line - as I started to assume that the (pcbnew\pcbnew.exe) version was for running in the VS ide. 

When I run (bin\pcbnew.exe) from within VS ide or command line I get several system error screens saying 'The code execution cannot proceed because wxms32ud_html_vc_custom.dll was not found. Reinstalling the program may fix this problem." Several of these pop up and substitute _html_ for _code_, _aui_, and _net_. 

In VS under the Build menu, I saw an option 'Install kicad'. I press this, and I get a Install succeeded. But running from cmd line or VS still barfs the code execution errors above.

Hmm, what am I missing?

I can only currently run my compiled version of pcbnew from VS (pcbnew\pcbnew.exe). How to get to stdout to see printf? I am assuming once I can run it from cmd line that I should then see stdout.

Is there an install process that I am missing to use pcbnew from the command line?

Thanks
Stuart

Andrew Lutsenko

unread,
Jul 8, 2023, 6:09:51 AM7/8/23
to dev...@kicad.org, Stuart Tyler
On windows GUI apps don't have stdout. You can use wxLog/wxTrace methods to debug.

Also see section 4 of build docs for hints on how to run kicad from build directory and what env vars to set so it can find python and other libs.



--
You received this message because you are subscribed to the Google Groups "KiCad Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to devlist+u...@kicad.org.

Jeff Young

unread,
Jul 8, 2023, 7:25:55 AM7/8/23
to dev...@kicad.org
I use CLion rather than MS Visual Studio, but if I run KiCad from CLion then there’s a “Run” window where it dumps the stdout to.

Did you find the debug decorator in the PNS Router code? It draws a bunch of graphical stuff on the canvas showing the start and end items, attempted paths, etc.

Cheers,
Jeff.

Alex Shvartzkop

unread,
Jul 8, 2023, 7:30:49 AM7/8/23
to dev...@kicad.org
To make stdout console window appear on Windows, set KICAD_ALLOC_CONSOLE environment variable in launch.vs.json or system-wide.

Stuart Tyler

unread,
Jul 8, 2023, 10:58:00 AM7/8/23
to KiCad Developers, dudesuc...@gmail.com
Thank you  for the tip on setting the launch environment variable  KICAD_ALLOC_CONSOLE. That worked. Now I can see printf() output.

Jeff, I have been seeing the decorator stuff in the code. What is the standard way of turning this on? I also see LOGs being used. m_logger->Log(). I follow this to being pushed onto m_events and accessed in method TOOL_EVENT.

What I am missing is how to access m_events from the screen or a log file. A pointer to accessing the decorator and logs would be appreciated.

Ta
Stuart


Jeff Young

unread,
Jul 8, 2023, 3:25:21 PM7/8/23
to dev...@kicad.org
At least some of the debug decorator can be turned on by putting “ShowRouterDebugGraphics=1” in your kicad_advanced file (a text file in your kicad preferences directory).  I’m not sure if that turns on all of it or not….

I’ve only used the logging stuff once.  I broke in the debugger and called saveRouterDebugLog().  (But I’m sure there’s a more automated way to do it.)

--
You received this message because you are subscribed to the Google Groups "KiCad Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to devlist+u...@kicad.org.

Stuart Tyler

unread,
Jul 8, 2023, 5:11:27 PM7/8/23
to KiCad Developers, je...@rokeby.ie
Thank you very much for the pointer to kicad_advanced file and saveRouterDebugLog()
I can see in the code all the settings that are valid for kicad_advanced, and I successfully turned on the ShowRouterDebugGraphics and I can now see the decorator and additional information being displayed by pcbnew and pns router.
I also looked up where saveRouterDebugLog() was called from, and I see in ROUTER_TOOL::handleCommonEvents that once ShowRouterDebugGraphics is turned on, that key press '0' then dumps the logs to pns.log

I did this and I was able to inspect the pns inner workings.

Thank you for these important pointers.

Okay - I feel that I have the tools now to start working on the pns code. Thank you to the dev team for the assistance.

Regards
Stuart 

Jeff Young

unread,
Jul 8, 2023, 5:40:31 PM7/8/23
to dev...@kicad.org
> that key press '0' then dumps the logs to pns.log

He he… you’re already father along than me then. ;)
Reply all
Reply to author
Forward
0 new messages