kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #31888
Re: [PATCH] Math expression support for pad editor.
-
To:
kicad-developers@xxxxxxxxxxxxxxxxxxx
-
From:
Wayne Stambaugh <stambaughw@xxxxxxxxx>
-
Date:
Thu, 23 Nov 2017 10:13:47 -0500
-
In-reply-to:
<CADhJ=352eYNH4ect8N+OQecLhiCFChvFD9XeHBXVr58c3oLDYQ@mail.gmail.com>
-
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0
Michael,
All source code in kicad must have a license statement and that license
must be compatible with the GPL3+. This is mandatory to minimize the
possibility of legal repercussions.
Cheers,
Wayne
On 11/23/2017 10:03 AM, Michael Geselbracht wrote:
> Hi,
> these files were written by me. The comment blocks at the top are
> generated by Eclipse ("let" is my login name).
> I am afraid that the coding style is about the opposite of the rules for
> Kicad. But if you can use the code feel free to do so.
>
> The current implementation has some issues:
> 1. The "%g" format in sprintf() does some rounding which is probably
> undesired (15.12356 -> 15.1236).
> 2. The decimal separator is set to '.' the input language settings by
> the user are not taken into account.
> 3. I did not check for memory leaks or buffer overflows.
>
> - Michael
>
>
> On Thu, Nov 23, 2017 at 2:36 PM, Maciej Sumiński
> <maciej.suminski@xxxxxxx <mailto:maciej.suminski@xxxxxxx>> wrote:
>
> We still do not have the feature freeze, so there is still a chance to
> shove it to the master branch. I feel a bit uneasy about exprtk (over 1
> MB header file), but Michael's parser approach seems like a good
> solution to me. We can extend it later as the lemon format is not very
> complex.
>
> I took Michael's parser, but modified the way the expression evaluation
> is done in dialog windows. Instead of adding the evaluator and focus
> event handlers to each dialog, I wrote a wrapper around wxTextCtrl that
> handles the process. I also converted most of pcbnew text input controls
> to use the wrapper, so with the patch merged one should be able to
> evaluate math in almost every text control that expects a numeric value.
> If you are interested, the patches are in my branch [1].
>
> My only concern is about two files (libeval/numeric.[h,cpp], [2]) that
> have an author, but no license. Michael, where did you get these files?
> We should contact the author to get permission to use the code.
> Otherwise we will need to replace these files.
>
> Regards,
> Orson
>
> 1.
> https://code.launchpad.net/~orsonmmz/kicad/+git/kicad/+ref/expr_eval
> <https://code.launchpad.net/~orsonmmz/kicad/+git/kicad/+ref/expr_eval>
> 2.
> https://git.launchpad.net/~orsonmmz/kicad/tree/common/libeval/numeric_evaluator.cpp?h=expr_eval
> <https://git.launchpad.net/~orsonmmz/kicad/tree/common/libeval/numeric_evaluator.cpp?h=expr_eval>
>
> On 09/02/2017 05:49 PM, Michael Geselbracht wrote:
> > Creating a variable looks a bit complicated to me. And if I see it
> > correctly it is not possible with exprtk to use constants with units
> > (0.16").
> > Maybe it would be possible to provide functions that do the math like
> > fromInch(0.16).
> >
> > That is the beauty of a parser generator. You can define the
> desired syntax
> > yourself.
> >
> > I have added support for variables to my parser approach. Now I
> can write
> > things like this:
> >
> > [Scratch Pad, global unit set to inch]
> > e=0.4mm; L=0.8mm; E=2.5mm
> >
> > PosX: -3.5*e
> > PosY: E/2-L/2+0.1mm
> >
> > I have attached a patch of my implementation. It adds the
> evaluator (object
> > size ~120kB) and includes it to the pad- and footprint dialogs.
> > The pad dialog contains a (misaligned and too small) scratch pad.
> >
> > The code is a mess and wouldn't make it into Kicad. But it works
> for me and
> > maybe you'll end up with your own parser solution.
> > The interface is not too different from exprtk so you wouldn't have to
> > throw away your work. If you want to play with the grammar
> > file you'll need the lemon parser generator ($ lemon grammar.lemon).
> >
> > - Michael
> >
> >
> > On Fri, Sep 1, 2017 at 3:23 AM, Russell Oliver
> <roliver8143@xxxxxxxxx <mailto:roliver8143@xxxxxxxxx>>
> > wrote:
> >
> >> Scratch Pad:
> >> I think this will be easily doable as an additional text box in the
> >> dialog, which is then added to the beginning of the expression
> for each
> >> text box. The format for the math library is as follows
> >>
> >> (a) Initialise x to zero
> >> var x;
> >>
> >> (b) Initialise y to three
> >> var y := 3;
> >>
> >> (c) Initialise z to the expression
> >> var z := if (max(1,x + y) > 2,w,v);
> >>
> >> Global variable support:
> >> I think this is possible but a simpler path might be to use a global
> >> scratch pad, which would be added first to the beginning of the
> expression
> >> used for the text box.
> >>
> >> Currently the expression text ie something like "posx + 1" isn't
> saved
> >> within the dialog or for the component.
> >>
> >> Regards
> >> Russell
> >>
> >>
> >>
> >>
> >>
> >> On Fri, Sep 1, 2017 at 7:46 AM Michael Geselbracht <
> >> mgeselbracht3@xxxxxxxxx <mailto:mgeselbracht3@xxxxxxxxx>> wrote:
> >>
> >>> Hi,
> >>>
> >>> I have tested the patch and I really like this feature. This
> automatic
> >>> variable assignment will sure come in handy.
> >>> How about adding a kind of scratch pad (a single line should do)
> to the
> >>> footprint editor so that one can add variables (measurements)
> given in
> >>> datasheets?
> >>> Like "c1=2.9; e=0.635" in the scratch pad and then in PosX
> field: "-c1/2
> >>> " and PosY: "-1.5*e" in order to place the first pad.
> >>>
> >>> - Michael
> >>>
> >>>
> >>> On Thu, Aug 31, 2017 at 3:58 PM, Tomasz Wlostowski <
> >>> tomasz.wlostowski@xxxxxxx <mailto:tomasz.wlostowski@xxxxxxx>> wrote:
> >>>
> >>>> On 31.08.2017 15 <tel:31.08.2017%2015>:27, Russell Oliver wrote:
> >>>>> Hi All.
> >>>>>
> >>>>> As a follow up to my earlier post, attached is a patch that
> implement
> >>>>> math expressions in the pad editor as well.
> >>>>>
> >>>>> A nifty feature is that the fields can be referenced from each
> other.
> >>>>> currently the fields are referenced by the following names.
> >>>>> - posx, posy, sizex, sizey, offsetx, offsetx, drillx, drillx.
> >>>>
> >>>> Hi Russell,
> >>>>
> >>>> Didn't have the time to check your patch yet, but I came up with an
> >>>> idea: add global variable support to the math parser, so that
> if you
> >>>> place a text anywhere in the design assigning to a variable (e.g.
> >>>> var=10), it will be updated in any of the expressions that
> reference it.
> >>>>
> >>>> Cheers,
> >>>> Tom
> >>>>
> >>>> _______________________________________________
> >>>> Mailing list: https://launchpad.net/~kicad-developers
> <https://launchpad.net/~kicad-developers>
> >>>> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >>>> Unsubscribe : https://launchpad.net/~kicad-developers
> <https://launchpad.net/~kicad-developers>
> >>>> More help : https://help.launchpad.net/ListHelp
> <https://help.launchpad.net/ListHelp>
> >>>>
> >>>
> >>> _______________________________________________
> >>> Mailing list: https://launchpad.net/~kicad-developers
> <https://launchpad.net/~kicad-developers>
> >>> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >>> Unsubscribe : https://launchpad.net/~kicad-developers
> <https://launchpad.net/~kicad-developers>
> >>> More help : https://help.launchpad.net/ListHelp
> <https://help.launchpad.net/ListHelp>
> >>>
> >>
> >
> >
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~kicad-developers
> <https://launchpad.net/~kicad-developers>
> > Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> > Unsubscribe : https://launchpad.net/~kicad-developers
> <https://launchpad.net/~kicad-developers>
> > More help : https://help.launchpad.net/ListHelp
> <https://help.launchpad.net/ListHelp>
> >
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> <https://launchpad.net/~kicad-developers>
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> Unsubscribe : https://launchpad.net/~kicad-developers
> <https://launchpad.net/~kicad-developers>
> More help : https://help.launchpad.net/ListHelp
> <https://help.launchpad.net/ListHelp>
>
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
>
References