Zoom Actual PR (poll)

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!

Did you try the macro and did it work as expected?

Poll ended at Sat Oct 30, 2021 7:24 pm

Yes, works as expected here.
3
50%
Yes, but it doesn't work here.
1
17%
No, don't want / not interested in this feature.
1
17%
What's a macro?
1
17%
 
Total votes: 6
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Zoom Actual PR (poll)

Post by TheMarkster »

There is a PR pending to add a Zoom Actual (1:1) zooming to the view menu.

https://github.com/FreeCAD/FreeCAD/pull/5125

It is based on this macro from kisolre:

Code: Select all

from pivy import coin
cam = Gui.ActiveDocument.ActiveView.getCameraNode()
vpSize = Gui.activeView().getSize()
invHeight = min(vpSize[0], vpSize[1])
vpDpi = Gui.getMainWindow().physicalDpiX()
cam.height.setValue(invHeight*25.4/vpDpi)
screenshot:
Image

What it does, when it works, is zooms the camera to a height such that, for example, a 10mm cube will measure (using a ruler held up to your screen) to be 10mm across (obviously when viewed orthogonally directly from front, side, top, etc.). This could be very handy when trying to model something to mate with another object, at least to get a rough approximation by holding the other part up to the screen for a comparison, and also just to get a better feel for the actual size of the object you are modeling.

One little problem: doesn't always work. We need folks to run the macro and report whether it worked or not for them and if not what their hardware specs are so we can get a better idea of what the failure rates are and decide from there whether this is worth merging into master. The only failure I know of is when running inside a virtual machine: (ubuntu guest running in a Virtual Box vm with a Windows 10 host). The cube measures 15mm instead of the expected 10 inside the VM, depending on the scaling being used in the Virtual Box settings.

There is a tweak parameter to solve this issue in these cases. It will be in the View folder in Edit Parameters: BaseApp/Preferences/View/ZoomActualTweak (float property). The way the tweak works is you measure the cube (or whatever) and if your measurement is 15mm when the expected size was 10mm then you would enter 1.5 as the tweak parameter. With the tweak it should work flawlessly after that (unless the VM scaling is changed). Is the tweak needed only for people running FreeCAD inside a Virtual Machine or can it also be required with some particular hardware, such as notebooks, tablets, or some graphics cards?

I'm adding a 3-day poll to make it easier to gauge responses.
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Zoom Actual PR (poll)

Post by adrianinsaval »

tried on a windows PC with a monitor and in a linux laptop, both worked. This weekend I might get a chance to test with the laptop connected to a TV.
The VM failing is acceptable IMO since it's not running real hardware.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Zoom Actual PR (poll)

Post by TheMarkster »

I have found a 2nd example of a failure. I dragged FreeCAD to my 2nd display (a TV actually, that is pulling double duty as a 2nd display when I'm not watching TV on it). There I measured a 100mm cube as 185 mm with the macro. Adding a tweak to the macro and setting to 1.85 resolved the issue.

Here is a revised version of the macro with a tweak you can edit:

Code: Select all

tweak = 1.00
Gui.ActiveDocument.ActiveView.getCameraNode().height.setValue(min(Gui.activeView().getSize()[0],Gui.activeView().getSize()[1])* tweak * 25.4/Gui.getMainWindow().physicalDpiX())
(It's all in one line so when run from c++ we don't need to create variables that might potentially pollute the namespace or interfere with existing variables.)

I'll save my thoughts until after the poll closes on which way I'm personally leaning on this.
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Zoom Actual PR (poll)

Post by adrianinsaval »

what's the purpose of using min there? Seems to be a dirty way of determining which one is the height? If that's the case, that's a bad assumption to make. Now I tested on the same laptop as before but on windows. If I make the 3d view have a width smaller than the height the macro fails but if it has more width than height it succeeds.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Zoom Actual PR (poll)

Post by TheMarkster »

adrianinsaval wrote: Wed Oct 27, 2021 11:35 pm what's the purpose of using min there? Seems to be a dirty way of determining which one is the height? If that's the case, that's a bad assumption to make. Now I tested on the same laptop as before but on windows. If I make the 3d view have a width smaller than the height the macro fails but if it has more width than height it succeeds.
I'm not sure why he wrote it that way. My guess is there was a good reason. I thought it was working, so I didn't want to change anything except to condense to a one-liner if possible, and later add the tweak parameter. If you can modify to be more reliable that would be great.
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Zoom Actual PR (poll)

Post by adrianinsaval »

Ok, I tested some more and it seems the last time I messed things up by running it first in the python console and not just as macro or something like that because now it's working :?
Apparently min is there precisely to ensure it works regardless of the form factor
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Zoom Actual PR (poll)

Post by wmayer »

TheMarkster wrote: Thu Oct 28, 2021 1:09 am
adrianinsaval wrote: Wed Oct 27, 2021 11:35 pm what's the purpose of using min there? Seems to be a dirty way of determining which one is the height? If that's the case, that's a bad assumption to make. Now I tested on the same laptop as before but on windows. If I make the 3d view have a width smaller than the height the macro fails but if it has more width than height it succeeds.
I'm not sure why he wrote it that way. My guess is there was a good reason. I thought it was working, so I didn't want to change anything except to condense to a one-liner if possible, and later add the tweak parameter. If you can modify to be more reliable that would be great.
Using min looks OK to me because it compensates the shrinking of the objects when height is higher than width. As a quick test do this:
  • Create a document and a standard cube
  • Click view all
  • Now move the vertical splitter (that separates the task view from the 3d view) from left to right
  • As long as the 3d view is wider than high you won't notice a difference. But as soon as the view's width becomes smaller then its height the cube will start to shrink.
drmacro
Veteran
Posts: 8864
Joined: Sun Mar 02, 2014 4:35 pm

Re: Zoom Actual PR (poll)

Post by drmacro »

Hmm...just built this a bit ago and no Zoom actual in the menu...
NoZoomAct.png
NoZoomAct.png (208.87 KiB) Viewed 1943 times
OS: Debian GNU/Linux 10 (buster) (XFCE/lightdm-xsession)
Word size of FreeCAD: 64-bit
Version: 0.20.26234 (Git)
Build type: Release
Branch: master
Hash: cd9055c396b4a563a660c1fefbc36912dfc7e7e9
Python version: 3.7.3
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Zoom Actual PR (poll)

Post by Syres »

drmacro wrote: Thu Oct 28, 2021 1:38 pm Hmm...just built this a bit ago and no Zoom actual in the menu...

Build type: Release
Branch: master
Hash: cd9055c396b4a563a660c1fefbc36912dfc7e7e9
Surely the commit hash should be 0571623a79d37654939543b09600b1ba68bfbc7b and the Branch wouldn't be master if you've built the PR???
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Zoom Actual PR (poll)

Post by TheMarkster »

My version, in building the PR, is 26203, hash: 0571623.
Post Reply