当前位置: 首页>>代码示例>>C++>>正文


C++ base::Quantity类代码示例

本文整理汇总了C++中base::Quantity的典型用法代码示例。如果您正苦于以下问题:C++ Quantity类的具体用法?C++ Quantity怎么用?C++ Quantity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Quantity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: schemaTranslate

QString UnitsSchemaInternal::schemaTranslate(Base::Quantity quant)
{
    double UnitValue = quant.getValue();
	Unit unit = quant.getUnit();

	return QString::fromAscii("%1 %2").arg(UnitValue).arg(QString::fromAscii(unit.getString().c_str()));
}
开发者ID:andrewjrobinson,项目名称:FreeCAD_sf_master,代码行数:7,代码来源:UnitsSchemaInternal.cpp

示例2: schemaTranslate

QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
{
    double UnitValue = std::abs(quant.getValue());
    Unit unit = quant.getUnit();
    // for imperial user/programmer mind; UnitValue is in internal system, that means
    // mm/kg/s. And all combined units have to be calculated from there!

    // now do special treatment on all cases seems necessary:
    if(unit == Unit::Length){  // Length handling ============================
        if(UnitValue < 0.00000254){// smaller then 0.001 thou -> inch and scientific notation
            unitString = QString::fromLatin1("in");
            factor = 25.4;
        //}else if(UnitValue < 2.54){ // smaller then 0.1 inch -> Thou (mil)
        //    unitString = QString::fromLatin1("thou");
        //    factor = 0.0254;
        }else{ // bigger then 1000 mi -> scientific notation
            unitString = QString::fromLatin1("in");
            factor = 25.4;
        }
    }else if (unit == Unit::Area){
        // TODO Cascade for the Areas
        // default action for all cases without special treatment:
        unitString = QString::fromLatin1("in^2");
        factor = 645.16;
    }else if (unit == Unit::Volume){
        // TODO Cascade for the Volume
        // default action for all cases without special treatment:
        unitString = QString::fromLatin1("in^3");
        factor = 16387.064;
    }else if (unit == Unit::Mass){
        // TODO Cascade for the wights
        // default action for all cases without special treatment:
        unitString = QString::fromLatin1("lb");
        factor = 0.45359237;
    }else if (unit == Unit::Pressure){
        if(UnitValue < 145.038){// psi is the smallest
            unitString = QString::fromLatin1("psi");
            factor = 0.145038;
        //}else if(UnitValue < 145038){
        //    unitString = QString::fromLatin1("ksi");
        //    factor = 145.038;
        }else{ // bigger then 1000 ksi -> psi + scientific notation
            unitString = QString::fromLatin1("psi");
            factor = 0.145038;
        }
    }else{
        // default action for all cases without special treatment:
        unitString = quant.getUnit().getString();
        factor = 1.0;
    }
    //return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
    QLocale Lc = QLocale::system();
    Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
    QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals());
    return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
}
开发者ID:PocketMonster5,项目名称:FreeCAD,代码行数:56,代码来源:UnitsSchemaImperial1.cpp

示例3: textFromValue

QString QuantitySpinBox::textFromValue(const Base::Quantity& value) const
{
    double factor;
    QString unitStr;
    QString str = value.getUserString(factor, unitStr);
    if (qAbs(value.getValue()) >= 1000.0) {
        str.remove(locale().groupSeparator());
    }
    return str;
}
开发者ID:needtogettomit,项目名称:FreeCAD,代码行数:10,代码来源:QuantitySpinBox.cpp

示例4: setValue

/// sets the field with a quantity
void InputField::setValue(const Base::Quantity& quant)
{
    actQuantity = quant;
    if(!quant.getUnit().isEmpty())
        actUnit = quant.getUnit();

    double dFactor;
    setText(quant.getUserString(dFactor,actUnitStr));
    actUnitValue = quant.getValue()/dFactor;
}
开发者ID:MarcusWolschon,项目名称:FreeCAD_sf_master,代码行数:11,代码来源:InputField.cpp

示例5: textChanged

void DlgExpressionInput::textChanged(const QString &text)
{
    try {
        //resize the input field according to text size
        QFontMetrics fm(ui->expression->font());
        int width = fm.width(text) + 15;
        if (width < minimumWidth)
            ui->expression->setMinimumWidth(minimumWidth);
        else
            ui->expression->setMinimumWidth(width);
        
        if(this->width() < ui->expression->minimumWidth())
            setMinimumWidth(ui->expression->minimumWidth());

        //now handle expression
        boost::shared_ptr<Expression> expr(ExpressionParser::parse(path.getDocumentObject(), text.toUtf8().constData()));

        if (expr) {
            std::string error = path.getDocumentObject()->ExpressionEngine.validateExpression(path, expr);

            if (error.size() > 0)
                throw Base::Exception(error.c_str());

            std::unique_ptr<Expression> result(expr->eval());

            expression = expr;
            ui->okBtn->setEnabled(true);
            ui->msg->clear();

            NumberExpression * n = Base::freecad_dynamic_cast<NumberExpression>(result.get());
            if (n) {
                Base::Quantity value = n->getQuantity();

                if (!value.getUnit().isEmpty() && value.getUnit() != impliedUnit)
                    throw Base::Exception("Unit mismatch between result and required unit");

                value.setUnit(impliedUnit);

                ui->msg->setText(value.getUserString());
            }
            else
                ui->msg->setText(Base::Tools::fromStdString(result->toString()));

            //set default palette as we may have read text right now
            ui->msg->setPalette(ui->okBtn->palette());
        }
    }
    catch (Base::Exception & e) {
        ui->msg->setText(QString::fromUtf8(e.what()));
        QPalette p(ui->msg->palette());
        p.setColor(QPalette::WindowText, Qt::red);
        ui->msg->setPalette(p);
        ui->okBtn->setDisabled(true);
    }
}
开发者ID:danielfalck,项目名称:FreeCAD,代码行数:55,代码来源:DlgExpressionInput.cpp

示例6: toLocale

QString UnitsSchema::toLocale(const Base::Quantity& quant, double factor, const QString& unitString) const
{
    //return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
    QLocale Lc = QLocale::system();
    const QuantityFormat& format = quant.getFormat();
    if (format.option != QuantityFormat::None) {
        uint opt = static_cast<uint>(format.option);
        Lc.setNumberOptions(static_cast<QLocale::NumberOptions>(opt));
    }

    QString Ln = Lc.toString((quant.getValue() / factor), format.toFormat(), format.precision);
    return QString::fromUtf8("%1 %2").arg(Ln, unitString);
}
开发者ID:WandererFan,项目名称:FreeCAD,代码行数:13,代码来源:UnitsSchema.cpp

示例7: event

bool PropertyConstraintListItem::event (QEvent* ev)
{
    if (ev->type() == QEvent::DynamicPropertyChange) {
        if (!blockEvent) {
            QDynamicPropertyChangeEvent* ce = static_cast<QDynamicPropertyChangeEvent*>(ev);
            // Get property via internal name of a PropertyUnit
            QVariant prop = property(ce->propertyName());
            QString propName = QString::fromLatin1(ce->propertyName());
            Base::Quantity quant = prop.value<Base::Quantity>();

            Sketcher::PropertyConstraintList* item;

            int id = 0;
            if (this->parent()->getTypeId() == SketcherGui::PropertyConstraintListItem::getClassTypeId()) {
                item = static_cast<Sketcher::PropertyConstraintList*>(this->parent()->getFirstProperty());
            }
            else {
                item = static_cast<Sketcher::PropertyConstraintList*>(getFirstProperty());
            }

            const std::vector< Sketcher::Constraint * > &vals = item->getValues();
            for (std::vector< Sketcher::Constraint* >::const_iterator it = vals.begin();it != vals.end(); ++it, ++id) {
                if ((*it)->Type == Sketcher::Distance || // Datum constraint
                    (*it)->Type == Sketcher::DistanceX ||
                    (*it)->Type == Sketcher::DistanceY ||
                    (*it)->Type == Sketcher::Radius ||
                    (*it)->Type == Sketcher::Angle ) {

                    // Get the internal name
                    QString internalName = QString::fromLatin1("Constraint%1").arg(id+1);
                    if (internalName == propName) {
                        double datum = quant.getValue();
                        if ((*it)->Type == Sketcher::Angle)
                            datum = Base::toRadians<double>(datum);
                        const_cast<Sketcher::Constraint *>((*it))->setValue(datum);
                        item->set1Value(id,(*it));
                        break;
                    }
                }
            }
        }
    }

    return PropertyItem::event(ev);
}
开发者ID:cpollard1001,项目名称:FreeCAD_sf_master,代码行数:45,代码来源:PropertyConstraintListItem.cpp

示例8: getFormatedValue

std::string  DrawViewDimension::getFormatedValue() const
{
    QString str = QString::fromUtf8(FormatSpec.getStrValue().c_str());
    double val = std::abs(getDimValue());
    //QLocale here(QLocale::German);                                           //for testing
    //here.setNumberOptions(QLocale::OmitGroupSeparator);
    QLocale here = QLocale();                                                  //system locale
    QString valText = here.toString(val, 'f',Precision.getValue());

    Base::Quantity qVal;
    qVal.setValue(val);
    if (Type.isValue("Angle")) {
        qVal.setUnit(Base::Unit::Angle);
    } else {
        qVal.setUnit(Base::Unit::Length);
    }
    QString userStr = qVal.getUserString();
    QStringList userSplit = userStr.split(QString::fromUtf8(" "),QString::SkipEmptyParts);   //break userString into number + UoM
    QString displayText;
    if (!userSplit.isEmpty()) {
       QString unitText = userSplit.back();
       displayText = valText + QString::fromUtf8(" ") + unitText;
    }

    QRegExp rx(QString::fromAscii("%(\\w+)%"));                        //any word bracketed by %
    QStringList list;
    int pos = 0;

    while ((pos = rx.indexIn(str, pos)) != -1) {
        list << rx.cap(0);
        pos += rx.matchedLength();
    }

    for(QStringList::const_iterator it = list.begin(); it != list.end(); ++it) {
        if(*it == QString::fromAscii("%value%")){
            str.replace(*it,displayText);
        } else {                                                       //insert additional placeholder replacement logic here
            str.replace(*it, QString::fromAscii(""));                  //maybe we should just leave what was there?
        }
    }
    return str.toStdString();
}
开发者ID:aberg001,项目名称:FreeCAD,代码行数:42,代码来源:DrawViewDimension.cpp

示例9: userInput

// Gets called after call of 'validateAndInterpret'
void QuantitySpinBox::userInput(const QString & text)
{
    Q_D(QuantitySpinBox);

    QString tmp = text;
    int pos = 0;
    QValidator::State state;
    Base::Quantity res = d->validateAndInterpret(tmp, pos, state);
    if (state == QValidator::Acceptable) {
        d->validInput = true;
        d->validStr = text;
    }
    else if (state == QValidator::Intermediate) {
        tmp = tmp.trimmed();
        tmp += QLatin1Char(' ');
        tmp += d->unitStr;
        Base::Quantity res2 = d->validateAndInterpret(tmp, pos, state);
        if (state == QValidator::Acceptable) {
            d->validInput = true;
            d->validStr = tmp;
            res = res2;
        }
        else {
            d->validInput = false;
            return;
        }
    }
    else {
        d->validInput = false;
        return;
    }

    double factor;
    res.getUserString(factor,d->unitStr);
    d->unitValue = res.getValue()/factor;
    d->quantity = res;

    // signaling
    valueChanged(res);
    valueChanged(res.getValue());
}
开发者ID:needtogettomit,项目名称:FreeCAD,代码行数:42,代码来源:QuantitySpinBox.cpp

示例10: schemaTranslate

QString UnitsSchemaMKS::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
{
    double UnitValue = std::abs(quant.getValue());
	Unit unit = quant.getUnit();

    // now do special treatment on all cases seams nececarry:
    if(unit == Unit::Length){  // Length handling ============================
        if(UnitValue < 0.000000001){// smaller then 0.001 nm -> scientific notation
            unitString = QString::fromLatin1("mm");
            factor = 1.0;
        }else if(UnitValue < 0.001){
            unitString = QString::fromLatin1("nm");
            factor = 0.000001;
        }else if(UnitValue < 0.1){
            unitString = QString::fromUtf8("\xC2\xB5m");
            factor = 0.001;
        }else if(UnitValue < 100.0){
            unitString = QString::fromLatin1("mm");
            factor = 1.0;
        }else if(UnitValue < 10000000.0){
            unitString = QString::fromLatin1("m");
            factor = 1000.0;
        }else if(UnitValue < 100000000000.0 ){
            unitString = QString::fromLatin1("km");
            factor = 1000000.0;
        }else{ // bigger then 1000 km -> scientific notation 
            unitString = QString::fromLatin1("mm");
            factor = 1.0;
        }
    }else if (unit == Unit::Area){
        // TODO Cascade for the Areas
        // default action for all cases without special treatment:
        unitString = quant.getUnit().getString();
        factor = 1.0;
    }else if (unit == Unit::Mass){
        // TODO Cascade for the wights
        // default action for all cases without special treatment:
        unitString = quant.getUnit().getString();
        factor = 1.0;
    }else if (unit == Unit::Pressure){
        if(UnitValue < 10.0){// Pa is the smallest
            unitString = QString::fromLatin1("Pa");
            factor = 0.001;
        }else if(UnitValue < 10000.0){
            unitString = QString::fromLatin1("kPa");
            factor = 1.0;
        }else if(UnitValue < 10000000.0){
            unitString = QString::fromLatin1("GPa");
            factor = 1000.0;
        }else{ // bigger then 1000 GPa -> scientific notation 
            unitString = QString::fromLatin1("Pa");
            factor = 1.0;
        }
    }else{
        // default action for all cases without special treatment:
        unitString = quant.getUnit().getString();
        factor = 1.0;
    }
	return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
}
开发者ID:Barleyman,项目名称:FreeCAD_sf_master,代码行数:60,代码来源:UnitsSchemaMKS.cpp

示例11: setValue

void QuantitySpinBox::setValue(const Base::Quantity& value)
{
    Q_D(QuantitySpinBox);
    d->quantity = value;
    // check limits
    if (d->quantity.getValue() > d->maximum)
        d->quantity.setValue(d->maximum);
    if (d->quantity.getValue() < d->minimum)
        d->quantity.setValue(d->minimum);

    d->unit = value.getUnit();

    updateText(value);
}
开发者ID:needtogettomit,项目名称:FreeCAD,代码行数:14,代码来源:QuantitySpinBox.cpp

示例12: setDatum

PyObject* SketchObjectPy::setDatum(PyObject *args)
{
    double Datum;
    int    Index;
    PyObject* object;
    Base::Quantity Quantity;
    if (PyArg_ParseTuple(args,"iO!", &Index, &(Base::QuantityPy::Type), &object)) {
        Quantity = *(static_cast<Base::QuantityPy*>(object)->getQuantityPtr());
        if (Quantity.getUnit() == Base::Unit::Angle)
            //Datum = Quantity.getValueAs(Base::Quantity::Radian);
            Datum = Base::toRadians<double>(Quantity.getValue());
        else
            Datum = Quantity.getValue();
    }
    else {
        PyErr_Clear();
        if (!PyArg_ParseTuple(args, "id", &Index, &Datum))
            return 0;
        Quantity.setValue(Datum);
    }

    int err=this->getSketchObjectPtr()->setDatum(Index, Datum);
    if (err) {
        std::stringstream str;
        if (err == -1)
            str << "Invalid constraint index: " << Index;
        else if (err == -3)
            str << "Cannot set the datum because the sketch contains conflicting constraints";
        else if (err == -2)
            str << "Datum " << (const char*)Quantity.getUserString().toUtf8() << " for the constraint with index " << Index << " is invalid";
        else if (err == -4)
            str << "Negative datum values are not valid for the constraint with index " << Index;
        else if (err == -5)
            str << "Zero is not a valid datum for the constraint with index " << Index;
        else
            str << "Unexpected problem at setting datum " << (const char*)Quantity.getUserString().toUtf8() << " for the constraint with index " << Index;
        PyErr_SetString(PyExc_ValueError, str.str().c_str());
        return 0;
    }

    Py_Return;
}
开发者ID:emiamar,项目名称:FreeCAD_sf_master,代码行数:42,代码来源:SketchObjectPyImp.cpp

示例13: onPressureChanged

void TaskFemConstraintPressure::onPressureChanged(const Base::Quantity& f)
{
    Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject());
    double val = f.getValueAs(Base::Quantity::MegaPascal);
    pcConstraint->Pressure.setValue(val);
}
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:6,代码来源:TaskFemConstraintPressure.cpp

示例14: getDatum

PyObject* SketchObjectPy::getDatum(PyObject *args)
{
    const std::vector<Constraint*>& vals = this->getSketchObjectPtr()->Constraints.getValues();
    Constraint* constr = 0;

    do {
        int index = 0;
        if (PyArg_ParseTuple(args,"i", &index)) {
            if (index < 0 || index >= static_cast<int>(vals.size())) {
                PyErr_SetString(PyExc_IndexError, "index out of range");
                return 0;
            }

            constr = vals[index];
            break;
        }

        PyErr_Clear();
        char* name;
        if (PyArg_ParseTuple(args,"s", &name)) {
            int id = 0;
            for (std::vector<Constraint*>::const_iterator it = vals.begin(); it != vals.end(); ++it, ++id) {
                if (Sketcher::PropertyConstraintList::getConstraintName((*it)->Name, id) == name) {
                    constr = *it;
                    break;
                }
            }

            if (!constr) {
                std::stringstream str;
                str << "Invalid constraint name: '" << name << "'";
                PyErr_SetString(PyExc_NameError, str.str().c_str());
                return 0;
            }
            else {
                break;
            }
        }

        // error handling
        PyErr_SetString(PyExc_TypeError, "Wrong arguments");
        return 0;
    }
    while (false);

    ConstraintType type = constr->Type;
    if (type != Distance &&
        type != DistanceX &&
        type != DistanceY &&
        type != Radius &&
        type != Angle) {
        PyErr_SetString(PyExc_TypeError, "Constraint is not a datum");
        return 0;
    }

    Base::Quantity datum;
    datum.setValue(constr->getValue());
    if (type == Angle) {
        datum.setValue(Base::toDegrees<double>(datum.getValue()));
        datum.setUnit(Base::Unit::Angle);
    }
    else {
        datum.setUnit(Base::Unit::Length);
    }

    return new Base::QuantityPy(new Base::Quantity(datum));
}
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:67,代码来源:SketchObjectPyImp.cpp

示例15: setDatum

PyObject* SketchObjectPy::setDatum(PyObject *args)
{
    double Datum;
    int    Index;
    PyObject* object;
    Base::Quantity Quantity;

    do {
        // handle (int,Quantity)
        if (PyArg_ParseTuple(args,"iO!", &Index, &(Base::QuantityPy::Type), &object)) {
            Quantity = *(static_cast<Base::QuantityPy*>(object)->getQuantityPtr());
            if (Quantity.getUnit() == Base::Unit::Angle) {
                Datum = Base::toRadians<double>(Quantity.getValue());
                break;
            }
            else {
                Datum = Quantity.getValue();
                break;
            }
        }

        // handle (int,double)
        PyErr_Clear();
        if (PyArg_ParseTuple(args, "id", &Index, &Datum)) {
            Quantity.setValue(Datum);
            break;
        }

        // handle (string,Quantity)
        char* constrName;
        PyErr_Clear();
        if (PyArg_ParseTuple(args,"sO!", &constrName, &(Base::QuantityPy::Type), &object)) {
            Quantity = *(static_cast<Base::QuantityPy*>(object)->getQuantityPtr());
            if (Quantity.getUnit() == Base::Unit::Angle) {
                Datum = Base::toRadians<double>(Quantity.getValue());
            }
            else {
                Datum = Quantity.getValue();
            }

            int i = 0;
            Index = -1;
            const std::vector<Constraint*>& vals = this->getSketchObjectPtr()->Constraints.getValues();
            for (std::vector<Constraint*>::const_iterator it = vals.begin(); it != vals.end(); ++it, ++i) {
                if ((*it)->Name == constrName) {
                    Index = i;
                    break;
                }
            }

            if (Index >= 0) {
                break;
            }
            else {
                std::stringstream str;
                str << "Invalid constraint name: '" << constrName << "'";
                PyErr_SetString(PyExc_ValueError, str.str().c_str());
                return 0;
            }
        }

        // handle (string,double)
        PyErr_Clear();
        if (PyArg_ParseTuple(args, "sd", &constrName, &Datum)) {
            Quantity.setValue(Datum);
            int i = 0;
            Index = -1;
            const std::vector<Constraint*>& vals = this->getSketchObjectPtr()->Constraints.getValues();
            for (std::vector<Constraint*>::const_iterator it = vals.begin(); it != vals.end(); ++it, ++i) {
                if ((*it)->Name == constrName) {
                    Index = i;
                    break;
                }
            }

            if (Index >= 0) {
                break;
            }
            else {
                std::stringstream str;
                str << "Invalid constraint name: '" << constrName << "'";
                PyErr_SetString(PyExc_ValueError, str.str().c_str());
                return 0;
            }
        }

        // error handling
        PyErr_SetString(PyExc_TypeError, "Wrong arguments");
        return 0;
    }
    while (false);

    int err=this->getSketchObjectPtr()->setDatum(Index, Datum);
    if (err) {
        std::stringstream str;
        if (err == -1)
            str << "Invalid constraint index: " << Index;
        else if (err == -3)
            str << "Cannot set the datum because the sketch contains conflicting constraints";
        else if (err == -2)
//.........这里部分代码省略.........
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:101,代码来源:SketchObjectPyImp.cpp


注:本文中的base::Quantity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。