Default format - small fix

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
babaroga
Posts: 178
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Default format - small fix

Post by babaroga »

After introduction of default format in TD I realised that diameter and radius symbol on dimensions were overriden by deafault format entered in preferences dialog. So if you enter anything as default format, diameter and radius symbol is missing on dimensions.

This is my small fix for this issue. @WandererFan can you please test it and consider change it since I am not Github guru?

This code in DrawViewDimension.cpp somewhere end of the file

Code: Select all

std::string DrawViewDimension::getDefaultFormatSpec() const
{
    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
                                         .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
    std::string prefFormat = hGrp->GetASCII("formatSpec","");
    QString formatSpec;
    if (prefFormat.empty()) {
        QString format1 = Base::Tools::fromStdString("%.");
        QString format2 = Base::Tools::fromStdString("f");
        int precision;
        if (useDecimals()) {
            precision = Base::UnitsApi::getDecimals();
        } else {
            precision = hGrp->GetInt("AltDecimals", 2);
        }
        QString formatPrecision = QString::number(precision);

        std::string prefix = getPrefix();
        QString qPrefix;
        if (!prefix.empty()) {
            qPrefix = QString::fromUtf8(prefix.data(),prefix.size());
        }

        formatSpec = qPrefix + format1 + formatPrecision + format2;
    } else {
        return prefFormat;
    }
    
    return Base::Tools::toStdString(formatSpec);
}

is to be replaced by :

Code: Select all

std::string DrawViewDimension::getDefaultFormatSpec() const
{
    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
                                         .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
    std::string prefFormat = hGrp->GetASCII("formatSpec","");
    QString formatSpec;
    QString qPrefix; //Move it here
    if (prefFormat.empty()) {
        QString format1 = Base::Tools::fromStdString("%.");
        QString format2 = Base::Tools::fromStdString("f");
        int precision;
        if (useDecimals()) {
            precision = Base::UnitsApi::getDecimals();
        } else {
            precision = hGrp->GetInt("AltDecimals", 2);
        }
        QString formatPrecision = QString::number(precision);

        std::string prefix = getPrefix();
        //QString qPrefix;
        if (!prefix.empty()) {
            qPrefix = QString::fromUtf8(prefix.data(),prefix.size());
        }

        formatSpec = qPrefix + format1 + formatPrecision + format2;
    } else {
        //return prefFormat;
        
        std::string prefix = getPrefix();
        qPrefix = QString::fromUtf8(prefix.data(),prefix.size());
        formatSpec = qPrefix + QString::fromStdString(prefFormat);
        
    }
    
    return Base::Tools::toStdString(formatSpec);
}
User avatar
wandererfan
Veteran
Posts: 6238
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Default format - small fix

Post by wandererfan »

babaroga wrote: Sun Apr 14, 2019 10:04 pm This is my small fix for this issue. @WandererFan can you please test it and consider change it since I am not Github guru?
Thanks. Desk check looks good. My devl environment is crowded right now, might take a few days to get to this.

If you can read and modify code, you can do Github. Somewhere in the forum there are step by step instructions. I'll see if I can find them.
User avatar
babaroga
Posts: 178
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: Default format - small fix

Post by babaroga »

OK, I will study it :oops:

THX
User avatar
babaroga
Posts: 178
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: Default format - small fix

Post by babaroga »

So, I did my first Pull request. It says checks are OK.

What now? Is there something else I should do?
User avatar
wandererfan
Veteran
Posts: 6238
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Default format - small fix

Post by wandererfan »

babaroga wrote: Wed Apr 17, 2019 10:27 am So, I did my first Pull request. It says checks are OK.
Awesome! Your change has been merged into master branch. You are now a FreeCAD developer!
What now? Is there something else I should do?
Find another bug to fix? :D
User avatar
babaroga
Posts: 178
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: Default format - small fix

Post by babaroga »

Yeeeeah,

I will drink a beer in that name... :D

Of course, there is one more I am working on. If "Show unit of measure" is ticked off in preferences, " ° " degree sign is missing on angular measures.
User avatar
wandererfan
Veteran
Posts: 6238
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Default format - small fix

Post by wandererfan »

babaroga wrote: Wed Apr 17, 2019 1:11 pm Of course, there is one more I am working on. If "Show unit of measure" is ticked off in preferences, " ° " degree sign is missing on angular measures.
Lots more fixes to be made. I may have to figure our how to send you a case of beer.
Post Reply