Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
Thanks everyone for your input. First off, I too think it will get the most usage in the footprint editor, specifically when calculating the position and size of a pad from cryptic datasheet dimensions. I chose the schematic value entry dialog simply because its a small target. But even having the ability to calculate values using an expression when designing the schematic I think will be useful. With regard to exposing the exprtk library to the python interface its beyond my pay grade. At this point i'm ambivalent to what library is finally used, but exprtk was easy to integrate and as Tomasz pointed out comes as a single header file. It has plenty of features and from my reading of the docs it might be possible to use it to create a program wide parametric design system using hierarchical symbol tables. It does compile to a fairly large object file though ~43 MB. Since python is already integrated to it might also be suitable parser. I was actually looking for create a custom wx Control instead of creating the MathProcesssor class, but couldn't find a suitable example from the wxWidgets doc. I think it would be fairly easy to extend the WX_UNIT_BINDER control to include the parser, and a few find and replaces could spread the functionality across Kicad. In regards to using the equals sign to denote an expression, I think this will only be needed in fields where the the final value is a string. In combination with using OnTextEnter event, the user expressly denotes if the input string is to be evaluated or left as is for the odd case where they want to leave the equals sign in place. Otherwise for numerical inputs it can always be evaluated in the way Michael has implemented his. Kind Regards Russell On Mon, Aug 28, 2017 at 11:42 PM Michael Geselbracht < mgeselbrac...@gmail.com> wrote: > Incidentally I have written a similar calculator last week and included it > in Pcbnew. I used the lemon parser generator > but exprtk might be a better choice. That way it should be easy to extend > the calculator with support for > variables without re-inventing the wheel. > > I wanted to mimick the behaviour of Solidworks or CorelDraw; they do not > use '=' to introduce a formula. > The text is always interpreted as expression and constants may have units. > > So if I want to move a FP from x:80.442 50mil to the right I write (or > append) "80.442+50mil". > A difference is that I use the OnTextFocusLost event to start the > evaluation and OnTextFocusGet to restore > the previous text just before the evaluation (ups, should have been > 25mils). > > The next step would be to integrate the evaluator in the footprint editor > as well. But it does not seem to be wise > right now ;). > > > - Michael > > > > On Mon, Aug 28, 2017 at 2:45 PM, hauptmechwrote: > >> or perhaps the python parser is already used in enough kicad builds that >> it should be used? >> >> On 28/08/17 19:56, Tomasz Wlostowski wrote: >> >>> On 27.08.2017 22:28, Marco Ciampa wrote: >>> +1 muparser is already present in many distros: apt-cache search muparser libmuparser-dev - fast mathematical expressions parse library (development) libmuparser-doc - fast mathematical expressions parser library (documentation) libmuparser2v5 - fast mathematical expressions parser library (runtime) >>> ...And exprtk is a single header file, which compiles on any OS. There >>> is life outside Linux, too. >>> >>> - my 5 cents, >>> Tom >>> >>> >>> ___ >>> Mailing list: https://launchpad.net/~kicad-developers >>> Post to : kicad-developers@lists.launchpad.net >>> Unsubscribe : https://launchpad.net/~kicad-developers >>> More help : https://help.launchpad.net/ListHelp >>> >> >> >> >> ___ >> Mailing list: https://launchpad.net/~kicad-developers >> Post to : kicad-developers@lists.launchpad.net >> Unsubscribe : https://launchpad.net/~kicad-developers >> More help : https://help.launchpad.net/ListHelp >> > > ___ > Mailing list: https://launchpad.net/~kicad-developers > Post to : kicad-developers@lists.launchpad.net > Unsubscribe : https://launchpad.net/~kicad-developers > More help : https://help.launchpad.net/ListHelp > ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
Incidentally I have written a similar calculator last week and included it in Pcbnew. I used the lemon parser generator but exprtk might be a better choice. That way it should be easy to extend the calculator with support for variables without re-inventing the wheel. I wanted to mimick the behaviour of Solidworks or CorelDraw; they do not use '=' to introduce a formula. The text is always interpreted as expression and constants may have units. So if I want to move a FP from x:80.442 50mil to the right I write (or append) "80.442+50mil". A difference is that I use the OnTextFocusLost event to start the evaluation and OnTextFocusGet to restore the previous text just before the evaluation (ups, should have been 25mils). The next step would be to integrate the evaluator in the footprint editor as well. But it does not seem to be wise right now ;). - Michael On Mon, Aug 28, 2017 at 2:45 PM, hauptmechwrote: > or perhaps the python parser is already used in enough kicad builds that > it should be used? > > On 28/08/17 19:56, Tomasz Wlostowski wrote: > >> On 27.08.2017 22:28, Marco Ciampa wrote: >> >>> +1 muparser is already present in many distros: >>> >>> apt-cache search muparser >>> libmuparser-dev - fast mathematical expressions parse library >>> (development) >>> libmuparser-doc - fast mathematical expressions parser library >>> (documentation) >>> libmuparser2v5 - fast mathematical expressions parser library (runtime) >>> >> ...And exprtk is a single header file, which compiles on any OS. There >> is life outside Linux, too. >> >> - my 5 cents, >> Tom >> >> >> ___ >> Mailing list: https://launchpad.net/~kicad-developers >> Post to : kicad-developers@lists.launchpad.net >> Unsubscribe : https://launchpad.net/~kicad-developers >> More help : https://help.launchpad.net/ListHelp >> > > > > ___ > Mailing list: https://launchpad.net/~kicad-developers > Post to : kicad-developers@lists.launchpad.net > Unsubscribe : https://launchpad.net/~kicad-developers > More help : https://help.launchpad.net/ListHelp > ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
or perhaps the python parser is already used in enough kicad builds that it should be used? On 28/08/17 19:56, Tomasz Wlostowski wrote: On 27.08.2017 22:28, Marco Ciampa wrote: +1 muparser is already present in many distros: apt-cache search muparser libmuparser-dev - fast mathematical expressions parse library (development) libmuparser-doc - fast mathematical expressions parser library (documentation) libmuparser2v5 - fast mathematical expressions parser library (runtime) ...And exprtk is a single header file, which compiles on any OS. There is life outside Linux, too. - my 5 cents, Tom ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
On 8/28/2017 3:55 AM, Tomasz Wlostowski wrote: > On 27.08.2017 17:03, Russell Oliver wrote: >> Hi all, >> >> Attached is a patch that allows for the use of a mathematical expression >> when editing the value field of components in Eeschema. >> >> If editing the value field and the entered string begins with an equals >> sign "=" as you would when entering a formula into an Excel spreadsheet >> cell, it is compiled and parsed when the Enter button is pressed while >> the text entry is in focus. >> >> A valid expression is returned as a double value which is then printed >> with a format to remove trailing zeroes. An invalid expression will not >> change the text value. >> >> The expression parser is simple wrap of the C++ Mathematical Expression >> Toolkit Library (ExprTk) written Arash Partow and is under the MIT >> licence [1]. >> > Hi Russell, > > Looks great, I wanted to have such a feature for parametric mechanical > design. > > Have a look at the WX_UNIT_BINDER class - it's used in more recent > dialogs for inputting coordinates/sizes. Perhaps the math parser could > become a standard part of it? This makes sense as long as we can continue to use WX_UNIT_BINDER for normal coordinate entry without math expression support. > > Cheers, > Tom > > > ___ > Mailing list: https://launchpad.net/~kicad-developers > Post to : kicad-developers@lists.launchpad.net > Unsubscribe : https://launchpad.net/~kicad-developers > More help : https://help.launchpad.net/ListHelp > ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
On 27.08.2017 22:28, Marco Ciampa wrote: > +1 muparser is already present in many distros: > > apt-cache search muparser > libmuparser-dev - fast mathematical expressions parse library (development) > libmuparser-doc - fast mathematical expressions parser library (documentation) > libmuparser2v5 - fast mathematical expressions parser library (runtime) ...And exprtk is a single header file, which compiles on any OS. There is life outside Linux, too. - my 5 cents, Tom ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
On 27.08.2017 17:03, Russell Oliver wrote: > Hi all, > > Attached is a patch that allows for the use of a mathematical expression > when editing the value field of components in Eeschema. > > If editing the value field and the entered string begins with an equals > sign "=" as you would when entering a formula into an Excel spreadsheet > cell, it is compiled and parsed when the Enter button is pressed while > the text entry is in focus. > > A valid expression is returned as a double value which is then printed > with a format to remove trailing zeroes. An invalid expression will not > change the text value. > > The expression parser is simple wrap of the C++ Mathematical Expression > Toolkit Library (ExprTk) written Arash Partow and is under the MIT > licence [1]. > Hi Russell, Looks great, I wanted to have such a feature for parametric mechanical design. Have a look at the WX_UNIT_BINDER class - it's used in more recent dialogs for inputting coordinates/sizes. Perhaps the math parser could become a standard part of it? Cheers, Tom ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
On Sun, Aug 27, 2017 at 04:06:50PM -0400, David Novak wrote: > On 8/27/2017 11:03 AM, Russell Oliver wrote: > >Hi all, > > > >Attached is a patch that allows for the use of a mathematical expression > >when editing the value field of components in Eeschema. > > > >If editing the value field and the entered string begins with an equals > >sign "=" as you would when entering a formula into an Excel spreadsheet > >cell, it is compiled and parsed when the Enter button is pressed while the > >text entry is in focus. > > > >A valid expression is returned as a double value which is then printed > >with a format to remove trailing zeroes. An invalid expression will not > >change the text value. > > > >The expression parser is simple wrap of the C++ Mathematical Expression > >Toolkit Library (ExprTk) written Arash Partow and is under the MIT > >licence [1]. > > > >I think this provides a template for other numerical input fields within > >Kicad. > > > >[1] http://www.partow.net/programming/exprtk/index.html > > > >Kind Regards > >Russell > > > You might consider muparser. > > David > +1 muparser is already present in many distros: apt-cache search muparser libmuparser-dev - fast mathematical expressions parse library (development) libmuparser-doc - fast mathematical expressions parser library (documentation) libmuparser2v5 - fast mathematical expressions parser library (runtime) -- Marco Ciampa I know a joke about UDP, but you might not get it. GNU/Linux User #78271 FSFE fellow #364 ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
You might consider muparser. David On 8/27/2017 11:03 AM, Russell Oliver wrote: Hi all, Attached is a patch that allows for the use of a mathematical expression when editing the value field of components in Eeschema. If editing the value field and the entered string begins with an equals sign "=" as you would when entering a formula into an Excel spreadsheet cell, it is compiled and parsed when the Enter button is pressed while the text entry is in focus. A valid expression is returned as a double value which is then printed with a format to remove trailing zeroes. An invalid expression will not change the text value. The expression parser is simple wrap of the C++ Mathematical Expression Toolkit Library (ExprTk) written Arash Partow and is under the MIT licence [1]. I think this provides a template for other numerical input fields within Kicad. [1] http://www.partow.net/programming/exprtk/index.html Kind Regards Russell ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
Anyone know how to expose this to python? Maybe incorporate https://pypi.python.org/pypi/cexprtk/0.2.0 ? Greg S. > On Aug 27, 2017, at 10:03 AM, Russell Oliverwrote: > > ExprTk ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [RFC] Proof of concept of mathematical expression input for text fields.
I don't see myself using it in eeschema, but having this in the footprint editor or pcbnew would be awesome. Calculating the (x,y) of a pad often requires some simple math. Freecad has this kind of math parser, very useful. Marcos On Sun, Aug 27, 2017 at 12:03 PM, Russell Oliverwrote: > Hi all, > > Attached is a patch that allows for the use of a mathematical expression > when editing the value field of components in Eeschema. > > If editing the value field and the entered string begins with an equals > sign "=" as you would when entering a formula into an Excel spreadsheet > cell, it is compiled and parsed when the Enter button is pressed while the > text entry is in focus. > > A valid expression is returned as a double value which is then printed > with a format to remove trailing zeroes. An invalid expression will not > change the text value. > > The expression parser is simple wrap of the C++ Mathematical Expression > Toolkit Library (ExprTk) written Arash Partow and is under the MIT licence > [1]. > > I think this provides a template for other numerical input fields within > Kicad. > > [1] http://www.partow.net/programming/exprtk/index.html > > Kind Regards > Russell > > ___ > Mailing list: https://launchpad.net/~kicad-developers > Post to : kicad-developers@lists.launchpad.net > Unsubscribe : https://launchpad.net/~kicad-developers > More help : https://help.launchpad.net/ListHelp > > ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp