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!
User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

How to have bullet points in an error message?

Postby NormandC » Sun Dec 02, 2018 2:20 am

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 806 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 806 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
Posts: 18190
Joined: Tue Mar 17, 2015 9:14 am

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

Postby chrisb » Sun Dec 02, 2018 6:51 am

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.
chrisb
Posts: 18190
Joined: Tue Mar 17, 2015 9:14 am

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

Postby chrisb » Sun Dec 02, 2018 6:52 am

I forgot: Your proposal sure is an improvement!
User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

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

Postby NormandC » Sun Dec 02, 2018 8:11 am

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
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

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

Postby NormandC » Sun Dec 02, 2018 8:23 am

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
Site Admin
Posts: 14807
Joined: Thu Feb 19, 2009 10:32 am

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

Postby wmayer » Sun Dec 02, 2018 10:10 am

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
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

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

Postby NormandC » Sun Dec 02, 2018 8:00 pm

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
Site Admin
Posts: 14807
Joined: Thu Feb 19, 2009 10:32 am

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

Postby wmayer » Sun Dec 02, 2018 8:14 pm

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
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

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

Postby NormandC » Sun Dec 02, 2018 8:51 pm

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

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

Postby wmayer » Mon Dec 03, 2018 1:45 pm

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.