Nester

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Nester

Post by yorik »

My nesting code is finally up enough to be merged, so it is now merged in git commit aba433880.

Warning, it is still very rough, slow and buggy. It will only work with pretty simple shapes like in the example below. It will still need a lot of work to become reasonably fast.

How it works:

1) create a series of flat shapes. They must all, at the moment, contain exactly one face, and have the same normal (same orientation). One of the shapes, that will be the container, must be rectangular. All these restrictions should be removed in the future.
Screenshot from 2017-07-18 17-57-08.png
Screenshot from 2017-07-18 17-57-08.png (105.01 KiB) Viewed 9920 times
2) Press the "Nest" button under the Arch panel tools

3) Add the container shape as Container, and all the others as Shapes

4) Change settings if you wish, then press "Start"
Screenshot from 2017-07-18 17-57-40.png
Screenshot from 2017-07-18 17-57-40.png (176.51 KiB) Viewed 9920 times
5) Wait for the calculation to finish. On my machine, nesting the shapes here take around one minute (I told you, it's slow).

6) Click "Preview"

7) If you like the solution, press "Ok". The preview will disappear and the shapes will all be moved to occupy the correct position.
Screenshot from 2017-07-18 17-59-04.png
Screenshot from 2017-07-18 17-59-04.png (111.8 KiB) Viewed 9920 times
There is still a lot of work to do, allow non-rectangular container, add support for margins/padding, allow some pieces to restrict to certain rotations, etc... Plus a lot of optimizing, and maybe making some of it multi-threaded, since several parts of the process could run in parallel, and after all that, allow to make several passes to refine the solution (by swapping pieces order). But it works already, that's already a big step :)

The code is divided between the task panel, which is in ArchPanel.py, and the nesting algorithm itself, which is in ArchNesting.py. The idea is that it could be used by other workbenches in case they don't like the task panel, they could build other GUI tools around it.

I tried to organize and comment that file a lot, so hopefully other people will be interested im jumping in and helping to optimize it.
Attachments
testshapes.fcstd
(31.77 KiB) Downloaded 217 times
User avatar
bitacovir
Veteran
Posts: 1570
Joined: Sat Apr 19, 2014 6:23 am
Contact:

Re: Nester

Post by bitacovir »

Impressive.
Well done Yorik :D
::bitacovir::
==================
One must be absolutely modern.
Arthur Rimbaud (A Season in Hell -1873)

Canal Youtube Grupo Telegram de FreeCAD Español

My personal web site
My GitHub repository
Mini Airflow Tunnel Project
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Nester

Post by looo »

Nice to see some work done in this direction.

Just tried it, but the result wasn't that smooth:
nesting.png
nesting.png (6.79 KiB) Viewed 9869 times
Also I first tried it with some custom face-objects, which use ViewProvider.Proxy=0 and therefore have no "getIcon". This makes your script fail. I believe it is in this line:
https://github.com/FreeCAD/FreeCAD/blob ... l.py#L1304

and could be solved by checking for:

Code: Select all

if hasattr(obj.ViewObject,"Proxy") and hasattr(obj.ViewObject.Proxy, "getIcon"):
But anyway, great work!

Once the solver is working it shouldn't be too much work to get it implemented in c++ and use some multi-threading. I believe this will speed up the algorithm quite a bit :D
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Nester

Post by yorik »

looo wrote: Wed Jul 19, 2017 3:41 amJust tried it, but the result wasn't that smooth:
Do you still have the file? It's a good, simple test case that fails, it's useful...
looo wrote: Wed Jul 19, 2017 3:41 am could be solved by checking for:

Code: Select all

if hasattr(obj.ViewObject,"Proxy") and hasattr(obj.ViewObject.Proxy, "getIcon"):

But anyway, great work!

Once the solver is working it shouldn't be too much work to get it implemented in c++ and use some multi-threading
Thanks, I'll add that fix. Yeah, the idea obviously is to port it to C++ once it's robust enough. Since a big part of the slowdown is lists processing, only that will make a huge difference. It only uses basic Part stuff so it should be easy. But at the moment it's much easier for me to develop/test in python...

I just found out that the good old DraftGeomUtils.findIntersection() function is faster than Part.distToShape()!
cox
Posts: 971
Joined: Wed Nov 26, 2014 11:37 pm

Re: Nester

Post by cox »

Frantic applause, from the North. :-) Nice feature.
Need help? Feel free to ask, but please read the guidelines first
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Nester

Post by chrisb »

Since a long time I have link bookmarked to http://svgnest.com/. I guess it can be deleted now :)
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

Re: Nester

Post by emills2 »

very nice.
we can already 'pre-pad' the shapes to account for cut width, but do you have any plans to include an adjustable spacing between the parts and the edges?
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Nester

Post by yorik »

emills2 wrote: Sat Jul 29, 2017 9:45 pmdo you have any plans to include an adjustable spacing between the parts and the edges?
yes of course... That, and the ability to use non-rectangular container, is what I'll do next
dschwartfeger
Posts: 2
Joined: Tue Mar 06, 2018 7:29 pm

Re: Nester

Post by dschwartfeger »

It wouldn't run for me until I changed the following-
I'm not sure if this is the correct way to do things but found a similar problem on the net and it worked!

Code: Select all

        if FreeCAD.GuiUp:
            from PySide import QtGui
            #changed qApp to QApplication.instance() on the next line
            QtGui.QApplication.instance().processEvents()
thanks for the good work.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Nester

Post by looo »

I guess this should be included in master already:
https://github.com/FreeCAD/FreeCAD/pull ... 5f3c4R1347
Post Reply