Lines pattern scaling

Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Lines pattern scaling

johnfound
Hi. I am a new user. After several days of exploring LibreCad I have noticed, that the different line patterns actually have sizes in pixels, not in physical units (mm for example). This way, when you zoom the drawing, the pattern of the line actually changes (in mm):

You can see, that on both screenshots, the size of the dash is always 48px, while the elements in mm change in size.

Is it intentional, because of some reason, or this is known problem, that can't be fixed for some reason?





Here is the text from "About":

Version: 2.2.0-undef
Compiler: GNU GCC 13.2.1
Compiled on: Nov  7 2023
Qt Version: 5.15.16
Boost Version: 1.83.0
System: Manjaro Linux
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

dxli
We reworked line patterns in. 2.2.1( to be released soon, pending Linux snap support).

Please try 2.2.1 or even 2.2.2 available at our GitHub page.

Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

johnfound
Thanks. I am compiling right now. BTW, according to the documentation, it needs qmake, but with the recent versions, you need (at least in Arch) to use qmake6, or else "make" breaks with error.
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

johnfound
This post was updated on .
In reply to this post by dxli
Well, I have tried:

Version: 2.2.2_alpha1-207-g7838da61f
Compiler: GNU GCC 14.2.1
Compiled on: Dec  2 2024
Qt Version: 6.8.0
Boost Version: 1.86.0
System: Arch Linux

But the line patters seems to be still in pixels, as shown in the my first post.

Or maybe I am doing something wrong? Should I activate some option or something?

I am attaching a file with a test project that illustrates the difference. The left dash-dot line is as it should be (IMHO) and the right dash-dot line is as it is now. Try to zoom in-out and export to pdf in order to see the difference.

good-lines-bad-lines.gz
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

johnfound
Well, today I have fixed the line pattern scaling (well, or changed it as I like, if not broken):

The source code diff here

And also, changed this annoying dash line selection to something better:

Better selection tool here
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

sand1024
Oh, that's great - I'll take a look on this in details, especially for the pattern scaling.  I'm slightly concerned there regarding different drawing units, so I think we have to check this deeper.

As for using alpha approach - well... I suspect that some quite interesting side effects may occur there - especially with combination with antialiasing, and so far I'm not sure about rendering performance if lot's of entities are selected. Probably it will look better in some environments, yet it's necessary to check how portable is such approach.

I think I'll pick your changes, test them and probably add an options that will define how to select entities.
Just changing default selection mode may be confusing for existing users.
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

johnfound
sand1024 wrote
Oh, that's great - I'll take a look on this in details, especially for the pattern scaling.  I'm slightly concerned there regarding different drawing units, so I think we have to check this deeper.
Oh, wait a minute. This is not the correct solution. Now I know what is the problem and think I have the correct solution. It is simple and will commit it tomorrow. The trick is that Qt does not measure the line patterns in pixels, but in line widths. So we need to convert from mm to line widths, not to pixels.
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

johnfound
In reply to this post by sand1024
Well, it seems I have a working solution of the problem with the line scaling.

Here is the commit:

https://asm32.info/fossil/librecad/info/679836fcf52e840c

But some bugs and glitches are possible.

I have tested it on the display, print preview and pdf export and everything seems to be OK. But still there are too many combinations between the different line widths and line screen widths and this makes the code too complex.

Here is a dxf file, I used for the tests:

dashed-lines.dxf

The left "center line" and the right "fake center line" should always look equal if everything is OK.
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

dxli
Hi johnfound,

Just want to be confirm with you on a few items:

1. in rs_linetypepattern.cpp, it is stated the patterns are defined in pixels. I few we may have to redefine this one. Better to make LibreCAD patterns defined in physical distances, like mm/inches. By defining line patterns in display/rendering space allows zooming in/out, with roughly the same line pattern appearance;
2. Qt line patterns are defined in line widths, and line width is taken as 1 pixels, if defined to be 0;
3. If we define LibreCAD line patterns in mm,
    p_Qt = p_LC * dpmm/(lineWidth)

with p_Qt and p_LC as the pattern values for QPen and LibreCAD (rs_linetypepattern), dpmm as the standard dots per mm, and lineWidth the line width in pixels.

A few things need improvement:

1. the cap style effects on line patterns;
2. DPMM may not be reliable;
3. connected entities, like polylines and splines.

johnfound wrote
Well, it seems I have a working solution of the problem with the line scaling.

Here is the commit:

https://asm32.info/fossil/librecad/info/679836fcf52e840c

But some bugs and glitches are possible.

I have tested it on the display, print preview and pdf export and everything seems to be OK. But still there are too many combinations between the different line widths and line screen widths and this makes the code too complex.

Here is a dxf file, I used for the tests:

dashed-lines.dxf

The left "center line" and the right "fake center line" should always look equal if everything is OK.
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

johnfound
dxli wrote
1. in rs_linetypepattern.cpp, it is stated the patterns are defined in pixels. I few we may have to redefine this one. Better to make LibreCAD patterns defined in physical distances, like mm/inches. By defining line patterns in display/rendering space allows zooming in/out, with roughly the same line pattern appearance;
Actually, the patterns are not defined in pixels and I think they never was. In the official versions, they are converted to pixels by multiplying with some constant and displayed this way.

In my version, they are interpreted as a millimeters and displayed this way.

dxli wrote
2. Qt line patterns are defined in line widths, and line width is taken as 1 pixels, if defined to be 0;
3. If we define LibreCAD line patterns in mm,
    p_Qt = p_LC * dpmm/(lineWidth)

with p_Qt and p_LC as the pattern values for QPen and LibreCAD (rs_linetypepattern), dpmm as the standard dots per mm, and lineWidth the line width in pixels.
This formula is not working in the current implementation, because there dpmm is simply a constant, somehow related to the screen/paper size. For correct work, we need dpmm = (pixes_size_on_the_screen/object_mm_size). But if so, then for some line dpmm = lineWidth_px/lineWidth_mm and then the formula becomes:

p_Qt = p_LC_mm/lineWidth_mm

My changes, provide exactly this - correct conversion from mm (in rs_linetypepattern.cpp) to relative units, needed by Qt.
Here is a link to rs_painter.cpp/ RS_Painter::SetPen() in my version:  

The conversion

How the k constant is computed

And you can check it simply by pulling the recent commit from my working repo: jf_fixes branch and test it.

If you don't want to mess with fossil, here is a download link for the source: LibreCad_jf_fixes.tar.gz
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

dxli
just checked the latest master.

I can see patterns are actually scaling with the entities.

This is wrong, so your fix is needed to make the pattern size defined in the viewing space, so the sizes stay roughly the same when zoomming in/out.

johnfound wrote
dxli wrote
1. in rs_linetypepattern.cpp, it is stated the patterns are defined in pixels. I few we may have to redefine this one. Better to make LibreCAD patterns defined in physical distances, like mm/inches. By defining line patterns in display/rendering space allows zooming in/out, with roughly the same line pattern appearance;
Actually, the patterns are not defined in pixels and I think they never was. In the official versions, they are converted to pixels by multiplying with some constant and displayed this way.

In my version, they are interpreted as a millimeters and displayed this way.

dxli wrote
2. Qt line patterns are defined in line widths, and line width is taken as 1 pixels, if defined to be 0;
3. If we define LibreCAD line patterns in mm,
    p_Qt = p_LC * dpmm/(lineWidth)

with p_Qt and p_LC as the pattern values for QPen and LibreCAD (rs_linetypepattern), dpmm as the standard dots per mm, and lineWidth the line width in pixels.
This formula is not working in the current implementation, because there dpmm is simply a constant, somehow related to the screen/paper size. For correct work, we need dpmm = (pixes_size_on_the_screen/object_mm_size). But if so, then for some line dpmm = lineWidth_px/lineWidth_mm and then the formula becomes:

p_Qt = p_LC_mm/lineWidth_mm

My changes, provide exactly this - correct conversion from mm (in rs_linetypepattern.cpp) to relative units, needed by Qt.
Here is a link to rs_painter.cpp/ RS_Painter::SetPen() in my version:  

The conversion

How the k constant is computed

And you can check it simply by pulling the recent commit from my working repo: jf_fixes branch and test it.

If you don't want to mess with fossil, here is a download link for the source: LibreCad_jf_fixes.tar.gz
Reply | Threaded
Open this post in threaded view
|

Re: Lines pattern scaling

johnfound
dxli wrote
just checked the latest master.
Hm, what you actually checked? What master?