yaqwsx / PcbDraw

Convert your KiCAD board into a nicely looking 2D drawing suitable for pinout diagrams
MIT License
1.16k stars 91 forks source link

Find board origin and crop out empty space #41

Closed FFY00 closed 3 years ago

FFY00 commented 4 years ago

Hey, currently pcbdraw only crops out at the vertical bottom limit of the board. Would it be possible to do the same in the other 3 side?

Example: luna_rev0

set-soft commented 4 years ago

Nice board! Did you try with this: https://github.com/yaqwsx/PcbDraw-Lib/blob/master/scrips/resize_canvas.sh

FFY00 commented 4 years ago

It is! I did not design it :sweat_smile:.

I haven't tried that, I will have a look tomorrow. It would still be cool to have it automatically done, would simplify populate and such.

yaqwsx commented 4 years ago

Currently, PcbDraw uses a board bounding box reported by KiCAD. This bounding box includes all items in the drawing (even the ones not used by PcbDraw). Cropping to only visible items makes sense. There are three ways to implement it:

I will think about it and try to implement it. Meanwhile, feel free to use the script above.

set-soft commented 4 years ago

I will think about it and try to implement it. Meanwhile, feel free to use the script above.

Please try to avoid the Inkscape dependency, is 172 MiB, is ok for my desktop, but an overkill for a docker image. I already avoided it for SVG conversions (is the default for convert tool).

FFY00 commented 4 years ago

I am not really aware of the API pcbnew exposes, but if you can iterate through the items and get the origin and size, it should be fairly straight forward to calculate the min and max x and y.

If this is difficult to do with the available API, you could pull inkscape as an optional dependency, disabling the functionality when it is missing.

yaqwsx commented 4 years ago

Don't worry, I do not plan to use Inkscape as it is a heavy dependency.

yaqwsx commented 4 years ago

Today I accidentally found svgelements. From the brief look, it looks exactly like what I need. It would also allow for dropping the SvgPathItem and replacing it with something more robust.

joaoantoniocardoso commented 4 years ago

Just to mention: that inkscape script doesn't work here, I had to use:

inkscape -D --export-filename=out.svg --verb=FileQuit in.svg

And yeah, inkscape is a big dependency...

yaqwsx commented 3 years ago

This was addressed in 27dafbc6acb31fb294cf749b3d06ee73f185ea6a