ROrthoGrid returns minSpacing or minSpacing squared times 10^n (Not auto)

If you are having problems with QCAD, post here. Please report bugs through our Bug Tracker instead.

Always attach your original DXF or DWG file and mentions your QCAD version and the platform you are on.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
CVH
Premier Member
Posts: 4957
Joined: Wed Sep 27, 2017 4:17 pm

ROrthoGrid returns minSpacing or minSpacing squared times 10^n (Not auto)

Post by CVH » Sun Jul 02, 2023 11:53 am

The issue is addressed here:
https://www.qcad.org/rsforum/viewtopic.php?f=95&t=10149
https://www.qcad.org/rsforum/viewtopic.php?f=8&t=8761
And a bug report exists here:
https://www.qcad.org/bugtracker/index.p ... sk_id=2284

I mainly refer to code for an orthogonal metric grid here: https://github.com/qcad/qcad/blob/maste ... hoGrid.cpp

Line 395 retrieves an ideal minimum grid spacing based on the minPixelSpacing (minDevicePixelSpacing) value and the view factor.
On lines 394 is mentioned that the result may be some odd number.
The idea is now to format the grid spacing automatically depending the zoom state in nice 10 based steps.

The grid spacing is then calculated in 5 distinct code sections:
- Line 398 divides this (odd) value by minSpacing for an idealFactor in X and Y.
- This idealFactor is again divided by minSpacing and of that the 10 based log is stored as exponent n in X and Y.
- A factor in X and Y is created equal to minSpacing times 10^n where n is rounded up to an integer after subtracting a tiny amount.
- Lines 409 - 415 will restrict these factors to not less than 1.
- In 417 - 421 the grid spacing is calculated as minSpacing times the factors.

Meaning that:
  • For factors less than 1 we get a grid spacing of minSpacing * 1
  • With n rounded to integers and equal to zero we get a grid spacing of minSpacing * minSpacing * 10^0(=1)
  • With larger integers for n we get a grid spacing of minSpacing * minSpacing * 10^n(=10, 100, 1000 ...)

And that is conform my findings in the provided lists:
Grid Spacing = 1.5 >>> Auto grid steps : 1.5 - 2.25 - 22.5 - 225 - 2250 - ...
Grid Spacing = 0.0625 >>> Auto grid steps : 0.0625 - 0.390625 - 3.90625 - 39.0625 - ...
Other example lists can be found here: https://qcad.org/rsforum/viewtopic.php?t=8761#p34738

It only works seemingly correct when the Grid Spacing preference is unit based like 10, 1, 0.1 or 0.01 ... (As listed in the combo box)
Andrew's advice to freeze the grid is not a proper solution as it doesn't automatically scale the grid anymore when zooming out.

It is of no use to re-enter a bug report as there is an open one by Stan Tibbs - 27.09.2021.
It doesn't serve anything to add this explanation to the mentioned user posts.
Maybe it is picked up this way, I'll add a link in the bug report and PM it to Andrew ...

The division by minSpacing under a log() is not counteracted by multiplying it an extra second time. e_geek
IMHO one needs to retrieve the ideal minimum grid spacing, divide that by the minSpacing.
Then define the rounded exponent n and return minSpacing times 10^n where n is restricted to zero or larger.

Regards,
CVH

User avatar
andrew
Site Admin
Posts: 8789
Joined: Fri Mar 30, 2007 6:07 am

Re: ROrthoGrid returns minSpacing or minSpacing squared times 10^n (Not auto)

Post by andrew » Mon Jul 03, 2023 9:39 am

Thanks for your analysis. This will more likely be completely refactored at one point to allow the user to enter a list of all acceptable grid spacings in the application preferences (per unit).

For metric, this would by default be something like:

0.01;0.1
0.1;1
1;10
10;100
100;1000

Or for imperial for example:
1/8;1
1/4;1
1/2;1
1;12
2;12
3;12
4;12
6;12
12;36

etc.

CVH
Premier Member
Posts: 4957
Joined: Wed Sep 27, 2017 4:17 pm

Re: ROrthoGrid returns minSpacing or minSpacing squared times 10^n (Not auto)

Post by CVH » Tue Jul 04, 2023 6:35 am

andrew wrote:
Mon Jul 03, 2023 9:39 am
acceptable grid spacings
For metric, this would by default be something like:
0.01;0.1
0.1;1
1;10
...
This is not what I intended, unit based metric grids works fine.
What if I want a grid based on 5mm ; 10mm
As example referring to sublayer import test.dxf in this topic:
Husky wrote:
Tue Jul 04, 2023 1:55 am
Use my test drawing to import such sub layers.
When zooming out I expect zoom states 5 - 50 - 500 - 5000 - ...
While the meta grid is 10 - 100 - 1000 - 10000 - ...

And not:
  • 5 < 10
    25 < 10 :!: :?:
    25 < 0 (=none)
    250 < 0 (=none)
    2500 < 0 (=none)
Regards,
CVH

Post Reply

Return to “QCAD Troubleshooting and Problems”