Topic: freepascal-code to take a QET- Element and scale the content by a fact

plc-user wrote:

Hello S.DEFFAUX!

Who do you want to punish with such work?  nomicons/wink
Checking all existing QET-Elements if they show a
front-view and then scale them by hand...

In the Lazarus-/freepascal-Wiki I found the beginning
of the now existing freepascal-code to take a QET-
Element and scale the content by a factor.

You find the sources and pre-compiled versions for
Debian unstable and ReactOS at
https://github.com/plc-user/QET_ElementScaler

The code compiles/runs with Lazarus 2.0.10 and
FreePascal 3.2.0 on Debian/GNU Linux (unstable) and
ReactOS (0.4.15-dev-1196) (didn't try, but should run
on win7 or 10, too)

In combination with a small shell-script the program
edited all front-views of "my" elements (about 800)
in 1.5 seconds.


But still the main-Question is: What scaling-faktor
do we want to use for front-views of our elements.
In my opinion 100 mm -> 200 px is a good value!
That means that ${someone} has to check, if the already
existing parts use the same scaling-factor. As I wrote
in a previous message: The three examples had three
different factors and I guess there are even more in the
QET-collection ...


Best regards
  plc-user

Re: freepascal-code to take a QET- Element and scale the content by a fact

I hadn't really tested this little utility yet, but recently I had to get back to drawing at work for a new electrical project ...
and this great tool has made it much easier to work with thumbnails not always at the right scale factor.

https://download.tuxfamily.org/qet/forum_img_2/QET_ElementScaler.png

Very easy to use:
example

laurent@debian:~/.qet$ ./QET_ElementScaler elements/nx300320190520.elmt 10
laurent@debian:~/.qet$ ./QET_ElementScaler elements/nx300320190520.elmt 0.5
laurent@debian:~/.qet$ ./QET_ElementScaler elements/nx300320190520.elmt 5


laurent@debian:~/.qet/elements$ ls -al | grep nx
-rw-r--r-- 1 laurent laurent   691553  1 juin   2021 nx300320190520.elmt
-rw-r--r-- 1 laurent laurent   673021  9 mai   21:21 nx300320190520.SCALED.elmt

Just reload collection by right click, drag and drop new scaled.elmt.

Great tool, thanks plc-user.

BTW, I added description and link to plc-user Github for download this nice tool on QET download main page.

Re: freepascal-code to take a QET- Element and scale the content by a fact

scorpio810 wrote:

Great tool, thanks plc-user.

You're welcome, Laurent!

4 (edited by plc-user 2022-08-14 18:08:49)

Re: freepascal-code to take a QET- Element and scale the content by a fact

EDITED
Just created a new version of QET_ElementScaler:
With the newly added optional parameter "-o" or "--stdout" it is now possible to write the scaled element-data to stdout instead of writing a renamed file.

The new option "-i" or "--stdin" allows QET_ElementScaler to be used with re-direction and/or pipes on the commandline:
The input-data is read from stdin and the output will be written to stdout.

Examples to write to stdout:
QET_ElementScaler -o InputElement.elmt 1.4 > NewScaledElement.elmt
QET_ElementScaler -o InputElement.elmt 1.4 | OtherSoftwareBinary

Examples to use re-direction and/or pipes:
QET_ElementScaler -i  1.4 < InputElement.elmt > NewScaledElement.elmt
cat  InputElement.elmt | QET_ElementScaler -i 1.4 | OtherSoftwareBinary

Have a look and give it a try:
https://github.com/plc-user/QET_ElementScaler

Re: freepascal-code to take a QET- Element and scale the content by a fact

Today I uploaded a new version of "QET_ElementScaler" to github: https://github.com/plc-user/QET_ElementScaler

This version is completely rewritten in C++, where I (like QET) use pugixml for handling the contents of the element files.

I made a few additions/changes that makes working with the software easier: The XML description line no longer needs to be removed afterwards!

As before, x and y scaling factors can be specified, input is via STDIN (-i) or a file (-f FILEINAME) and output is, as before, to a new file or to STDOUT (-o).

In addition, I have added the possibility to remove "terminals" from the element. This can be useful when terminals can be omitted from overloaded front views.

Furthermore, there is now the possibility to flip polygons and lines horizontally and/or vertically. This can be useful during the development of complex front views, as long as these functions are not yet available in the QET element editor.

Special care should be taken with the option "--OverwriteOriginal", because here the original file will be overwritten WITHOUT further request!

The scaled values of the new element are written into the new file with a maximum of 2 decimal places. In my view, this is completely sufficient for the display of schematic symbols and front views (thumbnails). In some elements present in the QET collection I have seen values with up to six decimal places, which in my opinion is excessive.
To "fix" such elements, QET_ElementScaler can of course be used! With the call:

QET_ElementScaler -f FILENAME

the values are rounded to max. 2 decimal places and any font sizes with decimal places are rounded to whole numbers.

I wish all users of the software a lot of fun and success with it and would like to see bugs reported (e.g. here or at github). Of course, I also have an "open ear" for suggestions for improvement!

Best regards
plc-user

Re: freepascal-code to take a QET- Element and scale the content by a fact

;-)

Re: freepascal-code to take a QET- Element and scale the content by a fact

Today I uploaded a new version of "QET_ElementScaler" to github: https://github.com/plc-user/QET_ElementScaler

It's not perfect yet, but it's getting better and better!

All graphic elements are now taken into account when mirroring!
The mirroring is done at the coordinate axes.

The texts are not (yet) in the right position, because the text-length, -width and -orientation must also be taken into account for the new position. For the values of the definition line (hotspots, ...) the way of calculation is not yet clear to me. But you have to open the new file with the element editor anyway to check or correct the positions of the texts. Then the definition line will be corrected. Take a look at the sample-file I created in the attachment.

In any case, this is already very useful as a starting point for the further processing of the component!  nomicons/smile

Post's attachments

Attachment icon FLIP-Samples.qet 795.35 kb, 16 downloads since 2022-12-29 

Re: freepascal-code to take a QET- Element and scale the content by a fact

here a screenshot of an element:

Post's attachments

FLIP-Sample.png, 58.54 kb, 1126 x 373
FLIP-Sample.png 58.54 kb, 13 downloads since 2022-12-29 

Re: freepascal-code to take a QET- Element and scale the content by a fact

Work only on linux ?

Re: freepascal-code to take a QET- Element and scale the content by a fact

at github I uploaded binaries for Linux and ReactOS. The ReactOS-binary works also on win.
If you compile it on other systems like macOS, etc. it will run there, too!

Re: freepascal-code to take a QET- Element and scale the content by a fact

Hi plc-user,
tried to compile on macOS 12 X86_64:

laurents-iMac-Pro:QET_ElementScaler laurent$ bash ./compile.sh 
In file included from main.cpp:94:
./main.h:92:5: warning: suggest braces around initialization of subobject [-Wmissing-braces]
    0
    ^
    {}
1 warning generated.
ld: warning: option -s is obsolete and being ignored
laurents-iMac-Pro:QET_ElementScaler laurent$ 
laurents-iMac-Pro:elements laurent$ ./QET_ElementScaler --FlipVertical pylone.elmt 
could not convert "pylone.elmt" to a float-number!
laurents-iMac-Pro:elements laurent$ ./QET_ElementScaler pylone.elmt --FlipVertical 
could not convert "pylone.elmt" to a float-number!

Post's attachments

Attachment icon QET_ElementScaler 347.09 kb, 16 downloads since 2022-12-29 

12 (edited by plc-user 2022-12-29 13:59:52)

Re: freepascal-code to take a QET- Element and scale the content by a fact

Salut Laurent!

Thank you for the feedback!
GCC on Debian unstable and TDM-GCC on ReactOS did not show this warning.
Otherwise I would have corrected that line:
Don't like warnings when compiling code, too!

You may change Line 92 in main.h to
    {0,0,0,0}

Then the warning should be gone.
EDIT (29.12.22 11:58 CET):
already changed at github - no new binaries needed for this code-change

Re: freepascal-code to take a QET- Element and scale the content by a fact

laurents-iMac-Pro:elements laurent$ ./QET_ElementScaler --FlipVertical pylone.elmt 
could not convert "pylone.elmt" to a float-number!
laurents-iMac-Pro:elements laurent$ ./QET_ElementScaler pylone.elmt --FlipVertical 
could not convert "pylone.elmt" to a float-number!

when using Options other than scaling-factor and filename, you have to add the filename with "-f filename"
For example:

./QET_ElementScaler --FlipVertical -f pylone.elmt 

Re: freepascal-code to take a QET- Element and scale the content by a fact

Hello plc-user,

what is the command line to use it?
I saw the same thing on my Debian unstable:

[11:32:19] laurent@debian:/media/backup6/download/QET_ElementScaler$ git pull
remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 22 (delta 13), reused 18 (delta 10), pack-reused 1
Dépaquetage des objets: 100% (22/22), 13.08 Kio | 893.00 Kio/s, fait.
Depuis https://github.com/plc-user/QET_ElementScaler
   4f4bda3..43b1d59  master     -> origin/master
 * [nouvelle étiquette] 0.4beta5   -> 0.4beta5
 * [nouvelle étiquette] 0.4beta2   -> 0.4beta2
 * [nouvelle étiquette] 0.4beta3   -> 0.4beta3
 * [nouvelle étiquette] 0.4beta4   -> 0.4beta4
Mise à jour 4f4bda3..43b1d59
Fast-forward
 README.md                  |  11 +++++------
 inc/pugixml/pugiconfig.hpp |   2 +-
 inc/pugixml/pugixml.cpp    |  32 +++++++++++++++++++++++++++----
 inc/pugixml/pugixml.hpp    |   7 +++++--
 main.cpp                   | 344 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------
 main.h                     |  67 ++++++++++++++++++++++++++++++++++++++++++----------------------
 6 files changed, 357 insertions(+), 106 deletions(-)
[11:32:26] laurent@debian:/media/backup6/download/QET_ElementScaler$ ./compile.sh 
[11:34:19] laurent@debian:/media/backup6/download/QET_ElementScaler$  cd /home/laurent/.qet
[11:35:25] laurent@debian:~/.qet$ ./QET_ElementScaler elements/pylone.elmt  --FlipVertical 
could not convert "elements/pylone.elmt" to a float-number!
[11:36:32] laurent@debian:~/.qet$ 

Re: freepascal-code to take a QET- Element and scale the content by a fact

plc-user wrote:
laurents-iMac-Pro:elements laurent$ ./QET_ElementScaler --FlipVertical pylone.elmt 
could not convert "pylone.elmt" to a float-number!
laurents-iMac-Pro:elements laurent$ ./QET_ElementScaler pylone.elmt --FlipVertical 
could not convert "pylone.elmt" to a float-number!

when using Options other than scaling-factor and filename, you have to add the filename with "-f filename"
For example:

./QET_ElementScaler --FlipVertical -f pylone.elmt 

Thanks! aaah just forgot -f, I' m stupid .. nomicons/smiley-green

[11:36:32] laurent@debian:~/.qet$ ./QET_ElementScaler  --FlipVertical -f elements/pylone.elmt 
[11:42:45] laurent@debian:~/.qet$ 

Re: freepascal-code to take a QET- Element and scale the content by a fact

Nice, works well on osx 12 monterey x86_64 with my build https://qelectrotech.org/forum/misc.php … download=1
https://download.tuxfamily.org/qet/forum_img_2/macos_qet_elementscaler_flip.png

17 (edited by plc-user 2022-12-29 13:10:20)

Re: freepascal-code to take a QET- Element and scale the content by a fact

scorpio810 wrote:

Hello plc-user,

what is the command line to use it?
(...)

Just call it without any options or use "--help":

me@notebook:~/Projekte/c_c++/QET_ElementScaler$ ./QET_ElementScaler --help

"QET_ElementScaler" version 0.4beta5 needs some arguments!

usage for simple mode:
"QET_ElementScaler"  [options]  FILENAME  ScalingFactor

In extended mode the scaling-factors for X and Y may differ and it is
allowed to specify only one direction for scaling. In each case the
Font-Sizes and Circle-Diameters are scaled by the smaller value.

usage for extended mode:
"QET_ElementScaler" [options] [-x FactorX] [-y FactorY] -f FILENAME


available options:
 -i | --stdin     input-data is read from stdin, a given filename is 
                  ignored and scaled element will be written to stdout
 -o | --stdout    output will be written to stdout
 -x VALUE         or
 --factorx VALUE  factor for x-values (x, rx, width, ...)
 -y VALUE         or
 --factory VALUE  factor for y-values (y, ry, height, ...)
 -f FILENAME      or 
 --file FILENAME  the file that will be used
 -h | --help      show this help


there are also some "long-opt"-only options:
"--RemoveAllTerminals" removes all terminals from the element
                       (useful for front-views or "thumbnails")
"--FlipHorizontal"     flips all graphical elements horizontally
                       (useful during creation of elements)
"--FlipVertical"       flips all graphical elements vertically
                       (useful during creation of elements)
"--OverwriteOriginal"  the original file is replaced by scaled one
                       (CAUTION: Be careful with this option!)

without parameters or with "-h" or "--help" this help is displayed


The most simple call:
"QET_ElementScaler" -f FILENAME
A new file is created with all values rounded to two decimal places
and all font sizes are set to integers - some kind of cleanup... 

As always with free software: Use it at your own risk! 

Re: freepascal-code to take a QET- Element and scale the content by a fact

With my QET cross-compile MXE environment x86_64 that I use to build QET Windows packages, I just compile new version of QET_ElementScaler.exe for Win 10/11:

[12:30:38] laurent@debian:/media/backup6/download/QET_ElementScaler$ export PATH=/home/laurent/digikam3333/project/bundles/mxe/build.win64/usr/bin:$PATH
[12:33:01] laurent@debian:/media/backup6/download/QET_ElementScaler$ ./compile.sh 
[12:33:18] laurent@debian:/media/backup6/download/QET_ElementScaler$ 

Change g++ PATH to my MXE environment toolchain for compile Windows package:

[12:52:38] laurent@debian:/media/backup6/download/QET_ElementScaler$ git diff
diff --git a/compile.sh b/compile.sh
index 94f4f4e..a950aa8 100755
--- a/compile.sh
+++ b/compile.sh
@@ -5,6 +5,6 @@ mkdir -p obj/inc/pugixml
 
 
# compile QET_ElementScaler
-g++ -Wall -O2 -std=c++17 -c inc/pugixml/pugixml.cpp -o obj/inc/pugixml/pugixml.o
-g++ -Wall -O2 -std=c++17 -c main.cpp -o obj/main.o
-g++ -o  QET_ElementScaler obj/inc/pugixml/pugixml.o obj/main.o  -s
+/home/laurent/digikam3333/project/bundles/mxe/build.win64/usr/bin/x86_64-w64-mingw32.static-g++ -Wall -O2 -std=c++17 -c inc/pugixml/pugixml.cpp -o obj/inc/pugixml/pugixml.o
+/home/laurent/digikam3333/project/bundles/mxe/build.win64/usr/bin/x86_64-w64-mingw32.static-g++ -Wall -O2 -std=c++17 -c main.cpp -o obj/main.o
+/home/laurent/digikam3333/project/bundles/mxe/build.win64/usr/bin/x86_64-w64-mingw32.static-g++ -o  QET_ElementScaler obj/inc/pugixml/pugixml.o obj/main.o  -s



Download here:
https://download.tuxfamily.org/qet/buil … entScaler/

https://www.virustotal.com/gui/file/413 … ?nocache=1

Re: freepascal-code to take a QET- Element and scale the content by a fact

Hallo plc-user,

A big thank you for your work and I speak on behalf of all users of QET, which fills a gap very often requested.
I just noticed a small bug, nothing serious but in your example provided, some elements had their hotspot shifted or next to it.

Cheers,

Laurent

https://download.tuxfamily.org/qet/forum_img_2/qet_elementscaler_flip_wrong_hotspot.png
https://download.tuxfamily.org/qet/forum_img_2/qet_elementscaler_flip_wrong_hotspot2.png


BTW, a workaround .... yes i love workaround, uhuhu ... it 's to open these element with wrong hotspot with QET element editor and save it to fix hotspot postion.

Re: freepascal-code to take a QET- Element and scale the content by a fact

Salut Laurent,

is it a "bug" if I already write exactly that in todays introductory post? nomicons/wink

plc-user wrote:

(...) For the values of the definition line (hotspots, ...) the way of calculation is not yet clear to me. But you have to open the new file with the element editor anyway to check or correct the positions of the texts. Then the definition line will be corrected. (...)

Maybe you (someone) can give me a hint where I can find the place in the QET source code where the values for the hotspots, width and height for the definition-line are determined? Or is it somewhere described, how to determine the correct values? Then I could perhaps implement this in the short term...

Re: freepascal-code to take a QET- Element and scale the content by a fact

Hallo Plc-user,

we had discussed it with UnAlcade (Raul) the developer of the qet_tb_generator plug-in, the discussion is in this topic:

https://qelectrotech.org/forum/viewtopi … 5269#p5269

Re: freepascal-code to take a QET- Element and scale the content by a fact

plc-user wrote:

Salut Laurent,

is it a "bug" if I already write exactly that in todays introductory post? nomicons/wink

hmm, I read too fast and did not pay attention to this detail, sorry. nomicons/wink

23 (edited by plc-user 2022-12-30 12:54:54)

Re: freepascal-code to take a QET- Element and scale the content by a fact

Salut Laurent!

Thank you for the Link to the other thread!

Hello everybody!

Please have a look at the new version:  https://github.com/plc-user/QET_ElementScaler

I now implemented the calculation of values for definition-line and tried with some Elements:
To me, this looks pretty good!  nomicons/smile

In the attached file you find some samples.

Post's attachments

Attachment icon FLIP-Samples_new.qet 530.17 kb, 12 downloads since 2022-12-30 

Re: freepascal-code to take a QET- Element and scale the content by a fact

Hallo Plc-user,

many thanks.
I also rebuild Windows & macOS executable programs.

Post's attachments

Attachment icon QET_ElementScaler 347.23 kb, 19 downloads since 2022-12-30 

Re: freepascal-code to take a QET- Element and scale the content by a fact

Salut Laurent,

there is no need to compile QET_ElementScaler for windows, because that is available in the releases.
I compile my programs for Windows on ReactOS and mention it that way to support another open source project at least by advertising it a bit!
https://reactos.org