How to have bullet points in an error message?

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

How to have bullet points in an error message?

Post by NormandC »

This is a follow up on this forum discussion which brought almost zero interest. Thanks DeepSOIC, at least I got two replies from one single person... :(

This:
FC018_PD_error_message_enhancement_02.png
FC018_PD_error_message_enhancement_02.png (21.94 KiB) Viewed 2389 times

Is utterly meaningless to beginners, as I mentioned in the linked topic. I'm trying to tackle this.

I made a branch, found the proper files where to change the message (again, all discussed in the previous topic).

But I can't get bullet points to properly show up, they are replaced with ⯢.
FC018_PD_error_message_enhancement_01.png
FC018_PD_error_message_enhancement_01.png (33.96 KiB) Viewed 2389 times

Naively I first tried this:

Code: Select all

    // if the Base property has a valid shape, fuse the prism into it
    TopoDS_Shape base;
    try {
        base = getBaseShape();
    } catch (const Base::Exception&) {
        return new App::DocumentObjectExecReturn("The requested feature cannot be created. The reason may be that:\n"
                                                 "• the active Body does not contain a base shape, so there is no "
                                                 "material to be removed;\n"
                                                 "• the selected sketch does not belong to the active Body.");
    }

Then, based on a quick web search, this:

Code: Select all

    // if the Base property has a valid shape, fuse the prism into it
    TopoDS_Shape base;
    try {
        base = getBaseShape();
    } catch (const Base::Exception&) {
        return new App::DocumentObjectExecReturn("The requested feature cannot be created. The reason may be that:\n"
                                                 "\u2022 the active Body does not contain a base shape, so there is no "
                                                 "material to be removed;\n"
                                                 "\u2022 the selected sketch does not belong to the active Body.");
    }
Both produce the same wrong result.

What I want it to look like is this:
Input error

The requested feature cannot be created. The reason may be either:
  • The active Body does not contain a base shape, so there is no material to be removed.
  • The selected sketch does not belong to the active Body.
Thanks.
chrisb
Veteran
Posts: 53921
Joined: Tue Mar 17, 2015 9:14 am

Re: How to have bullet points in an error message?

Post by chrisb »

How about using simple dashes? They have some advantages like so:
- they are available on every OS
- they are independent from locale settings

They work best if you can indent the follow-up lines. If indentation at the line start is preserved you could do the linebreaks yourself and indent the follow-ups manually.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 53921
Joined: Tue Mar 17, 2015 9:14 am

Re: How to have bullet points in an error message?

Post by chrisb »

I forgot: Your proposal sure is an improvement!
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How to have bullet points in an error message?

Post by NormandC »

Thanks Chris.

To be honest, I dislike use of dashes in bullet lists. But what you said had me wondering, how would this translate.

I really hope a dev can enlighten me...

I really think we need to improve error messages, to give more explicit information to end users.

One other error message to improve is the infamous "Failed to validate broken face". On the... face of it, it really is nonsensical to someone who has no idea how solids are built under the hood.

I just searched the Github repo, and I only found one place where this message appears, in
https://github.com/FreeCAD/FreeCAD/blob ... se.cpp#L92

I'm surprised it's in Part, I don't recall seeing this message anywhere but in PartDesign.
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How to have bullet points in an error message?

Post by NormandC »

I learned something new today.

Part Extrude has a "Face Maker Class" property, used when its property "Solid" is set to true. Default seems to be Part::FaceMakerBullseye. The field is text, not a pull down menu. I input Part::FacemakerCheese, based on the name of the file I mentioned above (FacemakerCheese.cpp).

For a Part Extrude of an open sketch set to solid, the error tooltip is "Wire is not closed" with Part::FaceMakerBullseye. For Part::FacemakerCheese, the error tooltip is "Failed to validate broken face".

In short, this limits options, since it is really a Part module message.

A suggestion: to change it to "Failed to create face, wire is not closed"?

Ideally, PartDesign should have its own error message, in my opinion.

But the real important question: what does cheese have to do with face creation? :D
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to have bullet points in an error message?

Post by wmayer »

But I can't get bullet points to properly show up, they are replaced with ⯢.
The \u2022 is the so called code point of the unicode character but you cannot use it as is in a C string. You have to encode it as a utf-8 string and then make sure that the Qt dialog that shows the error message uses QString::fromUtf8.

Here is a Python snippet to get the utf-8 encoded version:

Code: Select all

u"\u2022".encode("utf-8")
which gives the output: '\xe2\x80\xa2'
So, replace \u2022 with \xe2\x80\xa2 in the string.

FYI:
In C++11 there is an alternative way where a code point can be used directly:

Code: Select all

u8"\u2022"
However, MSVC 2013 sucks and raises an error.
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How to have bullet points in an error message?

Post by NormandC »

Thanks for the hint Werner, but

wmayer wrote: Sun Dec 02, 2018 10:10 am then make sure that the Qt dialog that shows the error message uses QString::fromUtf8.
This is just beyond me. I'm not a programmer, and I don't really want to learn, I don't have the time nor the inclination; I'm pretty busy with other FreeCAD stuff already. I just thought this would be simple... :?

To be honest, I assumed that all Qt dialogs would support utf8. It just seems logical to me to implement this at large by default.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to have bullet points in an error message?

Post by wmayer »

To be honest, I assumed that all Qt dialogs would support utf8. It just seems logical to me to implement this at large by default.
Yes, all Qt dialogs support utf-8 but in their API they only accept QString's and when a raw C string is provided then it's up to the programmer to know if the string is/can be encoded or not and thus to use QString::fromUtf8 or QString::fromLatin1.

Anyway, you only have to make the suggested change in the string you have modified. Don't care about the utf-8 stuff for the moment. In case it works you will see it immediately, otherwise the dialogs shows some garbage characters as in your screen shot.
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How to have bullet points in an error message?

Post by NormandC »

I applied your suggested change and compiled again, and I got the same garbled characters.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to have bullet points in an error message?

Post by wmayer »

I had a look where the error message is reported. It happens inside TaskDlgFeatureParameters::accept() (see file TaskFeatureParameters.cpp) with the line:

Code: Select all

QMessageBox::warning(Gui::getMainWindow(), tr("Input error"), QString::fromLatin1(e.what()));
So, because QString::fromLatin1 instead of QString::fromUtf8 is used the characters are not properly decoded.

Btw, with MSVC it even works to directly use the bullet character instead of its utf-8 encoding but I am not sure if this would be still platform independent.
Post Reply