Re: New .dxf to .elmt Conversion Program

Hello Vadoola!
Hallo plc-user!


dxftoelmt: add Print standard error and filepath name to the log files when launching program on QET element editor.
users shouldn't wait an hour in front of his element editor screen, but just look at the QET logs a minute later if nothing happens...

https://download.qelectrotech.org/qet/forum_img_2/print_dxf2elmt_error1.png

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

Re: New .dxf to .elmt Conversion Program

Hello Laurent,

One hour is a long time for a user to be waiting for a result, and there should be no need for that. I'm not sure how reasonable it is to assume a user will just look at the log file after a few minutes though either.

One thing on the list is to add some better logging / error handling into dxf2elemt. Right now on most errors it just panics and unwinds the stack printing an error to stderr.

If the program were to return an error code, ie  0 on success any anything else is an error, I assume you could capture that in QET? That way if dxf2elemt fails as it did with the above code pair issue, QET could capture that failure and pop up an alert or something saying "Conversion failed, see log for further information"

Re: New .dxf to .elmt Conversion Program

Hello Vadoola!
Hallo plc-user!

Now the program return a messageBox to inform users if dxf2elmt can't convert DXF files, but I loose QInfo() information about the errors in logs files... which is a bit of a shame, unless you do run dxf2elmt in a CLI terminal to read the convertion error!
if someone can help?


https://download.qelectrotech.org/qet/forum_img_2/dxf2elmt_error.png


--- sources/dxf/dxftoelmt.cpp
+++ sources/dxf/dxftoelmt.cpp
@@ -22,7 +22,6 @@
#include <QProcess>
#include <QMessageBox>
#include <QDir>
-#include <iostream>
#include <QDebug>
 
/**
@@ -45,11 +44,20 @@ QByteArray dxfToElmt(const QString &file_path)
     const QStringList arguments{file_path, QStringLiteral("-v")};
 
     process_.start(program, arguments);
+    // qInfo()<<"\n Start converting DXF file..........\n"<< file_path;
+    // qInfo()<< process_.readAllStandardError(); //Print standard error to log file
 
     if (process_.waitForFinished())
     {
-        qInfo()<<"\n Start converting DXF file..........\n"<< file_path;
-        qInfo()<< process_.readAllStandardError().data(); //Print standard error to log file
+        bool dxf2elmterr = process_.readAllStandardError().isEmpty();
+        QString message=QObject::tr(
+        "Error: Make sure the file is a valid .dxf file");
+       
+        if (!dxf2elmterr){
+        QMessageBox::warning(nullptr,
+                     QObject::tr("Error: to convert this dxf file."),
+                     message);
+        }
 
             const auto byte_array{process_.readAll()};
             process_.close();

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

Re: New .dxf to .elmt Conversion Program

I have this patch, show the real error but also an empty widget when convert is ok... humm what do you think?

--- sources/dxf/dxftoelmt.cpp
+++ sources/dxf/dxftoelmt.cpp
@@ -23,6 +23,8 @@
#include <QMessageBox>
#include <QDir>
#include <QDebug>
+#include <QTextBrowser>
+#include <QProcess>
 
/**
  * @brief dxftoElmt
@@ -39,28 +41,31 @@ QByteArray dxfToElmt(const QString &file_path)
         return QByteArray();
     }
 
-    QProcess process_;
+        auto process = new QProcess;
+        auto view = new QTextBrowser;
+       
+       
+        QObject::connect(process, &QProcess::readyReadStandardError, [process,view]() {
+            auto output=process->readAllStandardError().data();
+            view->append(output);
+        });
+       
         const QString program{dxf2ElmtBinaryPath()};
         const QStringList arguments{file_path, QStringLiteral("-v")};
 
-    process_.start(program, arguments);
-    // qInfo()<<"\n Start converting DXF file..........\n"<< file_path;
-     //qInfo()<< process_.readAllStandardError().data(); //Print standard error to log file
+        process->start(program, arguments);
 
-    if (process_.waitForFinished())
-    {
-        bool dxf2elmterr = process_.readAllStandardError().isEmpty();
-        QString message=QObject::tr(
-        "Error: Make sure the file is a valid .dxf file");
-       
-        if (!dxf2elmterr){
-        QMessageBox::warning(nullptr,
-                     QObject::tr("Error: to convert this dxf file."),
-                     message);
-        }
+        process->setProcessChannelMode(QProcess::MergedChannels);
+   
+        process->waitForStarted();
+        qDebug() << process->error();
+        view->show();
 
-            const auto byte_array{process_.readAll()};
-            process_.close();
+   
+    if (process->waitForFinished())
+    {
+            const auto byte_array{process->readAll()};
+            process->close();
             return byte_array;
     }
     else



https://download.qelectrotech.org/qet/forum_img_2/dxf2elmt_error2.png

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

105 (edited by plc-user 2024-10-06 15:44:02)

Re: New .dxf to .elmt Conversion Program

Salut Laurent !
Hello Vadoola!

I also played with the possibilities to give more information to the user and learned, that a MessageBox can have three texts:

QMessageBox msgBox;
msgBox.setText("QET_ElementScaler: \nadditional information about import / scaling");
msgBox.setInformativeText("See details here:");
msgBox.setDetailedText(error_output);
msgBox.exec();

That results in this MessageBox (details are hidden by default):

Post's attachments

Bildschirmfoto_2024-10-06_Import-Details.png, 17.79 kb, 307 x 273
Bildschirmfoto_2024-10-06_Import-Details.png 17.79 kb, 18 downloads since 2024-10-06 

Fragen zu QET gehören in dieses Forum und werden nicht per PM beantwortet! – Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

Re: New .dxf to .elmt Conversion Program

Hallo plc-user

great nomicons/smile

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

Re: New .dxf to .elmt Conversion Program

Such an additional MessageBox should only popup, when there really is information for the user: When everything's fine there should be no additional Box to close...

This means that we should be very frugal with any outputs in our CLI software!
If there is nothing to report, then shut up!   nomicons/wink

Fragen zu QET gehören in dieses Forum und werden nicht per PM beantwortet! – Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

Re: New .dxf to .elmt Conversion Program

Thanks you for your commit nomicons/wink

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

109 (edited by vadoola 2024-10-06 23:08:59)

Re: New .dxf to .elmt Conversion Program

Hello Laurent, plc-user,

@plc-user that multi-info messagebox looks like a useful way to do it. I agree the box should only popup when it's needed to provide info to a user, if everything goes well they should just get the element in the editor.

In verbose mode to print the element to stdout there shouldn't be a lot of information I think if everything goes well it's mostly just created <file_name>.elmt or something like that I would need to go double check. Clearly though something slipped through in my commit. The "Remove Polygon with one less points" was something I had in there when I was testing the most recent couple of commits, which doesn't convert single point polylines, and converts dual point polylines from Polygons to Line Elements. I thought I had removed them all from the code before commiting, but clearly missed something.

Re: New .dxf to .elmt Conversion Program

Hello Vadoola!
Hallo plc-user!


Uniformise MessageBox, add the same type of box popup like plc-user added for QET_ElementScaler, when dxf2elmt can't convert DXF files.
Add QObjet for translate box message.

https://download.qelectrotech.org/qet/forum_img_2/dxf2elmt_error3.png
https://download.qelectrotech.org/qet/forum_img_2/dxf2elmt_error6.png

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

Re: New .dxf to .elmt Conversion Program

Hello Vadoola,

about the definition-line.

The definition-line describes the dimensions of the element and is calculated by the element editor. It is therefore not noticeable that the values have not been calculated (correctly) if the import is carried out directly in the element editor.
If the element is converted on the command line and the element is used directly in the diagram editor, it is not displayed correctly because the width, height and hotspots are not set correctly.
This is particularly noticeable when dragging the element onto the folio, see appendix.

You already write it in a comment in your code (src/qelmt/mod.rs from line 59:

//The original code had the height, and width hard coded to 10
//and the hotspots hard coded to 5. I'm not sure why this is?
//Maybe actually calculating the size wasn't worth it? I'm not sure
//if that info is part of the dxf. And maybe when you open he elemnt
//in the elemtent editor it corrects it anyway. Just look into it, and
//se if this is something that needs to get adjusted.

The values for the definition line can only be calculated correctly if all information about all graphical elements is available.
In QET_ElementScaler I keep the whole QET-element in memory and recalculate the definition-line after scaling and before writing anything to stdout.
The calculation is specific to QET and it took me some time and help from Laurent and Joshua to implement it accordingly.

If you read in the file sequentially and output everything immediately to stdout, the definition-line values can not be correct. As far as I know, the necessary information is not in the dxf...

Post's attachments

Bildschirmfoto_falsche_def-line.png, 22.52 kb, 1189 x 750
Bildschirmfoto_falsche_def-line.png 22.52 kb, 19 downloads since 2024-10-14 

Fragen zu QET gehören in dieses Forum und werden nicht per PM beantwortet! – Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

Re: New .dxf to .elmt Conversion Program

Hallo plc-user

plc-user wrote:

Hello Vadoola,
If you read in the file sequentially and output everything immediately to stdout, the definition-line values can not be correct. As far as I know, the necessary information is not in the dxf...

The original version of the code was doing exactly that, essentially just converting it piecemeal and dumping it to stdout.

Part of the big change that was released in my version 0.4.0 was doing exactly what you are doing, reading the dxf in, converting to to element structures in memory and then writing it out. I made this change exactly for the reasons you are talking about, if I needed to do some processing on it, such as other things we had discussed, determining that a polyline is really a circle and concerting it to an ellipse, etc.

So it sounds like I'm heading in the right direction, I just need to keep ticking away at improvements. I already looked a bit into scaling it and such, I'll take a closer look at how you do it in QET_ElementScaler. Thanks

113 (edited by plc-user 2024-10-16 14:14:06)

Re: New .dxf to .elmt Conversion Program

Hello Vadoola,

start reading here:
https://github.com/plc-user/QET_Element … ts.cpp#L50
it's (almost?) the same as in QET

As input-parameter I use a rectangle that represents the min- and max-values of all graphical elements. This rectangle is a global variable "ElmtMinMax" and is determined during the processing of every part.

Fragen zu QET gehören in dieses Forum und werden nicht per PM beantwortet! – Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

114 (edited by plc-user 2024-10-16 14:15:40)

Re: New .dxf to .elmt Conversion Program

Hello Vadoola!
Salut Laurent !

About the Texts / Fonts:

I don't know, where to find "official" information about fonts in QET, so I noted what I found out about fonts in sources of QET_ElementScaler:
https://github.com/plc-user/QET_Element … nts.h#L301
If no font size is defined in the font-tag it defaults to "9" in QET what often is too big!

So the question is:
Do texts in dxf include a size? I guess so.
So you should add that info to the font-tag in elmt-file, Vadoola.

Fragen zu QET gehören in dieses Forum und werden nicht per PM beantwortet! – Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

Re: New .dxf to .elmt Conversion Program

Hello Laurent and plc-user,

plc-user wrote:

Hello Vadoola!
Salut Laurent !

About the Texts / Fonts:

I don't know, where to find "official" information about fonts in QET, so I noted what I found out about fonts in sources of QET_ElementScaler:
https://github.com/plc-user/QET_Element … nts.h#L301
If no font size is defined in the font-tag it defaults to "9" in QET what often is too big!

So the question is:
Do texts in dxf include a size? I guess so.
So you should add that info to the font-tag in elmt-file, Vadoola.

I'll add it to the list. It looks like the dxf has a text height property, I'm assuming it would be in the same units are the rest of the dxf, ie it's a height in mm, or inches, etc. I would have to convert that into a font size. It looks like I already need to figure out how to do some font processing. One of the forums posts mentioned text not being in the correct spot. I figure out why and documented it in the Issue https://github.com/Vadoola/dxf2elmt/issues/7. Essentially if the horizontal and vertical alignment on the text are not the default (top left), then you need to calculate the location based on a different set of coordinates, and the font rendering. As part of trying to add that in, I can also try to figure out converting the text size in the dxf into a proper font size.

Re: New .dxf to .elmt Conversion Program

@vadoola: FYI https://qelectrotech.org/forum/viewtopi … 496#p20496
https://github.com/ixmilia/dxf-rs/issues/46

You use last dxf-rs old tag or master git?


Edit you used the V 0.5.0
https://github.com/qelectrotech/new_dxf … o.toml#L20

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

Re: New .dxf to .elmt Conversion Program

scorpio810 wrote:

@vadoola: FYI https://qelectrotech.org/forum/viewtopi … 496#p20496
https://github.com/ixmilia/dxf-rs/issues/46

You use last dxf-rs old tag or master git?

As of right now, dxf2elmt is using the latest official tagged version of dxf-rs from crates.io, which is 0.5.0, tagged all the way back in September 2021.

I have been considering on updating to use the master branch from git, even though it looks like development on dxf-rs has slowed to a crawl there are still updates to the master branch that have happened int he last 3 years.

I think I've seen at least 2 or 3 of these where the dxf reading fails due to some unsupported code point. The past couple of weeks since I tagged 0.4.0 has been mostly investigating issues, and brainstorming. I may try and update dxf-rs to the master branch and see if that breaks anything, and if it fixes any of these reported issues as well.

Re: New .dxf to .elmt Conversion Program

Edit: I tried to go to last git main branch but dxf2elmt code can't compile after patched cargo.toml and use cargo update to update cargo.lock...

diff --git a/Cargo.toml b/Cargo.toml
index 2d78bdc..9b8bc2e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,7 +17,7 @@ lto = true
opt-level = 3
 
[dependencies]
-dxf = "0.5.0"
+dxf = { git = "https://github.com/ixmilia/dxf-rs.git" }
simple-xml-builder = "1.1.0"
bspline = "1.1.0"
uuid = { version = "1.10.0", features = ["serde", "v4"] }


~/new_dxf2elmt_vadoola_fork$ cargo build --release
   Compiling dxf2elmt v0.4.0 (/home/laurent/new_dxf2elmt_vadoola_fork)
warning: unused import: `dxf::objects::Object`
--> src/qelmt/mod.rs:1:5
  |
1 | use dxf::objects::Object;
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default
 
warning: unused import: `text`
--> src/qelmt/dynamictext.rs:1:13
  |
1 | use super::{text, two_dec};
  |             ^^^^
 
error[E0599]: no method named `get_is_closed` found for reference `&dxf::entities::Polyline` in the current scope
    --> src/qelmt/polygon.rs:60:26
     |
60   |             closed: poly.get_is_closed(),
     |                          ^^^^^^^^^^^^^
     |
help: there is a method `set_is_closed` with a similar name, but with different arguments
    --> /home/laurent/new_dxf2elmt_vadoola_fork/target/release/build/dxf-a92690d5c3960b91/out/generated/entities.rs:1726:5
     |
1726 |     pub fn set_is_closed(&mut self, val: bool) {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
error[E0599]: no method named `get_is_closed` found for reference `&dxf::entities::LwPolyline` in the current scope
    --> src/qelmt/polygon.rs:85:26
     |
85   |             closed: poly.get_is_closed(),
     |                          ^^^^^^^^^^^^^
     |
help: there is a method `set_is_closed` with a similar name, but with different arguments
    --> /home/laurent/new_dxf2elmt_vadoola_fork/target/release/build/dxf-a92690d5c3960b91/out/generated/entities.rs:1388:5
     |
1388 |     pub fn set_is_closed(&mut self, val: bool) {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
error[E0599]: no method named `get_is_closed` found for reference `&dxf::entities::Spline` in the current scope
    --> src/qelmt/polygon.rs:144:28
     |
144  |             closed: spline.get_is_closed(),
     |                            ^^^^^^^^^^^^^
     |
help: there is a method `set_is_closed` with a similar name, but with different arguments
    --> /home/laurent/new_dxf2elmt_vadoola_fork/target/release/build/dxf-a92690d5c3960b91/out/generated/entities.rs:2107:5
     |
2107 |     pub fn set_is_closed(&mut self, val: bool) {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
For more information about this error, try `rustc --explain E0599`.
warning: `dxf2elmt` (bin "dxf2elmt") generated 2 warnings
error: could not compile `dxf2elmt` (bin "dxf2elmt") due to 3 previous errors; 2 warnings emitted

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

Re: New .dxf to .elmt Conversion Program

scorpio810 wrote:

Edit: I tried to go to last git main branch but dxf2elmt code can't compile after patched cargo.toml and use cargo update to update cargo.lock...

error[E0599]: no method named `get_is_closed` found for reference `&dxf::entities::Polyline` in the current scope
    --> src/qelmt/polygon.rs:60:26
     |
60   |             closed: poly.get_is_closed(),
     |                          ^^^^^^^^^^^^^
     |
help: there is a method `set_is_closed` with a similar name, but with different arguments
    --> /home/laurent/new_dxf2elmt_vadoola_fork/target/release/build/dxf-a92690d5c3960b91/out/generated/entities.rs:1726:5
     |
1726 |     pub fn set_is_closed(&mut self, val: bool) {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It looks like the function was renamed at some point from get_is_closed to just is_closed, the source between the 2 is identica.

0.5.0

pub fn get_is_closed(&self) -> bool {
        self.flags & 1 != 0
    }

Master

pub fn is_closed(&self) -> bool {
        self.flags & 1 != 0
    }

I haven't tested it properly, but just replacing all the .get_is_closed() function calls with .is_closed() makes it compile for me

Re: New .dxf to .elmt Conversion Program

Thanks Carl, dxf2elmt compile it's now ok for me too, and correct at the same time issue 
https://github.com/ixmilia/dxf-rs/issues/46
and
https://github.com/Vadoola/dxf2elmt/issues/19


Linux debian sid 64 dxf2elmt
https://github.com/scorpio810/dxf2elmt.git

Make the File Executable

chmod +x dxf2elmt 

Post's attachments

Attachment icon dxf2elmt 2.92 mb, 20 downloads since 2024-10-18 

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

Re: New .dxf to .elmt Conversion Program

Windows 64 binary.

Post's attachments

Attachment icon dxf2elmt.zip 1.33 mb, 35 downloads since 2024-10-18 

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

Re: New .dxf to .elmt Conversion Program

macOS INTEL X86_64 binary

Post's attachments

Attachment icon dxf2elmt.zip 1.28 mb, 10 downloads since 2024-10-18 

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

Re: New .dxf to .elmt Conversion Program

I've noticed that many more DXF files are now being converted,
whereas previously they would generate an error and can't be converted.... nomicons/wink

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

Re: New .dxf to .elmt Conversion Program

scorpio810 wrote:

I've noticed that many more DXF files are now being converted,
whereas previously they would generate an error and can't be converted.... nomicons/wink

So it sounds like it's well worth upgrading to the master branch, and its pretty easy to make it compile.

Do you want to issue a pull request, or should I just make the few changes on my branch?

Re: New .dxf to .elmt Conversion Program

Without your help on the dxf-rs source code and polygon.rs change I wouldn't have got far,
so you do the honours to make the few changes in your branch. nomicons/wink

Thanks you Carl.

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