Topic: QET-Element to SVG

Salut Laurent et Joshua,
hello everyone,

based on the Idea of QET_ElementScaler I created a first version of a converting-tool in C++.

Some graphical elements already work very well, like RECT, ELLIPSE. POLYGON, ARC.
Not working: Line-Endings like Bullets or Arrows – they are not defined in SVG and have to be drawn separately.

What is a problem since I've been using Computers and Operating-Systems: Fonts!
So for now only static Texts are basically implemented with limitations: no rotation and the font is saved as "Sans Serif".

Another topic we should discuss are colors. Of course it is very useful for the user to have Names of colors in the GUI. But when I use the given names of the colors in SVG most of them aren't defined and some look different: "green" in QET is much lighter than "green" in SVG. So I had to implement a translation-table from the color-names to RGB-values which work very well in SVG.

Maybe we should use RGB-values instead of color-names in QET-Elements, too? Then the colors would be defined exactly.
And: Do we really need more than 150 named colors in QET where many of them are duplicates like "red"/"HTMLRedRed" or "cyan"/HTMLCyanAqua"/"HTMLCyanCyan" which represent the same RGB-values when I look at the color-table here: https://doc.qt.io/qt-6/qml-color.html?

In the attachments you find a sample-element and the resulting SVG.

I would like to use this thread to discuss the further details of the software with the developers of QET.

Best regards,
  plc-user

Post's attachments

Attachment icon wago_0750-0669-0000-0003.elmt 20.04 kb, 58 downloads since 2023-11-20 

Attachment icon wago_0750-0669-0000-0003.svg 12.79 kb, 70 downloads since 2023-11-20 

Re: QET-Element to SVG

Hallo Plc-user,

wow it's very great news, thank you so much again Plc-user for your works. \o/

See history of HTM color in this topic:
https://qelectrotech.org/forum/viewtopic.php?id=1245
And the first patch
https://qelectrotech.org/forum/viewtopi … 61&p=3

Maybe a possible changes in this PR ..?
https://github.com/qelectrotech/qelectr … 88a0721f86

Best regards,
Laurent

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."

Re: QET-Element to SVG

Old Tuxfamily git commit URL can be easy found on github by sha commit:
example:
https://git.tuxfamily.org/qet/qet.git/c … 21a1fd40a6
https://github.com/qelectrotech/qelectr … 21a1fd40a6

https://github.com/qelectrotech/qelectr … y.cpp#L603

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."

Re: QET-Element to SVG

Salut Laurent!

With your explanations and hints from the older posts: I think we can drop the topic "color" for now. Especially because the translation-table now exists for me and seems to work properly. nomicons/smile

As you already mentioned in the other thread, the texts are the particular challenge when converting to SVG!

Not only are the zero points for horizontal text different for "text elements" and "dynamic text", but this has a particular effect when the text is rotated. The font size and rotation-angle must then also be taken into account for the new position. In the attached screenshot you can see at the top the SVG with text and blue rect with the same values for x and y. In the lower part you see Element-Editor with a dynamic text, it's bounding box in dotted line and a rect with the same x- and y-values. In both cases x- and y-values for ELMT and SVG are the same (can be seen with rects)!

The "puzzle" continues if the dynamic texts are aligned differently horizontally and vertically...

Perhaps you have a hint for me where I can read, for example, how the border boxes of the various text elements behave depending on the font size? They are also different in size for text and dynamic text.


The font is a completely different topic: Is it perhaps possible to limit ourselves to a few generic font families instead of trying to support all the fonts that the various systems have to offer? As has already been criticized in many posts here in the forum, the texts behave differently depending on which operating system the file is opened on.

I would therefore suggest that we limit ourselves to generic font families (e.g. SansSerif, Serif, Monospace). Since we can process Unicode, I don't think we need a super-special font that is only available on system xyz. I will at least try to limit myself here for now.


But the most important thing for now would be the positioning of the different texts. Maybe you know where I can read in QET-Sourcecode or QT-Documentation where I can find hints about that?

Best regards
  plc-user

Post's attachments

Bildschirmfoto_Text-Nullpunkte.png, 30.77 kb, 949 x 526
Bildschirmfoto_Text-Nullpunkte.png 30.77 kb, 28 downloads since 2023-11-20 

Re: QET-Element to SVG

Hallo Plc-user,


Re edit
https://github.com/qelectrotech/qelectr … d.cpp#L250

//the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size
//The origin transformation point of PartTextField is the middle of left edge, and so by definition, change with the size of the font
//We need to use a QTransform to find the pos of this text from the saved pos of text item


maybe see:
https://github.com/qelectrotech/qelectr … icpart.cpp
https://github.com/qelectrotech/qelectr … tfield.cpp
https://github.com/qelectrotech/qelectr … rttext.cpp
Doxygen:
https://download.qelectrotech.org/qet/doxygen/html/

Edit:
https://github.com/qelectrotech/qelectr … ements_XML
https://qelectrotech.org/wiki_new/en/do … ements_0.3
https://qelectrotech.org/wiki_new/es/do … ents_0.2?s[]=text

Best regards,
Laurent

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."

Re: QET-Element to SVG

Hello Plc-user,
I'm happy to read you are currently working on an elmt to svg converter, and wow very very good job.

About the color : like you say, you can drop it for now.

About text : For historical reason (and bad choices I made), how the texts are managed in the elmt file is a mess.
With the links Laurent give, you can see there is several way how the position of the text are saved, and no one are good in sense of svg.

If you read PartText.cpp, the function toXml, you can see the position x and y is the position of graphicsItem of the text but not the text itself (in the same class read the function void PartText::adjustItemPosition(int new_block_count)).

And in the class PartDynamicTextField it's approximately the same thing.

In svg, the position of the text is the base line https://developer.mozilla.org/en-US/doc … ement/text and the base line is bottom left of the text (like you say in previous post)
So to resume the situation, it will be very difficult for you to convert the "qet" position to "svg" position, withouse the baseline of the current used font. From my point of view try to approximate the position in first time.

One other thing, the text size with Qt (see QFont class info) can be pixel size of point size. Until some year we used default value (point size) and have no problem because QElectroTech was used in with screen with same dpi. But now there is a lot of screens with different dpi and the text are not displayed in same size from screen to another. This is why now (and if we had known that before, we would done it from the start) we use pixel size.
Point size => Same physical size one screen no matter the dpi.
Pixel size => Same pixel size on screen no matter the dpi.
Consider the font size are in pixel size even if it's was not true when the element was saved.

I probably forget some information don't hesitate to ask us.

I don't know if you are aware or not but in future (long ?) I plan to rewrite a large part of QElectroTech (To solve lot of problem, bad choice, base design, etc...) one point of this rewrite is to use true svg for the graphical aspect of element and not an ersatz of it.
May be when this time will come I will used your code for that (if you are ok).


some link about text in Qt

https://doc.qt.io/qt-5/qfont.html
https://doc.qt.io/qt-5/qfontinfo.html
https://doc.qt.io/qt-5/qfontmetricsf.html

Don't forget, we don't draw directly text in the folio, but draw text inside a QGraphicsItem and the position is the position of this item, not the baseline of the text.
https://doc.qt.io/qt-6/qgraphicsitem.html

Joshua

Développeur QElectroTech

Re: QET-Element to SVG

Salut Joshua!

Thank you for your hints, links and explanations!

I love the sentence: "For historical reasons..."  nomicons/cwy
It always explains, why there are so many ugly workarounds.

But be sure: Most of the software I wrote in the past would NOT look the same if I wrote it now again! nomicons/wink

In the moment I think I could make a great step ahead, if I knew how to calculate the bottom-left-corner of the dynamic_text in it's boundingRect.
As you can see in the attached elmt-file I put a dynamic_text at Position x=0, y=5. The boundingRect is positioned exactly there (blue rect). But the text is placed in another position the green rect.

Maybe I find an explanation in QT-documentation from the link how to calculate the "missing values". I have to read.
After that it should be possible to move and rotate the text in SVG to the right position using trigonometry... nomicons/cheerful

Of course you can re-use my code for QET in further versions: That's why we support OpenSourceSoftware!
For now the sources are in a state I would like not to publish. I'll do it later on my GitHub-Account ... promised!

Best regards
  plc-user

Post's attachments

Attachment icon Element_Dynamic_Text.elmt 3.11 kb, 34 downloads since 2023-11-22 

Attachment icon Element_Dynamic_Text.svg 1.69 kb, 51 downloads since 2023-11-22 

8 (edited by Joshua 2023-11-22 22:56:59)

Re: QET-Element to SVG

I don't know what lib you use to write your converter,
but if you use Qt, you probably can find the bottom left corner by create an instance of QFont and QFontMetric with the specified font read in the xml.
If not (Qt) I think you can easily find lib to achieve this job.

About the rotation of the text in svg, there is the attribute rotate but apply the rotation for each character of the text.
https://developer.mozilla.org/en-US/doc … ement/text
For rotate text in svg you need to use a transformation https://developer.mozilla.org/en-US/doc … /transform
With Qt you can see https://doc.qt.io/qt-6/qtransform.html

Développeur QElectroTech

9 (edited by plc-user 2023-11-23 21:42:17)

Re: QET-Element to SVG

Salut Joshua,

I prefer to use plain C++ without special libs that may not be available on other systems, so also here: No QT or so.
It seems that I'm on a good way even with rotated texts!  nomicons/smile

EDIT:
It seems that the standard-value is true for closed in polygons?

Changed that in my code, because the SVGs looked kind of strange and I could not find any ELMT with "closed=true" in Collection!

Attached you find some screenshots to compare SVG.(top or left) and ELMT (right or bottom)

Post's attachments

Bildschirmfoto_2023-11-23_20-27-14.png, 60.95 kb, 681 x 807
Bildschirmfoto_2023-11-23_20-27-14.png 60.95 kb, 27 downloads since 2023-11-23 

Attachment icon Bildschirmfoto_2023-11-23_20-30-23.png 83.18 kb, 15 downloads since 2023-11-23 

Bildschirmfoto_2023-11-23_20-31-52.png, 30.35 kb, 404 x 582
Bildschirmfoto_2023-11-23_20-31-52.png 30.35 kb, 28 downloads since 2023-11-23 

Bildschirmfoto_2023-11-23_20-33-09.png, 110.95 kb, 1238 x 880
Bildschirmfoto_2023-11-23_20-33-09.png 110.95 kb, 31 downloads since 2023-11-23 

Bildschirmfoto_2023-11-23_20-34-25.png, 36.78 kb, 433 x 515
Bildschirmfoto_2023-11-23_20-34-25.png 36.78 kb, 27 downloads since 2023-11-23 

Re: QET-Element to SVG

Hallo plc-user,
Wow that's very good, thank you for the great support.


Best regards
Laurent

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."

Re: QET-Element to SVG

Hello plc-user,

I found other lessons about SVG

https://riptutorial.com/svg
SVG => rotate => text : https://riptutorial.com/svg/example/10312/rotate-text

SVG Tutorial
https://www.w3schools.com/graphics/svg_intro.asp
https://www.w3schools.com/graphics/svg_text.asp


with kind regards,
Erik

I am an industrial developer technician and born in 1960

12 (edited by Joshua 2023-11-24 20:01:24)

Re: QET-Element to SVG

About closed polygon, see const QDomElement PartPolygon::toXml(QDomDocument &xml_document) const

if (!m_closed) xml_element.setAttribute("closed", "false");

So if the the polygon is not close, the attribute is not present.

In svg there is not close or open polygon.
There is polygon (close) and polyline (open)

Développeur QElectroTech

13 (edited by plc-user 2023-11-24 20:23:38)

Re: QET-Element to SVG

Hello everyone!

For open or closed polygon / polyline I found a solution!

Let's get back to "dynamic_text": Can someone please confirm or explain this:

I have created a test element with three "dynamic_text" and set the horizontal alignment to left, centre or right. I notice that the texts still remain in almost the same X position.

When I apply the attribute left, centre or right to SVG-text, exactly what I expect to happen happens: the reference point of the text is at the specified X position.

That is what I would expect in QET, too...

EDIT:
There is no change in Text-Positions, even when I change Vertical Alignment to Center or Bottom.

Post's attachments

Bildschirmfoto_Text-Alignment-Horizontal.png, 51.24 kb, 872 x 756
Bildschirmfoto_Text-Alignment-Horizontal.png 51.24 kb, 29 downloads since 2023-11-24 

Attachment icon Element_Dynamic_Text_Alignment.elmt 2.73 kb, 38 downloads since 2023-11-24 

Attachment icon Element_Dynamic_Text_Alignment.svg 1.14 kb, 32 downloads since 2023-11-24 

Re: QET-Element to SVG

Hallo plc-user,
ich bin auch schon einige male auf  dieses Verhalten bei dynamischen Text gestoßen.
Ich nehme an Du hast den Text  in den Editor gezogen, beschriftet und dann die Ausrichtung angepasst. Wenn Du den Text in den Editor ziehst (Unterstrich löschen), Textausrichtung anpasst und dann den Text schreibst, dann erhältst du das erwartetete Ergebnis wie auch bei der SVG.
Trotzdem ist Textausrichtung in QET nicht ganz optimal. Hauptgrund ist sicher das QGraphicsTextItem, die Basisklasse für den dynamischen Text, nur die Textausrichtung "oben Links" kennt. Ich denke in QET wird die Textlänge berechnet und damit dann der Einfügepunkt des Textes entsprechend verschoben. Das verschieben des Einfügepunktes kann man auch gut an den x/y Koordinaten nachvollziehen.
Besser wäre sicherlich wenn der Punkt der Ausrichtung auch der Einfügepunkt ist, wie bei anderen CAD-Systemen auch.
Ich hoffe es hilft.
Gruß
Achim


With translator:
Hello plc-user,
I have also encountered this behaviour with dynamic text several times.
I assume you have dragged the text into the editor, labelled it and then adjusted the alignment. If you drag the text into the editor (delete the underline), adjust the text alignment and then write the text, you will get the expected result as with SVG.
Nevertheless, text alignment in QET is not quite optimal. The main reason is certainly that QGraphicsTextItem, the base class for dynamic text, only recognises the text alignment "top left". I think the text length is calculated in QET and the insertion point of the text is then moved accordingly. The shifting of the insertion point can also be easily understood by the x/y coordinates.
It would certainly be better if the point of alignment was also the insertion point, as with other CAD systems.

Greetings
Achim

15 (edited by plc-user 2023-11-25 23:01:58)

Re: QET-Element to SVG

Hallo Achim,

Danke für Deine Erklärung!

Da ich hier kein QT für die Grafik-Konvertierung verwende, am Element nicht verändern möchte und sowieso nur die Element-Datei habe, belasse ich meine Bemühungen mit der horizontalen Ausrichtung von dynamischem Text erstmal so wie sie nun sind, ohne besondere Ausrichtung! Die Positionen passen für mein Auge.

Gruß
  plc-user


via Online-Translator:

Hello Achim,

Thanks for your explanation!

Since I don't use QT for graphics-conversion here, don't want to change the element and only have the element file anyway, I'll leave my efforts with the horizontal alignment of dynamic text as they are for now, without special alignment! The positions suit my eye.

Greetings
  plc-user

Re: QET-Element to SVG

Hello everybody!

I decided to cancel the project "QET_Element2SVG"!  nomicons/sad

Instead I added SVG-Output-Support to QET_ElementScaler! nomicons/smile

In this context the order of commandline-parameters for QET_ElementScaler had to be adjusted!
So please:
Read the Readme and the scripts and batches provided on the github-page:
https://github.com/plc-user/QET_ElementScaler

In the Release-Section there are binaries for Debian GNU Linux (unstable), ReactOS (32bit) and Win10 (64bit) available, but you should be able to compile the sources on other platforms.

The software is re-written in great parts and may contain errors!

So:
Test the software and report errors, inconsistencies, or simply praise! nomicons/angel

Best regards
  plc-user

Re: QET-Element to SVG

Wow.......
Wonderful... Better for php scripting. Thank again plc_user.

Regards.
Laurent

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."

Re: QET-Element to SVG

Thank you, I can't wait to try this work but at the moment I have to fight for my health against death....

Regards,
Laurent

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."

Re: QET-Element to SVG

Salut Laurent!

I'll keep my fingers crossed and wish you all the best!
Health is one of our most valuable goods!

In the meantime I'll try to find out some more things, to implement Line-Markers, etc...

Best regards
  plc-user

Re: QET-Element to SVG

Hello plc-user,

On these url's find you about markers in SVG

https://www.svgbasics.com/markers.html
https://www.w3.org/TR/SVG11/painting.html#MarkerElement

with kind regards,
Erik

I am an industrial developer technician and born in 1960

Re: QET-Element to SVG

Hello Erik,

Thanks for your hints, but I already use the principle of how it should work with the line ends for the terminals.

If you look at the screenshot, you might realise why I'm still hesitating to implement anything: I want it to look at least similar to QET!

The lines in the image all have the same X values for start and end. The actual lines as you see them have different lengths depending on which line-ending is chosen.

Of course, I could also make the lines in the SVG the same length and place the ends over them. But then you can see the line shining through at ends without filling! In the screenshot you see a yellow rectangle behind the lines.

The complexity doesn't get any less if we think of four possible line widths, for which the "real" line length must then of course be adapted to the line width, the line-endings and the values for length...

Post's attachments

Bildschirmfoto_Linien-Enden.png, 11.74 kb, 1413 x 778
Bildschirmfoto_Linien-Enden.png 11.74 kb, 25 downloads since 2023-11-29 

Re: QET-Element to SVG

Hello plc-user,

dis_mag_term_3f-1.elmt.svg
Missing line left under

With kind regards,
Erik

Post's attachments

Attachment icon dis_mag_term_3f-1.elmt.svg 5.58 kb, 28 downloads since 2023-11-30 

I am an industrial developer technician and born in 1960

23 (edited by plc-user 2023-11-30 19:49:38)

Re: QET-Element to SVG

Hello Erik,

Thanks for Testing, Erik!  nomicons/smile
The line you are talking about is a dashed polyline and the "missing" part you mention is just a gap in this line.
If you open the SVG-file with a text-editor and change the stroke-dasharray="10,5" to perhaps "7,3" you'll find other parts of the same polyline "missing".

Maybe we need different dash-to-gap-ratio for different line-widths?  nomicons/ermm
Any suggestions?

I'm sure there's much more fine-tuning to be done...

Re: QET-Element to SVG

Hello Erik, (and all others!)

on https://github.com/plc-user/QET_ElementScaler you'll find a new version of QET_ElementScaler in which the handling of line-width and line-style for SVG-output is re-worked.

Here you see an example in the picture (top: SVG, bottom: Element-Editor) and in Element- and SVG-file.
Additionally your example with the re-worked styles is also attached.

I guess I found a quite usable solution...

Please test the new version with your "favorite" elements!
Thanks in advance! 

Best regards
  plc-user

Post's attachments

Bildschirmfoto_verschiedene_Linien.png, 26.62 kb, 813 x 893
Bildschirmfoto_verschiedene_Linien.png 26.62 kb, 26 downloads since 2023-11-30 

Attachment icon dis_mag_term_3f-1.elmt.svg 5.59 kb, 32 downloads since 2023-11-30 

Attachment icon Linien.elmt 3.99 kb, 30 downloads since 2023-11-30 

Attachment icon Linien.elmt.svg 2.46 kb, 35 downloads since 2023-11-30 

25 (edited by Re-searcher 2023-12-01 16:25:26)

Re: QET-Element to SVG

Hello plc-user,

Thanks for you program.

You are using polyline and qet elmt using polygon.

The polyline left under is not good.

elements/10_electric/10_allpole/200_fuses_protective_gears/12_magneto_thermal_circuit_breakers/
fa4213_disjoncteur_moteur_3p_n.elmt

with kind regards,
Erik

Post's attachments

Attachment icon fa4213_disjoncteur_moteur_3p_n.elmt.svg 5.25 kb, 42 downloads since 2023-12-01 

I am an industrial developer technician and born in 1960