General > General Technical Chat
What I'd love to see - number entry text boxes with minor math
(1/3) > >>
daqq:
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.

David


edit: And yeah, I know there are other ways of achieving stuff like this, graphical and intuitive, still, would be nice in many cases.
ajb:
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 way  :scared:

At 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?
T3sl4co1l:
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
Nominal Animal:
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.  (You can make Python eval() safe, and it isn't hard.)

For C, there is for example the zlib-licensed TinyExpr, 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.)
Lukas:

--- Quote ---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...
--- End quote ---

I'm glad you asked, that's exactly what numerical entries in Horizon EDA are capable of: https://horizon-eda.readthedocs.io/en/latest/entries.html Especially 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.
Navigation
Message Index
Next page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod