Parametric Curve FP discussion board

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board (latest: 0.2022.03.06.rev2)

Post by TheMarkster »

hammax wrote: Mon Mar 07, 2022 2:01 pm ... if I want to create a new Pc_Curve I have to call the macro.
It has already a predefined curve intus. Now comes the formula editing job.
I'm seeking for a start to get an "empty", or the most simple file (only a circle - R, sin(t), cos(t), e.g. ).
Rest can also be done with some (example)-JSON file, opened in the project, copy and paste jobs and later be deleted.

Here is the example that brought me to the recent form of ParametricCurve.
https://forum.freecadweb.org/viewtopic. ... 67#p569539
and the actual simplest state of my rope braiding trials.


RopeBraid.PNG
It's a good idea to have something really simple as default. It could be a simple circle. I don't want it empty because then it will show a failure, not a good first impression when somebody is first installing to try it out.

If you toggle New Formula it creates a new formula added to the JSON list. The new formula will contain all the same existing values as the current formula (IIRC), which you can then edit. The interface is terrible, I know. I have some ideas to improve it.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board (latest: 0.2022.03.06.rev2)

Post by TheMarkster »

Sneak peak at new formula editor. Still a bit of a work in progress, but I'll push the current update after I do a few chores.
Snip macro screenshot-677b3f.png
Snip macro screenshot-677b3f.png (36.27 KiB) Viewed 4098 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board (latest: 0.2022.03.06.rev2)

Post by TheMarkster »

Newest version: 0.2022.03.08

Features new formula editor. Double click the ParametricCurve object in the tree to bring up the editor, or toggle the EditFormulas property to True, or use the context menu in the tree.

In addition to what is shown in the image in the sneak preview in the previous post, I have also added a Clear button. This will clear the current formula (not the formula list).

Some properties related to formula editing have been removed, and the FormulaName property has been hidden:
Snip macro screenshot-5997b4.png
Snip macro screenshot-5997b4.png (71.33 KiB) Viewed 4041 times
But the code for handling those properties remains for now so objects created with the older versions will still (hopefully) work.

+ = add a new formula, a copy of the currently selected formula (goes to bottom of list)
- = delete selected formula
Copy = copy the currently selected formula to the clipboard in the form of a python dictionary
Paste = paste the current clipboard text into the currently selected formula
Rename = rename the currently selected formula
Clear = clear the currently selected formula

Reset = reset the dialog back to what it was when it first opened, undoing all changes you might have made (cannot be undone)
Apply = apply changes to the ParametricCurve object and recompute it (can be undone with Undo)
OK = close the dialog and apply all changes to the ParametricCurve object (can be undone with Undo)
Cancel = close the dialog and ignore all changes (except those applied)
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric Curve FP discussion board (latest: 0.2022.03.08)

Post by edwilliams16 »

So far, so good. Interface is definitely more user-friendly.
Screen Shot 2022-03-08 at 2.11.42 PM.png
Screen Shot 2022-03-08 at 2.11.42 PM.png (81.14 KiB) Viewed 4004 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board (latest: 0.2022.03.08)

Post by TheMarkster »

New version: 0.2022.03.09

I've added a few new buttons to the dialog and removed some properties.

Added: Open, Save, Append
Removed properties: Write File, Read File, and Open File.
File has been hidden, but remains so existing objects can still work as before (hopefully).

Open -- opens a file and loads it into the editor's memory, replacing existing contents. It does not affect the ParametricCurve object until you press OK or Apply. You can load a file, manipulate it, save it, and then click Cancel and it won't affect the PC object (unless there is a bug, of course).

Save -- saves to a JSON file. A dialog opens and you select the file each time. This overwrites any content of any existing file.

Append -- writes only the currently selected formula (NOT ALL FORMULAS!) to the selected file. If there is already a formula in that file with the same name, then you are prompted to enter a new name. It will not overwrite an existing formula. To replace a formula you would need to give this one a new name temporarily, then load that file, delete the old formula, and rename this one. Or you could use Copy and Paste.

The editor's memory contents are separate and apart from the ParametricCurve object's memory contents. Only when using OK or Apply does the PC Object's contents get updated. (Not true due to a bug in the previous version, so updating is definitely advised.)
Snip macro screenshot-a89a6c.png
Snip macro screenshot-a89a6c.png (75.92 KiB) Viewed 3941 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board (latest: 0.2022.03.09)

Post by TheMarkster »

Comments are also now allowed for the floating point properties: t_min, t_max, and interval (only in the JSON text, of course). All of the formula editing should be done in the dialog rather than using the properties directly, IMO.
User avatar
hammax
Veteran
Posts: 1985
Joined: Thu Jan 19, 2017 5:03 pm
Location: Ammersee DE

Re: Parametric Curve FP discussion board (latest: 0.2022.03.09)

Post by hammax »

... WOW many thanks for the improvements => much easier to understand and apply.
What a potential to create mathematical based forms.
My master file to create ParaCurves (with a fresh FC.19.4):

ParaCurve_2.PNG
ParaCurve_2.PNG (25.6 KiB) Viewed 3893 times
Attachments
ParCurve_1.FCStd
FC.19.4
(33.61 KiB) Downloaded 52 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board (latest: 0.2022.03.09)

Post by TheMarkster »

Excellent. I will add para_curve to the default formula list in the next update.

Next update will also have "ellipse" as the default formula:
Snip macro screenshot-9d583b.png
Snip macro screenshot-9d583b.png (45.92 KiB) Viewed 3793 times
Note the addition of a new function to the next update, which will be 0.2022.03.09.rev2:

ternary(a,b,c)

Read ternary as:

Code: Select all

if a != 0:
    return b
else:
    return c
In other words, if a, then b, else c.

Implemented in python as:

Code: Select all

b if a else c
Attachments
Parametric_Curve_FP.FCMacro
(77.89 KiB) Downloaded 51 times
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric Curve FP discussion board (latest: 0.2022.03.09)

Post by edwilliams16 »

Minor nitpick - if c is the eccentricity of the ellipse, you have the wrong formula for its minor radius.
Screen Shot 2022-03-09 at 5.00.50 PM.png
Screen Shot 2022-03-09 at 5.00.50 PM.png (44.8 KiB) Viewed 3751 times
should be
Screen Shot 2022-03-09 at 5.03.25 PM.png
Screen Shot 2022-03-09 at 5.03.25 PM.png (75.01 KiB) Viewed 3751 times

OTOH, this forces the major radius a, to be along the x-axis - so maybe just don't call it eccentricity - radius ratio perhaps.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board (latest: 0.2022.03.09)

Post by TheMarkster »

New version: 0.2022.03.10

Lots of changes.

New buttons in the dialog (feature creep starting to creep in)
Fixed bug in context menu
More error checking
Return null shape from makeCurve() if a shape cannot be constructed

The buttons top right are generally for the formulas in the top listbox, they work on a higher level than the ones below to the right. These bottom buttons generally work on the currently selected formula.

Clear All == zaps all the formulas, so should be used with some caution. It can't really be undone except you can use Reset, but this only gets you back to the state when the dialog was first opened.

Open == opens all formulas from a file, replacing those in the editor.

Save All == saves all formulas in the editor to a file, overwriting any contents of that file.

Append All == appends all formulas in the editor to a file, adding them to any formulas already in there. If there is a naming conflict you will be prompted for a new name for each formula that conflicts. Pressing cancel in that dialog aborts the operation, but everything already appended will remain in the file.

Import == Like Append, except it imports into the editor from a file. You can import all the formulas in the file or pick an individual formula to import. Like Appending, if there is a naming conflict you will be prompted for a new name for the formula being imported. Pressing cancel aborts the import operation, but everything already imported will remain.

Copy = copy the current formula to the clipboard in a text form that can be pasted into the editor. This is a way to share formulas between Parametric Curve objects.

Paste = paste the previously copied text from the clipboard into the current formula, overwriting it. Create a new formula before pasting so you don't zap one you want to keep.

Clear = clear all the variables in the current formula.

Save One = Save the currently selected formula to a file, overwriting all of its current contents, if any.

Append One = Append the currently selected formula to a file, adding to its current contents, if any.
Snip macro screenshot-1f046f.png
Snip macro screenshot-1f046f.png (73.97 KiB) Viewed 3717 times
Post Reply