Modify Path to my needs. How?

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Modify Path to my needs. How?

Post by sliptonic »

jcf wrote:Now I can generate a contour path by script.

The next step is to attack the profile path.
I have looked at the code which seems to be more complex, while part of this complexity lies in guessing the base object as it seems to me.
I have not fully understood which kind of object this must be. May it be 2D? For my approach the easiest would be Rectangle, Circle etc.
The contour and profile operations are always generating their paths from 2D geometry. We're staring with 3D objects because that helps us make reasonable guesses at starting and ending depths but the actual path is calculated from 2D. They get the needed geometry by projecting 3D objects onto a plane and there are several helper functions available to make this easier.

for example, you can take a sold object and do:

Code: Select all

import TechDraw
mywire=TechDraw.findShapeOutline(myobj.Shape, 1, Vector(0,0,1))
This gives you a wire for the outside silhouette of your object. From that, you can get the edges:

Code: Select all

edgelist = mywire.Edges
Sort them:

Code: Select all

edgelist = Part.__sortEdges__(edgelist)
Once you have the edges, you can start building your path commands. You might want to look at PathContour._buildPathLibarea() to get started.
Or would it be better to switch to 3D? Note that my decision to start with 2D and to write my own code was that there were difficulties making a path at all, and problems with changes in FreeCAD that made me going mad as what worked yesterday did not work today. So I hoped that if I understand the code I can build something that works for me, as long as FreeCAd is still evolving.

So my question is: how can I make a contour path by code, based on objects that I selected befor or that I set by code?
Much of the complexity in Path has to do with handling user selections, making guesses at depths, keeping track of tools, etc. Be careful you don't start trying to reinvent all those wheels too.
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Re: Modify Path to my needs. How?

Post by jcf »

Thank you, sliptonic! :)
sliptonic wrote: Much of the complexity in Path has to do with handling user selections, making guesses at depths, keeping track of tools, etc. Be careful you don't start trying to reinvent all those wheels too.
That's effectively something that stresses me a bit for the moment, that I have the feeling of doing something that others have already done, supposedly better.
On the other hand I do not see how I could get involved in elaborating the software, or do you see anything that I could do?
Anyway, it seems necessary for me to understand as much of the code as possible, if I want to do it on my own or if I would want to collaborate.

For the profile path, my idea would be the following:
1. select objects
2. push button to make contour
3. set depth and eventually other parameters (most will be predefined in my case)

I'll have a look at your suggestions an will try them out!
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Re: Modify Path to my needs. How?

Post by jcf »

I have tried to get an edgelist. This works fine for a Rectangle.

But with a circle it gives an error:

Code: Select all

mywire=TechDraw.findShapeOutline(myobj.Shape, 1, Vector(0,0,1))
<class 'Part.OCCError'>: GeometryObject::projectShape - error occurred while projecting shape
I am not so much astonished as a circle has an infinity of edges. But what do I do in this case? Most of my objects are round!
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Modify Path to my needs. How?

Post by chrisb »

If you execute the code in the python console you can view the members and their values of the current object. You have probably a Curve and not an Edge.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Re: Modify Path to my needs. How?

Post by jcf »

chrisb wrote:If you execute the code in the python console you can view the members and their values of the current object. You have probably a Curve and not an Edge.
Of course: a circle is a curve and not made of edges :D
So what do I do to make a PathProfile?
Maybe I have to select another Script like PathFromShape or PathFromFace??

I have had a look at PathFromFace.
There it seems as if I would find what I need

Code: Select all

shape = getattr(obj.Base[0].Shape, obj.Base[1][0])
            if shape.ShapeType == "Wire":
                wire = shape
            else:
                wire = shape.OuterWire
                ....
                
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Modify Path to my needs. How?

Post by sliptonic »

jcf wrote:
sliptonic wrote: Much of the complexity in Path has to do with handling user selections, making guesses at depths, keeping track of tools, etc. Be careful you don't start trying to reinvent all those wheels too.
That's effectively something that stresses me a bit for the moment, that I have the feeling of doing something that others have already done, supposedly better.
On the other hand I do not see how I could get involved in elaborating the software, or do you see anything that I could do?

Anyway, it seems necessary for me to understand as much of the code as possible, if I want to do it on my own or if I would want to collaborate.
I understand that desire but I think it's enough to understand the rough landscape of the whole thing and the specific details of the areas you want to work on. I understand Path pretty well but I'm completely lost outside that workbench. Still, over time, I'm learning more about Arch, Draft, and OCC.

There are DEFINITELY ways to get involved and contribute right now without even digging into the guts. It depends on your expertise and interest. The obvious answers for beginners are tracking down bugs and writing documentation but here's some other ideas.

We need certain strategies and algorithms. These could be hacked up in a macro and we can figure out how to get them into the code later. Examples of things I would LOVE to see:
  • Given a list of vectors (drilling points) we need something like a TSP solver to order them for shortest path. There are lots of python TSP solvers on github but we need something license compatible and which doesn't introduce new dependencies.
  • I've wanted to do a dressup to map a path onto a 4th axis. So given a path with XY moves and a radius of the 4th axis surface, modify the path to map one of the two axes (X or Y) onto A or B. The X/Y distance will be translated into an A/B rotational distance.
  • Our current engraving is really weak. It just follows the outside edges of the shapestring. F-engrave can do center-line 'v-carving' engraving and his code could be studied and rewritten to do something similar in FreeCAD. There are other strategies too like openvoronoi.
  • given a closed wire, which might include nested wires, find a point inside it where it's safe to do a helical descent using a tool of size r. The tool shouldn't clip the outer or any of the inner wires.
If you have expertise in QT, I have a stalled project working on the tool library manager and need some help.

RealThunder's new libarea wrapper needs exploration.

I'm sure there's more :D If you want help finding a project of limited scope to work on, chat with me on gitter or IRC. I'm sure we can find something.
For the profile path, my idea would be the following:
1. select objects
2. push button to make contour
3. set depth and eventually other parameters (most will be predefined in my case)

I'll have a look at your suggestions an will try them out!
This is pretty much how contour works now. You select one object for a job. Click contour, and get the path. params can be adjusted. It should be possible to select a 2D object for the job and get decent paths for the operations. The UI will need some attention though. For example, if the Job is working on a 2D object, it shouldn't be possible to add a 'surface' operation.
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Re: Modify Path to my needs. How?

Post by jcf »

sliptonic wrote: There are DEFINITELY ways to get involved and contribute right now without even digging into the guts. It depends on your expertise and interest. The obvious answers for beginners are tracking down bugs and writing documentation
I am willing to share any documentation arising in the process of trying to understand the Path modules.
Maybe I could do some contribution to the Path scripting chapter in the Doc that ends where I want to begin.
sliptonic wrote: but here's some other ideas.
These seem a bit off my reach for the moment. Maybe later??
sliptonic wrote: If you have expertise in QT, I have a stalled project working on the tool library manager and need some help.
I have not worked with Qt yet, only with wxPython and Tkinter.
sliptonic wrote: I'm sure there's more :D If you want help finding a project of limited scope to work on, chat with me on gitter or IRC. I'm sure we can find something.
Äääähmmmm.... :oops: .... I have never chatted in my life ... how do I do?
For the profile path, my idea would be the following:
1. select objects
2. push button to make contour
3. set depth and eventually other parameters (most will be predefined in my case)
This is pretty much how contour works now. You select one object for a job. Click contour, and get the path. params can be adjusted. It should be possible to select a 2D object for the job and get decent paths for the operations. ...
Your answer brought me to try the original again.
I updated Freecad-daily just now to

OS: Linux Mint 17.3 Rosa
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.10276 (Git)
Build type: None
Branch: master
Hash: 10191e90861cf0c87d24c1980761fd1c7f3cdde4
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17


When trying to switch to the Path workbench I got the error:

Code: Select all

cannot import name PathPreferencesPathDressup
Traceback (most recent call last):
  File "<string>", line 34, in Initialize
This kind of frustration was what started me to try to write my own part of code that would not stop working when I do an update.
Don't forget:
- the first reason for coding and trying to understand your code is that I want to use my machine that stands still for a long time already
(my colleagues always ask me why I do not want to buy a software, then everything should be very easy...)
- the second reason is: I love coding and I love FOS software! :)
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Modify Path to my needs. How?

Post by sliptonic »

jcf wrote:
sliptonic wrote: I'm sure there's more :D If you want help finding a project of limited scope to work on, chat with me on gitter or IRC. I'm sure we can find something.
Äääähmmmm.... :oops: .... I have never chatted in my life ... how do I do?
Go here:
https://gitter.im/FreeCAD/Path
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Re: Modify Path to my needs. How?

Post by jcf »

Thanks a lot!
I am looking at your Path videos, and that is already very enlightning :D
Post Reply