//public string SelectedLevelSelectedChildName //{ // get { return _selectedLevelSelectedChild?.Name; } // set // { // try // { // if (string.IsNullOrEmpty(value)) // { // _selectedLevelSelectedChild = null; // } // else if (CurrentlDisplayNode == null) // { // throw new UnspecifiedException(""); // } // else if ((_selectedLevelSelectedChild == null) || (!_selectedLevelSelectedChild.Name.Equals(value))) // { // _selectedLevelSelectedChild = _selectedLevelChildren[(string)value]; // //CurrentlySelectedTreeLevel.SelectedChildNode = _selectedLevelSelectedChild; // CurrentEquationCalc = null; // OnPropertyChanged("CurrentEquationCalc"); // RefreshVisibles(); // RefreshSelectedTreeLevels(_selectedLevelSelectedChild); // } // } // catch (Exception ex) // { // Logging.LogException(ex); // throw; // } // } //} //private void RefreshSelectedTreeLevels(EquationLibraryContentNode lastTnToKeep) //{ // try // { // int lastGoodItem = 0; // for (int i = 0; i < EquationLibraryDisplayTree.Count; i++) // { // if (EquationLibraryDisplayTree[i]?.SelectedChildNode == lastTnToKeep) // { // lastGoodItem = i; // break; // } // } // int j = EquationLibraryDisplayTree.Count - 1; // while (j > lastGoodItem) // { // EquationLibraryDisplayTree.RemoveAt(j); // j--; // } // // Add the selection point at the end // EquationLibraryDisplayNode lastSelectedTreeLevel = EquationLibraryDisplayTree[EquationLibraryDisplayTree.Count - 1]; // if (lastSelectedTreeLevel?.SelectedChildNode?.ChildTreeNodes?.Count > 0) // { // EquationLibraryDisplayNode newSelectedTreeLevel = new EquationLibraryDisplayNode(lastSelectedTreeLevel, lastSelectedTreeLevel.SelectedChildNode, lastSelectedTreeLevel.Indent + " "); // EquationLibraryDisplayTree.Add(newSelectedTreeLevel); // } // else // { // SelectEquation.Execute(null); // } // } // catch (Exception ex) // { // Logging.LogException(ex); // throw; // } //} /// <returns>Number of children</returns> public int ExpandTreeLevel(EquationLibraryDisplayNode displayNode) { try { if (CurrentDisplayNode != null) { CurrentDisplayNode.IsSelected = false; } EquationLibraryContentNode selectedContentNode = displayNode.ContentNode; selectedContentNode.Expanded = !selectedContentNode.Expanded; RefreshEquationLibraryDisplayTree(); CurrentDisplayNode = FindDisplayNode(selectedContentNode); CurrentEquationCalc = null; OnPropertyChanged("CurrentEquationCalc"); if (CurrentDisplayNode == null) { throw new UnspecifiedException("CurrentDisplayNode should not be null"); } CurrentDisplayNode.IsSelected = true; return(selectedContentNode.ChildTreeNodes.Count); } catch (Exception ex) { Logging.LogException(ex); throw; } }
void AddEquationCalcs(EquationLibraryContentNode 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 EquationLibraryContentNode(EquationLibraryContentNode parent, string name, SectionNode sectionNode) { Parent = parent; Name = name; SectionNode = sectionNode; parent?.ChildTreeNodes?.Add(this); }
private string GetNodePathRecursive(EquationLibraryContentNode tn, bool excludeTop) { if (tn.Parent != null) { if (!excludeTop || (tn.Parent.Parent != null)) { return(GetNodePathRecursive(tn.Parent, excludeTop) + $"{tn.Parent.Name} > "); } } return(""); }
private EquationLibraryDisplayNode FindDisplayNode(EquationLibraryContentNode contentNode) { foreach (var item in EquationLibraryDisplayTree) { if (item.ContentNode == contentNode) { return(item); } } return(null); }
private void AddChildNodes(SectionNode parentSn, EquationLibraryContentNode parentTn) { int numChildDescendantEquations = 0; foreach (var sn in parentSn.Children) { EquationLibraryContentNode childTn = new EquationLibraryContentNode(parentTn, sn.Name, sn); AddChildNodes(sn, childTn); numChildDescendantEquations += childTn.NumDescendantEquations; } parentTn.NumDescendantEquations = numChildDescendantEquations + parentSn.EqnCalcs.Count; }
private void InitData() { try { _topNode.NumDescendantEquations = 0; _topNode.Expanded = true; // Recursively build the tree information from the libraries foreach (var item in _vmEquations.ContentManager.EquationLibraries) { EquationLibrary eqbLib = item.Value; EquationLibraryContentNode libTn = new EquationLibraryContentNode(_topNode, eqbLib.Name, null); libTn.NumDescendantEquations = 0; foreach (var sn in eqbLib.TopSectionNodes) { EquationLibraryContentNode tn = new EquationLibraryContentNode(libTn, sn.Name, sn); AddChildNodes(sn, tn); libTn.NumDescendantEquations += tn.NumDescendantEquations; } _topNode.NumDescendantEquations += libTn.NumDescendantEquations; } RefreshEquationLibraryDisplayTree(); if (EquationLibraryDisplayTree?.Count > 0) { ExpandTreeLevel(EquationLibraryDisplayTree[0]); } } catch (Exception ex) { Logging.LogException(ex); throw; } }
private void AddEquationLibraryDisplayLevels(bool isTop, EquationLibraryDisplayNode parentNode, EquationLibraryContentNode contentNode) { EquationLibraryDisplayNode displayNode = null; if (!isTop) { displayNode = new EquationLibraryDisplayNode (parentNode, contentNode, ((parentNode == null) ? "" : parentNode.Indent + " ")); EquationLibraryDisplayTree.Add(displayNode); } if (contentNode.Expanded) { foreach (var childContentNode in contentNode.ChildTreeNodes) { AddEquationLibraryDisplayLevels(false, displayNode, childContentNode); } } }
public string GetNodePath(EquationLibraryContentNode tn, bool includeNode, bool excludeTop) { return(GetNodePathRecursive(tn, excludeTop) + (includeNode ? $"{tn.Name}" : "")); }
public EquationLibraryDisplayNode(EquationLibraryDisplayNode parent, EquationLibraryContentNode contentNode, string indent) { Parent = parent; ContentNode = contentNode; Indent = indent; }