1

(8 replies, posted in Import DXF)

NolanCarthy wrote:

Try checking DXF version compatibility or exporting with different settings.

The problem was that dxf2elmt didn't yet support nested blocks. I have a separate branch where I'm working on this. I actually had it working for this specific drawing, but I have another drawing with more deeply nested blocks and different scaling as they are nested. So far my attempts to get this working either correctly import one drawing or the other. I need to spend a bit more time to get it all working more consistently.

2

(193 replies, posted in Import DXF)

Wow...2.8MB that's a big dxf, Looks like it has a whole lot of blocks. Should be a good test drawing to find some deficiencies in dxf2elmt hopefully.

3

(193 replies, posted in Import DXF)

plc-user wrote:

Hello vadoola,

the file pxc_2700975_11_00_ILC-171-ETH-2TX_2D.dxf from Phoenix Contact seems to be a real challenge!
When converting exploded drawing from LibreCAD, the controller is found outside the drawing-area of the A3-sheet.
It is (of course) copyrighted, so no re-distribution here: --> Downloads --> Technische Zeichnung

Thanks I'll take a look at it.

4

(193 replies, posted in Import DXF)

Salut Laurent, Hallo plc-user,

And to anyone else willing to help out.

I created a branch to try and finish up on the issues with nested blocks: https://github.com/Vadoola/dxf2elmt/tree/nested_blocks, as originally brought up at https://qelectrotech.org/forum/viewtopic.php?id=2890

While there are still some minor issues (like text positioning but that's not exclusive to blocks), so far in my testing with a few files it seems to be pretty good.

If anyone has some good dxf files with nested blocks they want to test against let me know. I'll try and wrap up some of those minor issues, and merge it back into the main branch soon.

5

(193 replies, posted in Import DXF)

plc-user wrote:

@vadoola:

As also discussed in the other thread:
We are about to ship a few free fonts with QET. Among them is “osifont” which is often used as a font for CAD applications.
What do you think about specifying “osifont” as a font in converted elements for which no font is specified in the DXF?

When I look at the title block of the well-known “Wet Location Grip” file in LibreCAD and compare the font with “osifont” in QET, the font fits much better than a sans serif font.


Would like to have attached a screenshot, but something's still wrong with forum-settings: I cannot attach a file!

I've never heard of IS0 3O98, it looks like it's mostly a European thing, but it looks similar to other fonts I've seen used by AutoCad even outside of the Europe. I agree based on that screenshot you sent it does look a lot closer to what is being used by CAD that the Sans Serif font. Setting the default to "osifont" should be pretty straight forward. I'll see if I can do it tonight.

6

(8 replies, posted in Import DXF)

Salut Laurent, Hallo plc-user

Since it's unlikely that Antonioaja will be working on dxf2elmt going forward and and my fork has diverged quite a bit at this point, I was considering on disconnecting my fork from his. I still plan on giving him full credit for the work he did, and will update the Readme to link back to his repo, I just wanted to separate the fork.

There are some things I need to consider, I thought I saw somewhere that it might ruin any issues you have, but I'm not sure. Either way in order to separate it from Antonio's fork my repo can't have any fork's itself. Would you two be willing to delete the forks you have made from my repo so I can separate it from Antonio's? Then you can refork it if you need to.

7

(117 replies, posted in Code)

plc-user wrote:

The font-info-string is documented in Qt-docs: https://doc.qt.io/qt-5/qfont.html#toString (same for Qt6)
There it says, that it's a string of 16 entries.
But as we see in our element-files, the font-info-string is build with only 10 comma-separated entries.

Maybe that's what I was remembering that it was documented but wasn't quite right because the number of comma-seperated entries didn't match.

I looked into the Qt5 code to make sure the font string in dxf2elmt was being generated the same. I never looked at the Qt6 code since it wasn't relevant at the time. Looking at the doc for QFont::toString() in Qt5 and Qt6, it's identical, so I'm not really sure what the difference is or why it would have changed in the code. I'm just assuming the Wireshark issue is correct and there was a change however, and it might effect a future Qt6 version of QET, so it's good to be aware of it.

8

(117 replies, posted in Code)

Hello everyone,

A few months ago when I was looking to improve the font handling in dxf2elmt, I was trying to figure out what the font info string in the XML file is. I noticed it was using a built in method on QFontInfo that writes it out to a string, and I had to go dig into the Qt Source code to figure it out, as it appears to be undocumented.

I bring this up because back when I was researching this I came across this bug in Wireshark, that says the FontInfo string is not backwards compatible between Qt5 and Qt6: https://gitlab.com/wireshark/wireshark/-/issues/18553.

I forgot about it until just now when discussing a pull request plc-user made for dxf2elmt about text positioning. I just wanted to bring this to your attention since you guys are working on compiling it with Qt6, it's possible something will need to be done to make sure the font info from elemt files created with a Qt5 version works correctly with a version compiled with Qt6.

9

(7 replies, posted in Elements)

plc-user wrote:

Another reason to try to sort arrtibutes in element-file.
That's why valoola and I should use the same order for attributes in output of dxf2elmt and QET_ElementScaler. Seems that we do...


Good to know that we do, it was completely accidental, I mostly just stuck with the same general ordering of attributes Antonio was using in the original version. I'll try to make sure it stay's in sync with what QET_ElementScaler does.

10

(8 replies, posted in Import DXF)

So I did a quick look, I never quite finished the logic for nested blocks, so that is the problem here. I'll add it to the to do list. Thank you.

11

(8 replies, posted in Import DXF)

plc-user wrote:

The dxf contains Blocks in Blocks in Blocks in.....
That's currently not supported by dxf2elmt, but developer is working on it!

Blocks are currently supported. The way I wrote it I would have thought nested blocks would be supported, but I have not actually tested that yet.

I'll have to do some testing with your file and see why it's not working.

If it is due to nested blocks, what plc-user suggested: opening it in some CAD software and doing an explode on the blocks should work as a temporary solution until I can update the software.

I would agree with limiting it to 2 decimal places. I don't see any real benefit to that level of resolution in the element placement, and it bloats the XML file. Since you can't edit any more than 2 digits inside the element editor anyway, what need is there to store it in the XML.

13

(193 replies, posted in Import DXF)

I'm taking a closer look now that I'm on my lunch break, and it looks like I'm completely wrong about QET saying the font is in pt's. Nowhere does it say that, it simply refers to it as size. It's just so common for font to be stored as pt's instead of pixels I must have just assumed size meant font points instead of pixels. I clearly made a mistake here, downside of squeezing in time when I can even if that means I'm a bit distracted or tired. I'll try and find some time to get the code updated to scale the text correctly.

14

(193 replies, posted in Import DXF)

I think I see the confusion.

QET says it's measuring the font size in pts...but pts and pixels are not the same. Based on the file you just provided  (textsizes_in_QET.elmt) QET is actually storing the text size in pixels not points, despite it being labeled as in points. (I don't know if this is the case in all languages, or perhaps a mistranslation in the English text for QET). If that is the case, then you are correct that using the exact same scaling factor as the rest of the drawing should be accurate, since the text sizing is not stored how I though it was based on how QET labels it.

15

(193 replies, posted in Import DXF)

Hallo plc-user

I think I worded things in a way that did not translate properly for someone who is not a native English speaker. Sorry about that, I will try and word things better to make it more clear.

The current code is my first attempt and properly handling the text sizing, and text scaling over what Antonio had with just a fixed 12pt font. I based the conversion of the text size from real world units (which the text height is stored as in dxf) to font points using the defined definition of 1pt = 1/72 inch. In the couple of drawings I tested this scaling looked OK, but I knew it needed more testing and verification. I checked it in because it was already better than what was there. Perhaps I need to do a better job and work at some of these features in branches instead of on master so people don't think the checked in code is fully functional, however you testing against it and provided these files is very useful feedback for me to fix problems.

When you brought this up and provided the Schriftgroessen file I checked against some online calculators converting mm to pt to verify that I had done the math correctly in my code. Based on the conversion of 1pt = 1/72 inch, I did do the match correctly in my code, but this conversion factor clearly does not provide good results, after testing against some more files.

So the question is what conversion factor do I need to use? In the Schriftgoessen file you provided, if I had assumed that 1mm  = 1pt and then scaled it with the mm->px conversion of 2x, that actually would have been more accurate. It looks like it actually should be converted by a factor of 2.1, but 2 would have been closer than 2.8 used based on the mm->pt conversion I used. What I need to figure out is that roughly 2x height to pt conversion in the Schriftgroessen file something that could be valid or just coincidence in the factors similar?

Perhaps a better method here is assume that 1 unit (based on the file, mm, inches etc) is equal to 1pt and then scale based on the 1mm = 2px, perhaps I should always assume 1mm = 1pt, and then scale. I'm not really sure, I'll need to do more testing to try and narrow down what the right scaling factor might be, and need to make sure I'm testing against multiple units.

I think the next step for me to do is create a handful of files along the lines of Schriftgroessen but in several units like inches, ft, cm, etc and do some testing to try and narrow down a more accurate scaling factor.

Hopefully that makes things a bit more clear.

16

(193 replies, posted in Import DXF)

scorpio810 wrote:

My health is deteriorating and I find it hard to think and organise myself.


Laurent,

I'm sorry to hear about your health, and I hope you get better.

I wish I had more time to contribute and help out with QET, but I have young children which for the moment take a lot of time and energy.

17

(193 replies, posted in Import DXF)

Hallo plc-user,

plc-user wrote:

I noticed something similar with the imperial DXF from your American compatriot.!

I can double check, but I believe this extra scaling factor for the imperial unit drawing was fixed in the last commit.

plc-user wrote:

If we focus on the 20 mm font:
In LibreCAD (black background) it is good to see that both texts are the same size - I expect the same for the element.
In the element (white background), the polygon 20 mm are 40px high, but the 20 mm text has a font size of 57.
So there is still a factor of about 1.4 somewhere in there that doesn't belong.

The scaling for the font is handled separately from the rest of the drawing. This is because dxf stores text height in whatever unit the drawing is in (ie mm, inches, etc) and QET uses your stand font points. A font point is defined as 1pt = 1/72 inches, which comes out to 1pt = 0.3528mm.

Based on this conversion the values that are being generated are "correct", because text height in mm would be multiplied by a factor of roughly 2.83. instead of the 2 used to convert mm to pixels.

I checked a couple of online unit conversion calculators to verify my math and 20mm comes out to 56.692913386pt font, rounded to 57 in the element.

You are right though that this clearly isn't correct in the element file. Doing a quick hacky test of modifying the text element font size to try and match the polygon size, it looks like the factor in your sample file should be 2.1. (for the 20mm text, a font size of 42pts).  It's not clear to me where this 2.1 comes from...but it is close to the 2px per mm we use in the conversion of this drawing. Perhaps multiplying the text height in real world units by the same as the rest of the drawing instead of "properly" converting between font points and real world units would be better? I'll need to try and do more testing and see what I can come up with, and test it against some other drawings.

18

(193 replies, posted in Import DXF)

The font sizes should be correct in the latest commit (c3a5b2a). Before I had the real world units to Pt logic, I just scaled the text by the same scaling factor as the rest of the drawing as a temporary measure. I forgot to remove that code, so it was scaling it twice, once when converting between real world units and font points, and then again by the same factor the rest of the drawing was.

The handful of drawings I was using were in mm, so the extra scaling was 2x, but the drawing you were using was in inches, so the extra scaling was 50.8x.

There are still some other issues, with the text in that drawing for example in dxf the X and Y coordinates are based off alignment, in QET, they are always left and top regardless of alignment. So I need to add logic to do font measurements and that sort of thing. for this reason some of the text in the dxf is slightly off where it should be. Fixing is one of he things I was already starting to work on, but is more complicated, and will take a bit longer.

19

(193 replies, posted in Import DXF)

Lots to respond to...

andrew wrote:

Howdy all, hope this is the correct place for bugs on DXF conversion

The QET Forums, either this thread or creating a new one, are probably the best place for this. I do use Github Issues (https://github.com/Vadoola/dxf2elmt/issues) for tracking problems or enhancements etc., but if you make a post here, there can be a bit more discussion about it and I can make an Issue on Github, you are more then welcome to make a Github Issue as well though.


Thanks for the spreadsheet, I can take a look at it. The scaling should be in there already, but only recently and includes all the units supported by DXF. The code can be seen here: https://github.com/Vadoola/dxf2elmt/blo … od.rs#L213. Perhaps you grabbed a slightly older version of the conversion utility, because I only checked in that code a few days ago.

andrew wrote:

its set in inches 'cause I'm 'Murican

Now worries, I to am 'Murican, but have been living in New Zealand (where my wife is from) for a while now, that's why I'm late to the party here, I was asleep for most of this conversation.

andrew wrote:

and the text is garbled to heck

Yeah there is still quite a bit of work to do on the text but I'm slowly chipping away at it.
There are multiple text types in DXF
    * ArcAlignedText
    * MText
    * RText
    * Text
Right now Text should be somewhat well supported, but there are issues. MText has some very early and crude support, and the other two have no support. Just looking at the screenshot you shared (without having looked at the DXF yet) I'm guessing these are regular "Text" objects.

scorpio810 wrote:

I saw these fonts size was so biggest, like size= 1298 px ....

andrew wrote:

@Scorpio810, I may have to look into file format, but I assume the DXF has font size and QET has font size, so can't we get a porportion based on doc size and then just hit the font sizes with that (rounded as needed)

A font size of 1298 certainly seems wrong, I'll have to do some testing on that file to see what's going on. The DXF actually stores font height in drawing units, so if the drawing defaults to inches, the text height will be stored in inches not font points. I convert between real world units and font points at the code Laurent linked above and round it to a whole number. The conversion is based on the definition of a PostScript font point where 1pt is defined as 1/72 of an inch, and in my testing so far this seems to work well.

andrew wrote:

Also if it's prescaled, I wonder if prev document I converted from DWG->DXF->Element was messed up or if I did some dragging around 1st by mistake

It's certainly possible and hard to know. I'll take a closer look at the dxf and see what I can find, it might be a couple of days before I can get to it though.

20

(193 replies, posted in Import DXF)

plc-user wrote:

The primary aim is to obtain a “respectable” QET element that we can scale in a second step if necessary. The prerequisite for an element that requires little reworking is, of course, that circles from the dxf also look like circles in the element. To achieve this, the element size must be appropriate.

With the logic I added to check for circle shaped polygons and converting them to QET ellipses hopefully this will be less of an issue, but I know there is more work to be done here.

plc-user wrote:

Do we have the chance to determine during import whether the numerical values in the unitless dxf are so small that scaling would be necessary? Something similar to: “Values are all smaller than xx, so will be enlarged by a factor of 10 or 100!

Good question, and I'm not sure what a good default value would be. I didn't parse through all the QET Elements, but I looked at the Ladder Diagram elements, and they are 20px high (if I recall this was a couple of days ago).  So that's probably a good absolute minimum size for an element. However I doubt people will be importing dxf's of tiny simple drawings like a ladder diagram coil or contact. This would probably be mostly used for importing drawings of real life objects. I'm wondering if something like if it's under 20px high, we multiply it by 10? I feel like we might need to find some more sample files to test against. There may be enough differences here that it's not easy to come up with a good default.

I also just pushed another commit tonight that has some early stage work for properly scaling the fonts based on the size in the dxf file. From my testing so far there are some issues with the placement of the text due to a bigger boundary box in QET than what I believe the dxf is expecting, but it's an improvement over what was there before.

21

(193 replies, posted in Import DXF)

plc-user wrote:

Maybe it is necessary also to take the tag $MEASUREMENT into account?
In the file “05DI-AD16DIX-10.dxf” one can find this:

$MEASUREMENT
 70
     0
  0

When imported in current FreeCAD dev-version you can measure the terminal-width: 18,19 mm (see screenshot)

Yeah I will probably need to use both to try and figure it out. That DXF file seems to be a bit all over the place. I opened it up in QCad, and in the details is the said the drawing was Unitless, the Paper was in millimeters, and the hatching was in imperial units....

That same section of Terminal Block according to QCad was 1.09, I'm not sure where that number is coming from, and don't see any obvious way to make it line up with the 18.19mm you got from FreeCad

plc-user wrote:

@scorpio810:
Do you know the manufacturer and name of that part to get the real dimensions, Laurent?

To me it looks like it might be a Distech ECY-DI16. I found this PDF (https://docs-be.distech-controls.com/bu … les_SP.pdf) with some dimensions from various parts in that series, but none of the drawings show the terminal blocks like in the dxf. Going off the width of the main module and not the terminal blocks, that PDF gives 2.95 inches / 74.99mm. QCad is giving me "1.51983129"...I really have no clue where that is coming from.

So I went ahead and installed FreeCad, and measuring that same base part of the dxf file I got 39.03mm....which once again no obvious way that lines up to 74.99mm. It seems if no units are defined perhaps the CAD program just make a best guess, and each one does that differently?

22

(193 replies, posted in Import DXF)

plc-user wrote:

I have noticed that there are differences in the unitless dxf files.
The test file for 1-point polygons does not contain “INSUNITS” and the file “05DI-AD16DIX-10.dxf” (see here https://qelectrotech.org/forum/viewtopi … 379#p20379) contains the tag “INSUNITS”, but no entry “70” for the unit, but this:

INSUNITS
350
99E
  3

Thanks for looking into this. It looks like INSUNIT (https://help.autodesk.com/view/ACD/2025 … F55A2B4FD8) is for trying to match the scaling between a block and the drawing its inserted into. Gives me a good place to start looking further.

23

(193 replies, posted in Import DXF)

Salut Laurent,
Hallo plc-user,

scorpio810 wrote:

I'll have to find plc-user's messages about the dimensions of the thumbnails, like this.
https://qelectrotech.org/forum/viewtopi … 393#p17393

plc-user wrote:

As I suggested several times we should use a front-view-scaling where the user can see the real size at first sight or where he/she can calculate the real size by using a simple integer factor:
1 mm <-> 2 px

1 px is also the smallest step size, a QET-Element can be moved in diagram-editor. So then we could "move" the elements by 1 px = 1/2 millimeter in real-life.

Thanks going through these discussions was a good read. Either I hadn't seen these or just forgot about them, when I got back and started working on this. I agree the 1 mm <-> 2 px ratio seems like it would work well, I'll make this change and do some testing on it.

Another question is if I have a dxf that is "unit less" should I do any scaling at all or just assume it's in pixels. I don't recall which drawing it was at the moment, I'll have to try and go back to find it, but I had one drawing which was unit less and with no scaling it was quite small, but with no dimensions at all it's hard to make any assumptions and give a reasonable output that would work across all drawings. So perhaps it's better to just leave them as is, and if the user needs to scale using QET_ElementScaler they do.


plc-user wrote:

Hello vadoola!
About the texts / fonts

That wasn't meant as a negative criticism: just a remark that this is the case.
It is clear to me in particular that there is still a lot of work to be done to integrate the texts correctly into the element. You will have "a lot of fun” with the text position, because it is not directly on the baseline of the first letter, but on a bounding box that is specified by qt, but not well described...

A difference to many other software: QET can only handle font-sizes which are integer numbers!

No worries I didn't interpret it as negative criticism. I was just trying to point out myself that right now nothing is really handled at all for fonts and there is a lot of work there.

In another forum post there was a bug report about the text ending up in the wrong location. I looked into it and found out why, but fixing it wasn't so straight forward. Essentially per the DXF spec, if text isn't using the default alignment of Top and Left, you need to use the "Second alignment points" and then calculate the size of the text in the appropriate font, to get the x and y coordinates. Reading in these second alignment points from the DXF is easy, but calculating the text dimensions in the appropriate font not so much.

I already started doing a bit of work on the font handling stuff last night. There is a lot of work to do there, but hopefully I can start getting some small improvements going.

24

(193 replies, posted in Import DXF)

Hallo plc-user

plc-user wrote:

Hello Vadoola!
It looks very good, but unfortunately I have to say that the dimensions are not yet right. There's a factor of 10/3 in there somewhere with the part I used. The attached part has the dimensions 60 x 210 mm, but the resulting element is 200 x 700 px.

That calculation is based on trying to map the real world dimensions to pixels based on an A4 Sheet of paper using the standard QET Template. The standard QET Template I believe is 700px high (including the title block) and landscape, so that would come out to 700/210mm = 3⅓px per mm, which comes out to 200x700px, and printed on an A4 sheet of paper should be roughly the real world dimensions of 60x210mm. That is obviously a very large item on an A4 sheet of paper, real world dimensions in landscape it's about 30% of the height, and 70% of the width, so perhaps this isn't the best way to do it. I am open to suggestions or thoughts on how better to map the real world dimensions to useful pixels for the elements.


plc-user wrote:

And when I look at the texts that come out of a previously used example (05DI-AD16DIX-10.dxf): There the font is not correct yet and the font height is not set either, so QET uses the default size 9 when opened.

In the original code from Antonio there were a handful of things that were hard coded, whether the polygon was open or closed for example was just hard coded initially to false, then true, instead of reading it from the dxf. I'm slowly going through and trying to clean these up and grab the information from the dxf where it exists and use it appropriately. The Fonts for the text is one of these, he just had a hard coded "Arial Normal" in there with no font sizing regardless of what was in the DXF. This is the next thing I plan on tackling is reading in this information correctly and using it.

25

(193 replies, posted in Import DXF)

Hello Laurent,

Strange, that looks like debugging info I had in there while I was testing, but I just checked the last commit (fb09197) and I had removed it before committing.

Are you sure you grabbed the latest commit?

The other possibility is I screwed something up, the last time I worked on a (non-plc) project as a team was in C++ but probably 12+ years ago now and we were using SVN. All my experience with Git is as a solo developer, and I have a tendency to just work off the main branch. I know it's not best habits and have been trying to learn better git technique, so I was working on these features in a different branch and then merged them. Perhaps I didn't merge them correctly, and you aren't seeing the latest code?