Per-project metrics

A forum for research and development of the user interface of FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
mtsinc
Posts: 25
Joined: Tue Apr 24, 2018 12:40 pm

Per-project metrics

Post by mtsinc »

Has any thought been put into assigning a measurement units property at the document level?

The USA, as is well known is backwards, so I have at least 3 measurement systems to deal with.

1. CNC and 3D print projects I usually do in metric.
2. Woodworking plans I do in inches
3. Architectural plans I do in feet/inches

It's a real nuisance when I have multiple documents open to have to keep switching back and forth globally on their metrics. Actually, it's a real nuisance to have to stop and determine which metric option to switch to when opening a project at all.

Inkscape was a one-size-fits-all metric system as well, but they finally gave up and moved the metric basis from the application to the document. It was painful for them, but much appreciated by their user community. I don't know about anyone else, but I'd definitely be glad to see that in FreeCAD as well.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Per-project metrics

Post by yorik »

It is true that I also switch a lot depending on when I work on a project in the US or not...
However, I'm not sure a per-project setting is the best path, because some people will want to adopt the file unit when opening the file, some not.

I'd be more in favor of adding an easy units switch to the UI, like I did with the BIM workbench. For me that solved it all, one mouse click to change the unit.

If there is enough interest, that control could be implemented FreeCAD-wide (in the tux module for ex)
mtsinc
Posts: 25
Joined: Tue Apr 24, 2018 12:40 pm

Re: Per-project metrics

Post by mtsinc »

I thought about that myself.

However, it's really not being faithful to the intent of the document creator to go arbitrarily switching units. Especially on dimensioned drawings.

I'm aware that the real units internally are always the same and all we really do is adjust the conversions done on display, but when a user designs something and they start laying things out in whole meters or tenths of an inch or whatever, it makes more sense to make the designed units be the normal display for that document (as a document property) and any alternative unit system would be something done as a local override. Via a macro, perhaps or a user preferences setting.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Per-project metrics

Post by yorik »

You have a point there. There is not much sense in enforcing a unit to the user, however indeed it would be a good thing to be informed of the unit the model is intended to be used with. It could also have impact on precision, etc.

It seems to me the best path for that would be to add a field in File -> Project information
mtsinc
Posts: 25
Joined: Tue Apr 24, 2018 12:40 pm

Re: Per-project metrics

Post by mtsinc »

I'd say that there's a lot of sense in enforcing the unit system in a project. I seem to recall that a rather valuable space probe was allegedly lost because people weren't paying proper attention to the unit system being used. And, contrariwise, I don't know of any real-world cases where multiple participants in a project each got to choose their own system of measurement.

Now we do have wonderous chimeras like USA automobile engines where my 2.3L engine was secured with 7/8-inch bolts, but that's something I'd expect within a project not between users of it and it's not a topic I'd care to add to this discussion. Sufficient unto the day is the evil thereof.

As far as where to put this property, while I haven't yet managed to find time to thoroughly dissect FreeCAD project structure, it appears to be the fairly common approach where document/file/project are more or less the same thing and thus the natural place for most projects to define the measuring system would be in the "document properties header".

I briefly toyed with the idea of putting in a plea to make the project header also remember the last workbench used before saving, but recollected that things of that nature probably better go in the user's local metadata not the project - based on how I've seen that work in IDE's, where sharing projects is rampant.

Keeping track of what system of measurement is currently in use is actually the easiest part, I think, since the displays in property editors and (IIRC) dimension lines typically include that information on a per-item basis. The only truly hard part would be shifting systems when you switched from something like a view of a cm-based CAD project to an in/ft architectural project's page within an instance of FreeCAD.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Per-project metrics

Post by Joel_graff »

yorik wrote: Tue Mar 12, 2019 2:08 pm You have a point there. There is not much sense in enforcing a unit to the user, however indeed it would be a good thing to be informed of the unit the model is intended to be used with. It could also have impact on precision, etc.

It seems to me the best path for that would be to add a field in File -> Project information
Internally, I convert units on-the-fly. It's just a matter of proliferating a scaling factor throughout the code that checks the current document units before building an object, so that it always converts properly to mm. At the same time, I still assume that units are fixed to the document / project and don't change. Which means my unit-handling code is likely very broken. :)

Still, I've wondered how best to handle this from time to time. I think most users will consider units as being an intrinsic characteristic of the document / project and will not want them to change, so enforcing that idea as the default expectation makes the most sense to me.

I think. :roll:
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
mtsinc
Posts: 25
Joined: Tue Apr 24, 2018 12:40 pm

Re: Per-project metrics

Post by mtsinc »

Joel, does that mean that you're the resident expert on measurement here?

I've identified 3 aspects of project metrics, and they kind of overlap, but alas currently are kind of distributed in FreeCAD's innards:

1. System of measurement. Basically Metric System versus Freedom Units.
2. Scale of project. Millimeter, centimeter, meter, and of course US architectural, for starters.
3. Display mode: This can be seen most clearly in the additional Fractional Inches Units option for US measurement, but also in how you divide up formatting if you're displaying feet/inches measures. And, of course, number of displayed decimal places.

Obviously life would be a lot easier if the whole world went metric, but at the moment a 2x4 lumber isn't even 2 inches by 4 inches, alas.

I've been playing with the source code and getting per-project metrics injected into each project is easy enough, but the other half of the task is re-rendering the MainWindow when you switch to reflect the new settings. When you change global metrics, this event fires automatically, but I can't tell what sets it off - it's "magic". If anyone could steer me in the right direction, it would be very helpful!
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Per-project metrics

Post by Joel_graff »

mtsinc wrote: Tue Apr 16, 2019 9:19 pm Joel, does that mean that you're the resident expert on measurement here?
Expertise is entirely relative. I would use the term sparingly. :lol:

So are you proposing a 'project' is a document? A collection of related documents?

As for your code issues, I've really no idea. You'll have to start posting code and getting specific, I'm afraid. Also, if you're working in C++, I know I won't be much help. I'm pretty familiar with C++ but, to this point, have entirely ignored it with FreeCAD.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Per-project metrics

Post by Jee-Bee »

i would say a project is a file.

otherwise it becomes more difficult.
mtsinc
Posts: 25
Joined: Tue Apr 24, 2018 12:40 pm

Re: Per-project metrics

Post by mtsinc »

The terms are admittedly somewhat fluid, but I think FreeCAD "Projects", "Documents" and project files are pretty much aspects of the same thing.

FreeCAD internally refers to a "Project" as a 'Document" and further distinguishes the App::Document (which is the persistable part) with the Gui::Document, which controls interaction with the GUI subsystem - probably wise since FreeCAD can be run so much by scripting that I'm not even sure it has to open a GUI in the first place.

The Gui::Project in turn exists in a many-to-many relationship with MDIWindow views of the various sheets being displayed. So when you select a new sheet tab, you can potentially change between Projects and when you do, then if what I'm plotting plays out, the units displays for both the displayed (active) sheet and any selected object in that sheet (ComboView) should adopt the units preferences for that project.

Whoops, I had a momentary heart attack, thinking of having one project document active, but an object from another document in the ComboView, potentially having a clash in display metrics. Fortunately, as of FreeCAD 18 at least, that's not possible. I think it may have been in FreeCAD 17, though. Dodged a bullet there.

My primary confusion about getting the units to switch for the project when you change preferences turned out to be in forgetting that I was hijacking the application-level units objects and the application-level unit preferences was saving over the top of things. So I'm now looking at some of the finer details. Still would like to know what triggers the MainWindow refresh, though. It might be useful to know someday.
Post Reply