Nester

Info about new implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
User avatar
yorik
Site Admin
Posts: 10198
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Nester

Postby yorik » Tue Jul 18, 2017 9:19 pm

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 2679 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 2679 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 2679 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 42 times
User avatar
bitacovir
Posts: 377
Joined: Sat Apr 19, 2014 6:23 am
Contact:

Re: Nester

Postby bitacovir » Wed Jul 19, 2017 3:10 am

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

My Blog
Mini Airflow Tunnel Project
looo
Posts: 2067
Joined: Mon Nov 11, 2013 5:29 pm

Re: Nester

Postby looo » Wed Jul 19, 2017 3:41 am

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 2628 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
Site Admin
Posts: 10198
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Nester

Postby yorik » Wed Jul 19, 2017 1:34 pm

looo wrote:
Wed Jul 19, 2017 3:41 am
Just 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: 950
Joined: Wed Nov 26, 2014 11:37 pm

Re: Nester

Postby cox » Wed Jul 19, 2017 3:07 pm

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

Re: Nester

Postby chrisb » Wed Jul 19, 2017 4:37 pm

Since a long time I have link bookmarked to http://svgnest.com/. I guess it can be deleted now :)
emills2
Posts: 503
Joined: Tue Apr 28, 2015 11:23 pm

Re: Nester

Postby emills2 » Sat Jul 29, 2017 9:45 pm

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
Site Admin
Posts: 10198
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Nester

Postby yorik » Mon Jul 31, 2017 3:17 pm

emills2 wrote:
Sat Jul 29, 2017 9:45 pm
do 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

Postby dschwartfeger » Mon Apr 23, 2018 6:27 am

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.
looo
Posts: 2067
Joined: Mon Nov 11, 2013 5:29 pm

Re: Nester

Postby looo » Mon Apr 23, 2018 7:53 am

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