예제 #1
0
파일: RUnit.cpp 프로젝트: ppiecuch/qcad
/**
 * Formats the given length in architectural format (e.g. 5' 4 1/2").
 *
 * \param length The length in the current unit of the drawing.
 * \param prec Precision of the value (e.g. 0.001 or 1/128 = 0.0078125)
 & \param showUnit Append unit to the value.
 */
QString RUnit::formatArchitectural(double length, RS::Unit unit,
                                   int prec, bool showUnit,
                                   bool /*showLeadingZeroes*/, bool /*showTrailingZeroes*/,
                                   bool /*onlyPreciseResult*/) {
    if (unit!=RS::Inch && unit!=RS::Foot) {
        qWarning() << "RUnit::formatArchitectural:"
                   << "Unit must be set to 'Inch' for architectural format";
        return "";
    }

    QString ret;

    double lengthInch;
    if (unit==RS::Foot) {
        lengthInch = length * 12;
    }
    else {
        lengthInch = length;
    }

    bool neg = (lengthInch<0.0);

    int feet = (int)floor(fabs(lengthInch)/12);
    double inches = fabs(lengthInch) - feet*12;

    QString sInches = formatFractional(inches, RS::Inch, prec, showUnit);

    if (sInches=="12") {
        feet++;
        sInches = "0";
    }

    // suppress 0 feet:
    if (feet==0) {
        if (neg) {
            ret.sprintf("-%s\"", (const char*)sInches.toLatin1());
        } else {
            ret.sprintf("%s\"", (const char*)sInches.toLatin1());
        }
    }
    else {
        if (neg) {
            ret.sprintf("-%d'-%s\"", feet, (const char*)sInches.toLatin1());
        } else {
            ret.sprintf("%d'-%s\"", feet, (const char*)sInches.toLatin1());
        }
    }

    return ret;
}
예제 #2
0
/**
 * Formats the given length in the given format.
 *
 * @param length The length in the current unit of the drawing.
 * @param format Format of the string.
 * @param prec Precision of the value (e.g. 0.001 or 1/128 = 0.0078125)
 & @param showUnit Append unit to the value.
 */
QString RS_Units::formatLinear(double length, RS2::Unit unit,
                                 RS2::LinearFormat format,
                                 int prec, bool showUnit) {
    QString ret;

    // unit appended to value (e.g. 'mm'):
    /*QString unitString = "";
    if (showUnit) {
        unitString = unitToSign(unit);
}*/

    // barbarian display: show as fraction:
    switch (format) {
    case RS2::Scientific:
        ret = formatScientific(length, unit, prec, showUnit);
        break;

    case RS2::Decimal:
        ret = formatDecimal(length, unit, prec, showUnit);
        break;

    case RS2::Engineering:
        ret = formatEngineering(length, unit, prec, showUnit);
        break;

    case RS2::Architectural:
        ret = formatArchitectural(length, unit, prec, showUnit);
        break;

    case RS2::Fractional:
        ret = formatFractional(length, unit, prec, showUnit);
        break;

    case RS2::ArchitecturalMetric:
        ret = formatArchitecturalMetric(length, unit, prec, showUnit);
        break;

    default:
        RS_DEBUG->print(RS_Debug::D_WARNING,
                        "RS_Units::formatLinear: Unknown format");
        ret = "";
        break;
    }

    return ret;
}
예제 #3
0
파일: RUnit.cpp 프로젝트: ppiecuch/qcad
/**
 * Formats the given length in the given format.
 *
 * \param length The length in the current unit of the drawing.
 * \param format Format of the string.
 * \param prec Precision of the value (e.g. 0.001 or 1/128 = 0.0078125)
 & \param showUnit Append unit to the value.
 */
QString RUnit::formatLinear(double length, RS::Unit unit,
                            RS::LinearFormat format,
                            int prec, bool showUnit,
                            bool showLeadingZeroes, 
                            bool showTrailingZeroes,
                            bool onlyPreciseResult) {
    QString ret;

    // imperial display: show as fraction:
    switch (format) {
    case RS::Scientific:
        ret = formatScientific(length, unit, prec, showUnit, 
            showLeadingZeroes, showTrailingZeroes, onlyPreciseResult);
        break;

    case RS::Decimal:
        ret = formatDecimal(length, unit, prec, showUnit,
            showLeadingZeroes, showTrailingZeroes, onlyPreciseResult);
        break;

    case RS::Engineering:
        ret = formatEngineering(length, unit, prec, showUnit,
            showLeadingZeroes, showTrailingZeroes, onlyPreciseResult);
        break;

    case RS::Architectural:
    case RS::ArchitecturalStacked:
        ret = formatArchitectural(length, unit, prec, showUnit,
            showLeadingZeroes, showTrailingZeroes, onlyPreciseResult);
        break;

    case RS::Fractional:
    case RS::FractionalStacked:
        ret = formatFractional(length, unit, prec, showUnit,
            showLeadingZeroes, showTrailingZeroes, onlyPreciseResult);
        break;

    default:
        qWarning() << "RUnit::formatLinear: Unknown format";
        ret = "";
        break;
    }
    
    return ret;
}
예제 #4
0
/**
 * Formats the given length in architectural format (e.g. 5' 4 1/2").
 *
 * @param length The length in the current unit of the drawing.
 * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125)
 & @param showUnit Append unit to the value.
 */
RS_String RS_Units::formatArchitectural(double length, RS2::Unit /*unit*/,
                                        int prec, bool showUnit) {
    RS_String ret;
    bool neg = (length<0.0);

    int feet = (int)floor(fabs(length)/12);
    double inches = fabs(length) - feet*12;

    RS_String sInches = formatFractional(inches, RS2::Inch, prec, showUnit);

    if (sInches=="12") {
        feet++;
        sInches = "0";
    }

    if (neg) {
        ret.sprintf("-%d'-%s\"", feet, (const char*)sInches.local8Bit());
    } else {
        ret.sprintf("%d'-%s\"", feet, (const char*)sInches.local8Bit());
    }

    return ret;
}
예제 #5
0
/**
 * Formats the given length in architectural format (e.g. 5' 4 1/2").
 *
 * @param length The length in the current unit of the drawing.
 * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125)
 & @param showUnit Append unit to the value.
 */
QString RS_Units::formatArchitectural(double length, RS2::Unit /*unit*/,
                                        int prec, bool showUnit) {
    QString ret;
    bool neg = (length<0.0);

    int feet = (int)floor(fabs(length)/12);
    double inches = fabs(length) - feet*12;

    QString sInches = formatFractional(inches, RS2::Inch, prec, showUnit);

    if (sInches=="12") {
        feet++;
        sInches = "0";
    }

    if (neg) {
        ret = QString("-%1'-%2\"").arg(feet).arg(sInches);
    } else {
        ret = QString("%1'-%2\"").arg(feet).arg(sInches);
    }

    return ret;
}