Derived formula only from Formula

This commit is contained in:
Álvaro González 2026-03-10 19:04:25 +01:00
parent e4f79ccab6
commit 8dda10d5da
2 changed files with 4 additions and 14 deletions

View file

@ -458,21 +458,12 @@ class _FormulaScreenState extends State<FormulaScreen> {
void _solveForVariable(VariableSpec variable) { void _solveForVariable(VariableSpec variable) {
// Check if the formula is already a DerivedFormula // Check if the formula is already a DerivedFormula
if (formula is DerivedFormula) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Cannot create derived formula from another derived formula'),
duration: Duration(seconds: 2),
),
);
return;
}
try { try {
// Create a DerivedFormula with this input variable as output // Create a DerivedFormula with this input variable as output
var rootFormula = FormulaInterface.getRootFormula(formula);
final derivedFormula = DerivedFormula( final derivedFormula = DerivedFormula(
outputName: variable.name, outputName: variable.name,
originalFormula: formula, originalFormula: rootFormula
); );
// Navigate to the new DerivedFormula screen // Navigate to the new DerivedFormula screen

View file

@ -196,11 +196,10 @@ class DerivedFormula implements FormulaInterface {
return f.input.every( (vs) => vs.unit != "string") && f.output.unit != "string"; return f.input.every( (vs) => vs.unit != "string") && f.output.unit != "string";
} }
DerivedFormula({required this.outputName, required FormulaInterface originalFormula}) { DerivedFormula({required this.outputName, required this.originalFormula}) {
this.originalFormula = FormulaInterface.getRootFormula(originalFormula);
if( !isDerivable(this.originalFormula) ){ if( !isDerivable(originalFormula) ){
throw ArgumentError( throw ArgumentError(
"Derived formulas are not supported for formulas with string inputs, because we can't solve for them. Original formula: ${originalFormula.toString()}"); "Derived formulas are not supported for formulas with string inputs, because we can't solve for them. Original formula: ${originalFormula.toString()}");
} }