Example #1
0
        public void ClearResults()       // For use before calculation and when the display may be inconsistent
        {
            CurrentEquationCalc.SetCalcStatus(CalcStatus.Uknown);

            _errorMessage = "";

            foreach (var eqCalcVar in EqCalcVariables)
            {
                if (eqCalcVar.IsCalculated && (eqCalcVar.GetSingleValue() is Variable))
                {
                    eqCalcVar.GetSingleValue()?.CalcQuantity?.Clear();
                    eqCalcVar.RefreshThisData();
                }
            }

            OnMessagesChanged();
        }
Example #2
0
        // -------------------------------------
        public void Recalculate()
        {
            try
            {
                if (EqCalcVariables.Count > 0)
                {
                    if (_bCalculating)
                    {
                        return;
                    }
                    _bCalculating = true;

                    UpdateCalcInputs();
                    ClearResults();

                    CalcStatus calcStatus = CurrentEquationCalc.CalculateAll();

                    IList <FunCalcError> lowestErrors = new List <FunCalcError>();
                    IList <FunCalcError> allErrors    = new List <FunCalcError>();
                    CurrentEquationCalc.GetErrors(ref lowestErrors, ref allErrors, NumberFormat: NumberFormat);
                    if (lowestErrors?.Count > 0)
                    {
                        _errorMessage = lowestErrors[0].Message;
                    }
                    OnMessagesChanged();

                    RefreshEqCalcVariables();

                    SetMaxUOMLength();
                    CalculationFinished?.Invoke(this, null);
                }
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw;
            }
            finally
            {
                _bCalculating = false;
            }
        }
Example #3
0
        private void SetEqCalcVariables()
        {
            try
            {
                IList <SingleValue> eqVars      = CurrentEquationCalc?.FindAllVariables() ?? (new List <SingleValue>());
                IList <SingleValue> eqConstants = CurrentEquationCalc?.FindAllConstants() ?? (new List <SingleValue>());

                // -------------
                SetMaxVarLength(eqVars, eqConstants);

                // -------------
                EqCalcVariables.Clear();

                for (int i = 0; i < eqVars.Count; i++)
                {
                    var item = eqVars[i];
                    item.ClearAllVarVals();

                    bool isCalculated = false;
                    if (i == 0)
                    {
                        isCalculated = true;
                    }

                    EqCalcVariables.Add(new VmEqVar(this, item, isCalculated));
                }

                for (int i = 0; i < eqConstants.Count; i++)
                {
                    var item = eqConstants[i];
                    EqCalcVariables.Add(new VmEqVar(this, item, true));
                }
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw;
            }
        }