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!
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Modify Path to my needs. How?

Post by jcf »

I would like to build my own Path workbench that is focused on my needs and my machine.

I found info on writing my own modules and my own workbench, but there is one thing that I would need and that I didn't find out until now:
What is going on for example when I press the "New Job" button? Which functions in which script are called? Is the GUI interface for this programmed in C or Python? If I knew the answers to these questions I could modify the needed scripts and adopt the scripts exactly to my needs.

Can anyone give me a hint where to find this information?
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Modify Path to my needs. How?

Post by DeepSOIC »

Hi!
Toolbar buttons are initialized in InitGui.py (assuming you make a python workbench). To add a button to a toolbar, you need to first register a command. For that, you write a python class for the command, that tells what to do when it's clicked, as well as what its icon is, label, etc. Then you register it using FreeCADGui.addCommand("MyPath_NewProject", CommandNewProject()). Then it can be added to menus, toolbars (see Path's InitGui.py how it's done).
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:I would like to build my own Path workbench that is focused on my needs and my machine.
I don't want to discourage you from doing this because sometimes great things come out of a venture like that but I'd like to know more about what needs you have that aren't met.

For instance, is the current path workbench limited on object selection? path generation? output customization? Is the workflow too clunky? confusing?

I'm happy to help you get started but please help us understand how to improve the thing for everyone.
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Re: Modify Path to my needs. How?

Post by jcf »

@sliptonic:
For instance, is the current path workbench limited on object selection? path generation? output customization? Is the workflow too clunky? confusing?
Don't misunderstand me!
I didn't mean that anything is not well done.
I have several motivations for my idea:
1. I have a slight tendancy to always take another than the straight path to my aims. ;) (Don't know where it comes from, but it is so.)
2. It helps me a lot to get a deeper understanding (which I always like to have) doing this.
3. In fact, for my needs at the moment the procedure to generate a path is a little bit too complicated.
Let me tell you what I'd like to have for my private workbench (and if anyone is interested I'd like to share it):
  • A text window where I can enter codes for my drawings, like "c 5 5 30" (circle at (5,5) with diameter=30) or "r 10 15 60 40" (rectangle with left bottom corner at (10, 15) with length 60 and height 40).
    You may wonder why I do not like to draw this with the FreeCAD GUI, but I do not like fumbling with the mouse, text input is much faster.
    You notice that all the above is for 2D, as I use my machine mainly for making front plates for the moment. But it could be extended to 3D.
    (By the way, this part of my project is already done, if anyone is interested, I can share it.)
  • A button to create a Path job, for my machine, where I would only have a dialog (for the moment) to enter the mill diameter.
  • Some buttons similar to the original Path workbench where I could set the other parameters for the path
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Re: Modify Path to my needs. How?

Post by jcf »

@ DeepSOIC:
Toolbar buttons are initialized in InitGui.py (assuming you make a python workbench). To add a button to a toolbar, you need to first register a command. For that, you write a python class for the command, that tells what to do when it's clicked, as well as what its icon is, label, etc. Then you register it using FreeCADGui.addCommand("MyPath_NewProject", CommandNewProject()). Then it can be added to menus, toolbars (see Path's InitGui.py how it's done).
Thank you. Though I have not done it yet, I think I understand the principle and I think I can get it working.
My lack of knowledge is another:
Let's suppose I want to modify (simplify for my needs) the "Create Path job" part of the code.
Then I would like to take the original code (I hope it is in Python) and modify a copy of it so it does what I want.
My problem is that it is hard to find out where to find the function that is called by this button. I even don't know if it is written in C or Python.
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: Modify Path to my needs. How?

Post by chrisb »

jcf wrote:I even don't know if it is written in C or Python.
Most (all?) of the Path Workbench is written in Python. The scripts dwell in the directory Mod/Path and below.
Usually I would encourage you to rather join the common development than to program your own stuff but the workflow you describe is in fact so special that I don't see much in common. In fact, it sounds as if you don't need a 3D modelling tool at all, since it is almost the GCodes you want to enter. You may need a good GCode editor instead?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
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: Let me tell you what I'd like to have for my private workbench (and if anyone is interested I'd like to share it):
  • A text window where I can enter codes for my drawings, like "c 5 5 30" (circle at (5,5) with diameter=30) or "r 10 15 60 40" (rectangle with left bottom corner at (10, 15) with length 60 and height 40).
This sounds a lot like another kind of application called a 'conversational cnc' program. It's usually implemented closer to the machine and can be used to very quickly do simple task like planing and pocketing and can do more sophisticated work like bezels and drill patters as well.

You don't say what kind of controller you're using for your machine but if you're running Linuxcnc, you might check out linuxcnc-features.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Modify Path to my needs. How?

Post by microelly2 »

Two remarks from me:
The path wb is written in python, so you can create your own extension classes from there into your own files and add your special gui components
accessable by macro buttons.
reading the complete code is time consuming but asking a question here in the forum will help you.

to edit lists of data I use the table view widget (I started from the spreadsheet wb and then I decided to switch to a free temporary dialog)
this can be a way for you too
get the path data from path workbench
start your own post path editor - the table helps you to support the right syntax
and run your post commands

this is an example of the bspline/dwire editor
https://www.youtube.com/watch?v=CmhZlU1V46Y
and a more complex example
https://www.youtube.com/watch?v=f-6I7SRBDvs

the discussion was here:
viewtopic.php?f=3&t=16473&start=120#p152469
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Re: Modify Path to my needs. How?

Post by jcf »

chrisb wrote:Usually I would encourage you to rather join the common development than to program your own stuff
In fact I would love to do that...
but it's a question of time ( I think it will take a lot of time before understanding what others already have done and before one can get productive )
and, as you say, my needs for the moment are a little bit different.
But that will change with time... So, who knows... maybe some time later I can contribute.

Anyway, what I am doing now is good as I learn a lot.

By the way, my original goal was to use our CNC machine in the makerspace with only free open source software. I did a lot of research on which programs I could use, and first tryed HeeksCAd, and then came to FreeCAD.
jcf
Posts: 53
Joined: Tue Nov 15, 2016 10:34 am

Re: Modify Path to my needs. How?

Post by jcf »

microelly2 wrote:to edit lists of data I use the table view widget ...
That sounds interesting. I had a short look at your links, it is somewhat similar to what I did. If I had known before ...
maybe I would have done it this way. But I'm also happy with my solution. ;)
Last edited by jcf on Fri Jan 20, 2017 12:46 pm, edited 1 time in total.
Post Reply