MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / applyImpliedUnit

Method applyImpliedUnit

src/Gui/Dialogs/DlgExpressionInput.cpp:591–622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

589}
590
591void DlgExpressionInput::applyImpliedUnit()
592{
593 if (!expression || impliedUnit == Base::Unit::One) {
594 return;
595 }
596
597 std::unique_ptr<App::Expression> evaluated(expression->eval());
598 const auto* numberExpr = toNumberExpr(evaluated.get());
599 if (!numberExpr || !numberExpr->getQuantity().isDimensionless()) {
600 return;
601 }
602
603 double factor = 1.0;
604 std::string unitString;
605 Base::Quantity(1.0, impliedUnit).getUserString(factor, unitString);
606 if (unitString.empty()) {
607 return;
608 }
609
610 auto left = expression->copy();
611 auto right = std::make_unique<App::UnitExpression>(
612 path.getDocumentObject(),
613 Base::Quantity(factor, impliedUnit),
614 unitString
615 );
616 expression = std::make_shared<App::OperatorExpression>(
617 path.getDocumentObject(),
618 left.release(),
619 App::OperatorExpression::Operator::UNIT,
620 right.release()
621 );
622}
623
624void DlgExpressionInput::createBindingVarSet(App::Property* propVarSet, App::DocumentObject* varSet)
625{

Callers

nothing calls this directly

Calls 11

toNumberExprFunction · 0.85
evalMethod · 0.80
isDimensionlessMethod · 0.80
getDocumentObjectMethod · 0.80
QuantityClass · 0.70
getMethod · 0.45
getQuantityMethod · 0.45
getUserStringMethod · 0.45
emptyMethod · 0.45
copyMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected