private void AddEqnCalcs(IList <EqnCalc> eqnCalcs, SectionNode sn) { foreach (var item in sn.EqnCalcs) { eqnCalcs.Add(item); } foreach (var child in sn.Children) { AddEqnCalcs(eqnCalcs, child); } }
public static void AddEquationToSectionNode(ContentManager contentManager, SectionNode sectionNode, EquationDetails ed) { string description = ""; if (!string.IsNullOrEmpty(ed.Name)) { description += ((string.IsNullOrEmpty(description) ? "" : " ") + ed.Name); } if (!string.IsNullOrEmpty(ed.Reference)) { description += ((string.IsNullOrEmpty(description) ? "" : " ") + ed.Reference); } if (!string.IsNullOrEmpty(ed.Description)) { description += ((string.IsNullOrEmpty(description) ? "" : " ") + ed.Description); } // ---------------------- JongErrWarn errW = null; FunctionCalc funCalc = contentManager.CreateFunctionCalcFromExpression(ed.EquationAsText, description, ed.VariableInfos, out errW); // ---------------------- if (funCalc != null) { // ------------- Record the test values if there are any if ((ed.TestValues != null) && (ed.TestValues.Count > 0)) { funCalc.TestValues = new Dictionary </*variable name*/ string, double>(); for (int i = 0; i < ed.VariableInfos.Count; i++) { VarInfo vi = ed.VariableInfos[i]; funCalc.TestValues.Add(vi.Name, ed.TestValues[i]); } } funCalc.ExpectedDimensions = new Dictionary </*variable name*/ string, Dimensions>(); if (ed.VariableInfos != null) { foreach (VarInfo vi in ed.VariableInfos) { funCalc.ExpectedDimensions.Add(vi.Name, vi.ParamType?.Dimensions); } } // ------------- sectionNode.EqnCalcs.Add((EqnCalc)funCalc); } }
public void CreateFromDatabase(ContentManager contentManager, SqLiteContentDatabase database, IList <TblEqLibSectionNode_Row> sectionNodeRows, IList <TblEqLibEquation_Row> equationRows, IList <TblEqLibVariable_Row> variableRows) { Name = database.GetInfoVal("EquationLibraryName"); Description = database.GetInfoVal("EquationLibraryDescription"); // ----------- Read all the section nodes IDictionary <int, Tuple <TblEqLibSectionNode_Row, SectionNode> > allSectionNodes = new Dictionary <int, Tuple <TblEqLibSectionNode_Row, SectionNode> >(); // Key is TblEqLibSectionNode_Row.SectionNodeID foreach (var nodeRow in sectionNodeRows) { SectionNode sectionNode = new SectionNode(nodeRow.Name) { Description = nodeRow.Description }; allSectionNodes.Add(nodeRow.SectionNodeID, new Tuple <TblEqLibSectionNode_Row, SectionNode>(nodeRow, sectionNode)); } // ----------- Connect the parents foreach (var nodeTpl in allSectionNodes) { TblEqLibSectionNode_Row nodeRow = nodeTpl.Value.Item1; SectionNode sectionNode = nodeTpl.Value.Item2; if (nodeRow.ParentNodeID > 0) { int parentNodeID = nodeRow.ParentNodeID; if (allSectionNodes.ContainsKey(parentNodeID)) { sectionNode.Parent = allSectionNodes[parentNodeID].Item2; } else { int iDbg = 0; // TODO } } else { TopSectionNodes.Add(sectionNode); } } // ----------- Check for duplications or loops... TODO // ----------- Store the EquationDetails IDictionary <int, Tuple <TblEqLibEquation_Row, EquationDetails> > allEquationDetails = new Dictionary <int, Tuple <TblEqLibEquation_Row, EquationDetails> >(); // Key is TblEqLibEquation_Row.EquationID foreach (var eqnRow in equationRows) { EquationDetails ed = new EquationDetails(eqnRow.Name, eqnRow.EquationAsText); allEquationDetails.Add(eqnRow.EquationID, new Tuple <TblEqLibEquation_Row, EquationDetails>(eqnRow, ed)); } // ----------- Add the variables to the EquationDetails foreach (var varRow in variableRows) { string paramTypName = varRow.ParamType?.ToLower(); ParamType paramType = null; if (contentManager.ParamTypes.ContainsKey(paramTypName)) { paramType = contentManager.ParamTypes[paramTypName]; } else { int iDbg = 0; // TODO } VarInfo vi = new VarInfo(varRow.Name, varRow.Description, paramType); int equationID = varRow.EquationID; if (allEquationDetails.ContainsKey(equationID)) { allEquationDetails[equationID].Item2.VariableInfos.Add(vi); // TODO: Check for duplicate names } else { int iDbg = 0; // TODO } } // ----------- Create the EquationCalcs in the section nodes foreach (var eqTpl in allEquationDetails) { TblEqLibEquation_Row eqnRow = eqTpl.Value.Item1; EquationDetails ed = eqTpl.Value.Item2; int sectionNodeID = eqnRow.SectionNodeID; if (allSectionNodes.ContainsKey(sectionNodeID)) { AddEquationToSectionNode(contentManager, allSectionNodes[sectionNodeID].Item2, ed); } else { int iDbg = 0; // TODO } } }
public SectionNode(SectionNode parent, string name) { Parent = parent; Name = name; }