private void InitData() { try { TreeNode1 topNode = new TreeNode1(null, $"Top", null); topNode.NumDescendantEquations = 0; SelectedTreeLevels.Clear(); CurrentlySelectedTreeLevel = new SelectedTreeLevel1(null, topNode, ""); SelectedTreeLevels.Add(CurrentlySelectedTreeLevel); // Recursively build the tree information from the libraries foreach (var eqbLib in _vmEquations.EquationLibraries) { TreeNode1 libTn = new TreeNode1(topNode, eqbLib.Name, null); libTn.NumDescendantEquations = 0; foreach (var sn in eqbLib.TopSectionNodes) { TreeNode1 tn = new TreeNode1(libTn, sn.Name, sn); AddChildNodes(sn, tn); libTn.NumDescendantEquations += tn.NumDescendantEquations; } topNode.NumDescendantEquations += libTn.NumDescendantEquations; } } catch (Exception ex) { Logging.LogException(ex); throw; } }
void AddEquationCalcs(TreeNode1 treeNode, IList <IGrouping <string, EqnCalc> > equationCalcs) { if (treeNode == null) { return; } if (treeNode?.SectionNode != null) { IEnumerable <IGrouping <string, EqnCalc> > groups = treeNode.SectionNode.EqnCalcs //.OrderBy(x => x.SortString) .GroupBy(x => GetNodePath(treeNode, includeNode: true, excludeTop: true)); foreach (var item in groups) { equationCalcs.Add(item); } } foreach (var tn in treeNode.ChildTreeNodes) { AddEquationCalcs(tn, equationCalcs); } }
public TreeNode1(TreeNode1 parent, string name, SectionNode sectionNode) { Parent = parent; Name = name; SectionNode = sectionNode; parent?.ChildTreeNodes?.Add(this); }
private string GetNodePathRecursive(TreeNode1 tn, bool excludeTop) { if (tn.Parent != null) { if (!excludeTop || (tn.Parent.Parent != null)) { return(GetNodePathRecursive(tn.Parent, excludeTop) + $"{tn.Parent.Name} > "); } } return(""); }
private void AddChildNodes(SectionNode parentSn, TreeNode1 parentTn) { int numChildDescendantEquations = 0; foreach (var sn in parentSn.Children) { TreeNode1 childTn = new TreeNode1(parentTn, sn.Name, sn); AddChildNodes(sn, childTn); numChildDescendantEquations += childTn.NumDescendantEquations; } parentTn.NumDescendantEquations = numChildDescendantEquations + parentSn.EqnCalcs.Count; }
public void SelectTreeLevel(SelectedTreeLevel1 selectedTreeLevel) { try { CurrentlySelectedTreeLevel = selectedTreeLevel; CurrentEquationCalc = null; OnPropertyChanged("CurrentEquationCalc"); if (CurrentlySelectedTreeLevel == null) { throw new UnspecifiedException("CurrentlySelectedTreeLevel should not be null"); } _selectedLevelChildren.Clear(); _selectedLevelSelectedChild = null; IList <string> itemsToShow = new List <string>(); IDictionary <string, string> itemsToReturn = new Dictionary <string, string>(); foreach (var node in CurrentlySelectedTreeLevel?.TreeNode?.ChildTreeNodes) { string itemToShow = node.Name + $" ({node.NumDescendantEquations} equations)"; itemsToShow.Add(itemToShow); itemsToReturn.Add(itemToShow, node.Name); _selectedLevelChildren.Add(node.Name, node); } if (itemsToShow.Count != 0) { _vmEquations.EquationsUiService.SelectStringFromList(itemsToShow, (s) => { SelectedLevelSelectedChildName = itemsToReturn[s]; return(true); }); } } catch (Exception ex) { Logging.LogException(ex); throw; } }
private void RefreshSelectedTreeLevels(TreeNode1 lastTnToKeep) { try { int lastGoodItem = 0; for (int i = 0; i < SelectedTreeLevels.Count; i++) { if (SelectedTreeLevels[i]?.SelectedChildNode == lastTnToKeep) { lastGoodItem = i; break; } } int j = SelectedTreeLevels.Count - 1; while (j > lastGoodItem) { SelectedTreeLevels.RemoveAt(j); j--; } // Add the selection point at the end SelectedTreeLevel1 lastSelectedTreeLevel = SelectedTreeLevels[SelectedTreeLevels.Count - 1]; if (lastSelectedTreeLevel?.SelectedChildNode?.ChildTreeNodes?.Count > 0) { SelectedTreeLevel1 newSelectedTreeLevel = new SelectedTreeLevel1(lastSelectedTreeLevel, lastSelectedTreeLevel.SelectedChildNode, lastSelectedTreeLevel.Indent + " "); SelectedTreeLevels.Add(newSelectedTreeLevel); } else { SelectEquation.Execute(null); } } catch (Exception ex) { Logging.LogException(ex); throw; } }
public string GetNodePath(TreeNode1 tn, bool includeNode, bool excludeTop) { return(GetNodePathRecursive(tn, excludeTop) + (includeNode? $"{tn.Name}" : "")); }
public SelectedTreeLevel1(SelectedTreeLevel1 parent, TreeNode1 treeNode, string indent) { Parent = parent; TreeNode = treeNode; Indent = indent; }