What I'd love to see - number entry text boxes with minor math - Page 1
Forum section: electronics / general

author: daqq
author_rank: Super Contributor
timestamp: May 27, 2021, 08:02:33 pm
content: Hi,Just a thought - I'd love to see text boxes where you enter a number OR enter a simple mathematical expression and it accepts it become the norm - at least in CAE software. I often need to enter some stuff that is a fraction or a multiple of some constant by another constant. Say, I need to manually enter the XY coordinates, I know the reference point is at 1.44, 7.87 and I need the thing 0.48 and 8.2 away from it, so instead of running my calculator and entering 1.92, 16.07 I would enter 1.44+0.48 , 7.87+8.2. Or something needs to be a third of the way from something else, so I enter 0.48+22.8/3 . Or setting up grids and so on...Wouldn't need to be anything extensive or complicated, no need to bother with sines, tans and so on, just +, -, / and * between numeric constants. Maybe mixed units would be nice, the ability to enter 1mm + 30 mil would be nice...What are your thoughts? I think that some CAD software had something like that, but I've never seen it since.Davidedit: And yeah, I know there are other ways of achieving stuff like this, graphical and intuitive, still, would be nice in many cases.

author: ajb
author_rank: Super Contributor
timestamp: May 27, 2021, 08:24:50 pm
content: This is very common, albeit in a more powerful form, in parametric CAD systems (like SolidWorks and Fusion 360), which can use referential values, like a parameter at the file/project level or the value of a driven dimension, and can retain the expression and recompute its value dynamically. This is difficult to do well because you can develop extremely complex dependency graphs and reconstructing a model if a parameter at the beginning of the dependency chain is modified can be intensive. Also anyone who has done anything of any complexity in these software systems knows that its easy to end up blowing the whole design up by changing a parameter in the wrong wayAt a more basic level, AutoCAD has a little calculator button in the numeric boxes in the properties window. It's a little annoying because it locks out the rest of the UI, but can be pretty useful.[ Specified attachment is not available ]EDIT: so is attachment inlining broken, or what?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 27, 2021, 08:37:06 pm
content: What, just as a wish? Yeah, agreed.Altium has that, at least with some parameters (others, there's a "..." dialog you can enter a different kind of expression, and yes of course, the syntax is different just about everywhere, you have to remember which namespace goes with each..). Or, had; there's at least one instance I noticed got removed in AD20 or 21!I suppose it might be possible to add on, in general, using some heavy-weight methods? First, you'd have to detect that a field is numerical in nature; then intercept the content, and reinterpret it when the user finishes entering it. (Which might be ENTER, a button, or clicking away, who knows?) There are APIs for this -- language tools in text boxes for example. Not sure if the small input boxes have the same features available though. And as for context, good luck figuring that out, you'd have to snoop into what the program is using it for somehow, I guess? Else you'd have a database of windows and textbox IDs (assuming there is something identifiable about them; this isn't HTML parsing here!), a huge and fragile PITA to do in general.Oh and that's not really first, zeroth is identifying the window in the first place, and getting these hooks to its text entry if applicable.I'm slightly aware of this series of events being possible on Windows; I don't know how other OSs do it, beyond guessing they might use a broadly similar architecture around this problem.For sure, getting anything contextual, and pulled from active namespace, is a pipe dream; that's a function Altium and others provide, but you'd have to simply RE the whole damn thing to figure out how to access that in any random program, and that, in turn, is likely prohibited in the EULA.As for doing it yourself, in a program from scratch, you could parse the string and see if it's entirely numeric, test for operators/symbols, etc.; in JS you could risk an eval() but it's probably better to just write out the damn parser whole (and by "write out" I mean, find a package that already does it..). And you can opt for whatever operators or functions you like, or reference other objects in context, etc. Not terrrrribly difficult to do, just a lot of stuff that needs to be brought together. So... pretty clear why you don't see it all that often.Tim

author: Nominal Animal
author_rank: Super Contributor
timestamp: May 27, 2021, 08:41:04 pm
content: There are lots of (math) expression evaluators out there.Unit support is a bit of a discussion item, because the rules are so vague; you really need to define a good set of fixed rules for units, and a custom lexer that consumes numbers with an optional trailing unit specification. Not difficult technically at all, but people preferring different conventions tend to disagree what the rules are.Function-format unit support, on the other hand, would be trivial. Instead of writing "90 degrees" or "30 mil", you'd write "degrees(90)" or "mil(30)"; your example would be e.g. "mm(1) + mil(30)". This is trivially supportable in e.g. Python eval() with custom dictionaries (so disallowing arbitrary I/O and module imports), because the "units" are just conversion functions to the default units being used. (Youcanmake Pythoneval()safe, and it isn't hard.)For C, there is for example the zlib-licensedTinyExpr, but AFAIK it does not support units.The difficult bit is getting application writers to allow their users to do this. If you think cats are difficult to herd, just try to get application devs to agree on something, and in the best case they just come up with a new standard that nobody follows that really only gets used by the marketing wanks. In the worst case, their illogical and insane arguments (just don't get me started with "UTF-8 is the only non-legacy character set") makes you lose your mind. (If you ever find mine, let me know.)

author: Lukas
author_rank: Frequent Contributor
timestamp: May 27, 2021, 09:36:31 pm
content: QuoteI'm glad you asked, that's exactly what numerical entries in Horizon EDA are capable of:https://horizon-eda.readthedocs.io/en/latest/entries.htmlEspecially the pipe operator for computing the average comes in handy when datasheets specficy pads by their start and end position rather than center and size.

author: NiHaoMike
author_rank: Super Contributor
timestamp: May 29, 2021, 06:03:33 pm
content: Perhaps what we need is a calculator that can enter calculated values into the PC, acting as a "smart keyboard" of sorts? Could probably be done with an Arduino, or a Pi Zero if you want the calculator to have its own GUI. Or if you're OK with no hardware buttons, a smartphone app.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: May 29, 2021, 10:23:50 pm
content: Quote from: NiHaoMike on May 29, 2021, 06:03:33 pmI'm sure I've seen something like that somewhere. It was a numeric keypad peripheral that was aimed primarily at laptop users, I think. Standalone it functioned like a typical calculator with an LCD screen, but when connected via USB it acted as a numeric keypad. When in 'PC' mode, you could press a button and then input a calculation, then pressing the same button again (or maybe it was another one), it would 'type' the result in to the PC. Can't remember what it was called or where I saw it, though.

author: tooki
author_rank: Super Contributor
timestamp: May 30, 2021, 09:02:56 am
content: Quote from: daqq on May 27, 2021, 08:02:33 pmLots of professional graphics software supports this. It’s sad that more products don’t.

author: daqq
author_rank: Super Contributor
timestamp: May 30, 2021, 12:33:31 pm
content: Thanks for the comments!I only saw it once in the wild, it's good to know that it's elsewhere as well.Nominal Animal: Good points, but I having a full scripting language would be overkill in my opinion.QuoteReally? Can you point me to one?

author: Nominal Animal
author_rank: Super Contributor
timestamp: May 30, 2021, 02:35:07 pm
content: Quote from: daqq on May 30, 2021, 12:33:31 pmWell, I meant it more like"this is not difficult to implement; the problem is getting the application developers to agree on its behaviour, and actually USE these".I could easily write a GTK+3GtkEntryderivative in C or a Qt5QLabelderivative in C++ or Python 3, that provide this functionality in a seamless drop-in fashion, under say CC0-1.0 (i.e., Do Whatever You Wish But Don't Blame Me license) or preferably the toolkit's own (least restrictive) license.The hard work would be the human stuff, getting the application developers to use it, and not mangle it all to hell because they have odd notions on how their users should do this.(As an example, the reason you cannot select UTF-8 as the default character set in your browser, is that someone decided that "UTF-8 is the only non-legacy character set". No, seriously, that's the rule, and all current browser developers go by that rule. What the hell does "legacy" even mean in this context? UTF-8 was first used in Plan-9 in 1992, ISO-8859-15 (which is not a "legacy character set") was first proposed in 1996, and adopted into the standard even later, so "legacy" definitely has no relation to time. It's just a word used to say "fuck you, we don't care, this is how we decided stuff so shut up already".)Please note that I am describing this as a person who has provided patches to a LOT of different projects over the years, and know how the cycle goes. I have done something like this before, and am wary of trying to do it again, because it is so much social-interaction-work to convince people it is useful/necessary; at least an order of magnitude more than the programming work.The one working approach I can see is getting the functionality integrated into the various GUI widget toolkits, GTK+ and Qt in particular. You do need to have personal contacts with people who have deciding power, however. I do not, any more. (Being a burnt out husk of a man, and so on.)As to the technical details, I would implement these backed with three "dictionaries" or callback functions: one for variables, one for units, and one for functions. Variables would default to empty/not supported; functions would default to a basic set of trigonometric functions, square root, exponent, logarithm, and absolute value; and for units, there would be a few different default sets: one for lengths, one for angles, one for surface area, and one for volumes, at least. These would be easily extended or replaced by application programmers, but the default ones should cover most reasonable use cases, so they wouldn't, and this would Just Work in most applications.If there is somebody willing to do the social work – convincing others to integrate this, pushing it upstream, etc. – I would be happy to do the development work. What I do not want to get involved in, is in the endless bike-shedding discussions into minute details on how this should be done before anyone has even tested it in real life.Having thought about this some more, I think a version without unit support would be much more likely to be accepted by the developers. That would also remove one of the difficult questions – how to control the units used by the widget internally. (Unit conversions could be provided via functions, as described in my first post, though.)

author: ajb
author_rank: Super Contributor
timestamp: June 01, 2021, 02:02:16 am
content: Oh, another application that already does this is CorelDraw, I don't know how extensive its calculation entry support is, but at least some places like the X/Y location and size boxes will take at least basic arithmetic entry. Like if you want to move an object a specific distance you can append "+50mm" or whatever to the end of the current value. It will also do unit translation, so you can enter values in pixels, points, millimeters, inches, etc, and it does the necessary conversions as well as the arithmetic.

author: emece67
author_rank: Frequent Contributor
timestamp: June 01, 2021, 03:56:02 am
content: .

author: Alex Eisenhut
author_rank: Super Contributor
timestamp: June 01, 2021, 04:39:27 am
content: Allegro does it.

author: Deni
author_rank: Regular Contributor
timestamp: June 01, 2021, 05:05:59 am
content: Believe it or not, our pick&place machines (GSM's) running on OS/2 (yes, really!) have that feature - since 90's...And it's a great help.