openscopeproject / InteractiveHtmlBom

Interactive HTML BOM generation plugin for KiCad, EasyEDA, Eagle, Fusion360 and Allegro PCB designer
MIT License
3.64k stars 459 forks source link

A couple of enhacement suggestions #246

Open Jacajack opened 3 years ago

Jacajack commented 3 years ago

Hi,

First of all, thank you for this great project - it's really helpful and helps to save a lot of time.

Today I used the interactive BOM during assembly of two rather large PCBs (~350 BOM entries each). Based on my first impressions, I came up with a list of suggestions that could make manual assembly process a bit smoother. I just wanted to know if there's any chance that these could be implemented in the future versions:

This was my first time using this tool, so I suppose some of the features I mentioned might already exist, but I could have just missed them. In any case, if you think that any of these are worth having, I could try (I'm not very good with Python) to implement some of them and open a PR.

Thanks

qu1ck commented 3 years ago

Hi, thanks for the suggestions, let me address them in same order:

I'm not totally opposed to implementing something like this but usability issues need to be considered thoroughly. For example question of "how much zoom" can be answered with either "let user zoom in once and set it as preferred zoom" or "heuristically determine zoom for each component as bounding box taking 10% of viewport area or being 20px on longest dimension, whichever is smaller". Question of "how can user understand which piece of board is zoomed in" is typically resolved with drawing a minimap of the image in a corner with a rectangle representing viewport area.

If you'd like to help then the proximity thing will be in python but autozoom feature will be entirely in javascript.

Jacajack commented 3 years ago

Thanks for your quick and detailed response

Jacajack commented 3 years ago

As for the spatial ordering, here's what I got using the BVH so far: Figure_1 It's not perfect and there are still a couple of things to tweak, but I think it looks quite good already.

qu1ck commented 3 years ago

Alt+[1-9] shortcuts already exist and work when focus is in text field. They don't advance the row like N does but Alt+char is used in some locales to enter variations of the character so I'd like to avoid using such shortcut.

Regarding spatial ordering, first of all: awesome discussion. You never know when some hardcore CS stuff will pop into relevance even in something so utilitarian in function as bom generation.

Second, I like your ideas and BVH graph looks a lot better than random. I also pondered on your MST idea with BFS and I think it can be improved quite a bit:

  1. Use DFS instead of BFS. BFS will jump around a lot on later stages.
  2. Choose start node smartly: a leaf node on one of the ends of a longest path of the tree should work fine.
  3. Sort child nodes by angle relative to "entry" edge so that you traverse subtrees in, say clockwise order.

This should be pretty good and maybe some more optimization can be added if we visualize it.

qu1ck commented 3 years ago

Another thing we can do for any algorithm as post optimization:

Say the path we found is A1..An, say the longest edge is Ai-Ai+1 Try to find 0<j<i such that if we take subpath Aj-Ai and reverse it in place so that resulting path will be A1..Aj-1-Ai-Ai-1..Aj-Ai+1..An and it's total length is less than initial path. Do the same on the other side of the longest edge.

Repeat the operation reasonable amount of times thus continually reducing overall length.

Each optimization attempt for an edge should be O(n) so for n<300 we can try about n^2 optimizations. There won't be too many large groups on any board anyway.

What do you think?

Jacajack commented 3 years ago

Alt+[1-9] shortcuts already exist and work when focus is in text field. They don't advance the row like N does but Alt+char is used in some locales to enter variations of the character so I'd like to avoid using such shortcut.

That's right, I didn't think of that, but unfortunately unlike N these shortcuts do not advance the selection. One little thing, though - in Firefox Alt+1...9 are used to switch between tabs by default and it seems that you forgot to override the default behavior with preventDefault(). I just fixed that and will submit a pull request in a second (#247).

Regarding spatial ordering, first of all: awesome discussion. You never know when some hardcore CS stuff will pop into relevance even in something so utilitarian in function as bom generation.

That's exactly what I though too! I never thought I would ever have to write a BVH tree to optimize component placement :)

As for the MST method, you're right - DFS will probably be better. Initially I thought it would be more "jumpy" than BFS, but if you start at the end of the longest path in the tree, it should be better. I like the idea of sorting the nodes by relative angle too. I might implement that later and see how it performs. Right now, I'm still playing around with the BVH and I think I can improve it by a lot by changing the order in which the nodes are visited at the end. Maybe the MST-based algorithm will come useful here? We'll see...

Another thing we can do for any algorithm as post optimization: [...]

Sounds like something worth trying, but I have to admit that it's hard for me to visualize in my head how effective that will be. Still, definitely a something to keep in mind :)

qu1ck commented 3 years ago

Sounds like something worth trying, but I have to admit that it's hard for me to visualize in my head how effective that will be. Still, definitely a something to keep in mind :)

The idea here is to see if we can get rid of long jumps between tight sections by flipping start and end points of some tight sections. Here is a visualization (forgive my scribbles in the most advanced graphics editor ever known, ms paint): pic

When applied a lot of times it will have a tendency to also uncross all overlapping edges and "unwind" the spiral into more of a zigzag.

Jacajack commented 3 years ago

I think this approach can be generalized a bit and replaced with a genetic algorithm (for approximating TSP solution). Maybe then we could determine the optimal order in three passes:

  1. Group together close vertices with BVH.
  2. Inside each group (leaf) determine the shortest path using said genetic algorithm.
  3. Extract the first and last vertices from all these paths and connect them with "mandatory" bidirectional edges. Use similar genetic algorithm to find the shortest path passing through all the mandatory edges.

What do you think about that?

qu1ck commented 3 years ago

I don't think it will work too well because

TSP heuristics page has a MST based algorithm and it even has decent upper bound on solution deviation from optimum.

Unsurprisingly someone thought of the edge replacement optimization long before me, it is described on the same page, see "Pairwise exchange" section.

I vote for not treading a new path in this well researched problem.

qu1ck commented 3 years ago

One advantage of following BVH path is that it may generate a route that feels more "natural" even if other algorithm provides a shorter path. We may have to build the alternative and compare the results visually to make a call on that.

Jacajack commented 3 years ago

Okay, I'll try out the k-opt technique and maybe the BVH+TSP combo too if I have some time this week. I'll let you know when I have some results.