Example #1
0
        // ------------------------------

        public void CheckParamTypes()
        {
            // Assign AnonUOM to each variable based on the param type
            UpdateInputsDimensions();

            // Check the consistency of dimensions
            CalcStatus calcStatus = EquationCalc.CheckDimensionsAll();

            if (calcStatus == CalcStatus.Bad)
            {
                ParamTypeMsg = "Parameter types have inconsisent dimensions";
            }
            else
            {
                ParamTypeMsg = DefaultParamTypeMsg;
            }
        }
Example #2
0
        private void UpdateInputsDimensions()
        {
            UOMSet uomSetSI = ContentManager.UOMSets["SI"];

            IList <SingleValue> variables = EquationCalc.FindAllVariables();

            foreach (var ei in EqCalcVarInfos)
            {
                string     vName = ei.Name;
                Dimensions vDims = ei?.ParamType?.Dimensions;

                foreach (var v in variables)
                {
                    if (v.Name.Equals(vName))
                    {
                        v.CalcQuantity.AnonUOM = new AnonUOM(vDims, uomSetSI);
                        break;
                    }
                }
            }
        }
Example #3
0
        // ------------------------------

        private void SetEqCalcVarInfos()
        {
            if (EquationCalc == null)
            {
                return; //Might just be a temporary syntax error, so we don't want to lose all our variable definitions
            }

            IList <SingleValue> eqVars = EquationCalc?.FindAllVariables() ?? (new List <SingleValue>());

            // -------------
            int maxVarLen = 0;

            foreach (var item in eqVars)
            {
                if (item?.Name?.Length > maxVarLen)
                {
                    maxVarLen = item.Name.Length;
                }
            }
            MaxVarLength = maxVarLen;
            MaxVarLengthChanged?.Invoke(this, null);

            // -------------
            IList <VmEqCalcVarInfo> toRemove = new List <VmEqCalcVarInfo>();

            // ------------ Remove the hacks
            for (int i = EqCalcVarInfos.Count - 1; i >= 0; i--)
            {
                VmEqCalcVarInfo ei = EqCalcVarInfos[i];
                if (ei.Name == null)
                {
                    EqCalcVarInfos.Remove(ei);
                }
            }
            foreach (var ei in EqCalcVarInfos)
            {
                if (ei.Name == null)
                {
                    EqCalcVarInfos.Remove(ei);
                }
            }
            foreach (var ei in EqCalcVarInfos)
            {
                toRemove.Add(ei);
            }

            // ------------ Add new items and note those still needed
            for (int i = 0; i < eqVars.Count; i++)
            {
                var sv = eqVars[i];
                sv.ClearAllVarVals();

                bool bFound = false;
                foreach (var ei in toRemove)
                {
                    if (ei.Name.Equals(sv.Name))
                    {
                        bFound = true;
                        toRemove.Remove(ei);    //still needed
                        break;
                    }
                }

                if (!bFound)
                {
                    EqCalcVarInfos.Add(new VmEqCalcVarInfo(this, sv));
                }
            }

            // ------------ Remove any no longer needed
            foreach (var ei in toRemove)
            {
                EqCalcVarInfos.Remove(ei);
            }
        }